diff --git a/import-export-cli/cmd/mg/undeployAPI.go b/import-export-cli/cmd/mg/undeployAPI.go index c78785075..23f6f3706 100644 --- a/import-export-cli/cmd/mg/undeployAPI.go +++ b/import-export-cli/cmd/mg/undeployAPI.go @@ -20,6 +20,7 @@ package mg import ( "fmt" + "strings" "github.com/spf13/cobra" mgImpl "github.com/wso2/product-apim-tooling/import-export-cli/impl/mg" @@ -27,24 +28,31 @@ import ( ) var ( - undeployAPICmdAPIName string - undeployAPICmdAPIVersion string - undeployAPICmdAPIVHost string - undeployAPIEnv string + undeployAPICmdAPIName string + undeployAPICmdAPIVersion string + undeployAPICmdAPIVHost string + undeployAPICmdAPIGatewayEnvs []string + undeployAPIEnv string ) +const gatewayNameSeparator = ":" + const ( undeployAPICmdShortDesc = "Undeploy an API in Microgateway" undeployAPICmdLongDesc = "Undeploy an API in Microgateway by specifying name, version, environment, username " + "and optionally vhost" ) -var undeployAPICmdExamples = utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` --environment dev -n petstore -v 0.0.1 - ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --vhost www.pets.com - ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n SwaggerPetstore -v 0.0.1 --environment dev` + +var undeployAPICmdExamples = ` ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` --environment dev -n petstore -v 0.0.1 + ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --vhost www.pets.com + ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev -g "Production and Sandbox" -g Label1 -g Label2 + ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --vhost www.pets.com --gateway-env "Production and Sandbox" + ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n SwaggerPetstore -v 0.0.1 --environment dev - "\n\nNote: The flags --name (-n), --version (-v), --environment (-e) are mandatory. " + - "The user needs to be logged in to use this command." +Note: The flags --name (-n), --version (-v), --environment (-e) are mandatory. +If the flag (--gateway-env (-g)) is not provided, API will be undeployed from all deployed gateway environments. +If the flag (--vhost (-t)) is not provided, API with all VHosts will be undeployed. +The user needs to be logged in to use this command.` // UndeployAPICmd represents the undeploy api command var UndeployAPICmd = &cobra.Command{ @@ -60,6 +68,7 @@ var UndeployAPICmd = &cobra.Command{ queryParams["apiName"] = undeployAPICmdAPIName queryParams["version"] = undeployAPICmdAPIVersion queryParams["vhost"] = undeployAPICmdAPIVHost + queryParams["environments"] = strings.Join(undeployAPICmdAPIGatewayEnvs, gatewayNameSeparator) err := mgImpl.UndeployAPI(undeployAPIEnv, queryParams) if err != nil { utils.HandleErrorAndExit("Error undeploying API", err) @@ -75,6 +84,7 @@ func init() { UndeployAPICmd.Flags().StringVarP(&undeployAPICmdAPIName, "name", "n", "", "API name") UndeployAPICmd.Flags().StringVarP(&undeployAPICmdAPIVersion, "version", "v", "", "API version") UndeployAPICmd.Flags().StringVarP(&undeployAPICmdAPIVHost, "vhost", "t", "", "Virtual host the API needs to be undeployed from") + UndeployAPICmd.Flags().StringSliceVarP(&undeployAPICmdAPIGatewayEnvs, "gateway-env", "g", []string{}, "Gateway environments the API needs to be undeployed from") _ = UndeployAPICmd.MarkFlagRequired("environment") _ = UndeployAPICmd.MarkFlagRequired("name") diff --git a/import-export-cli/docs/apictl_mg_undeploy_api.md b/import-export-cli/docs/apictl_mg_undeploy_api.md index 3e0cf97af..e04585298 100644 --- a/import-export-cli/docs/apictl_mg_undeploy_api.md +++ b/import-export-cli/docs/apictl_mg_undeploy_api.md @@ -13,21 +13,27 @@ apictl mg undeploy api [flags] ### Examples ``` -apictl mg undeploy api --environment dev -n petstore -v 0.0.1 - apictl mg undeploy api -n petstore -v 0.0.1 -e dev --vhost www.pets.com - apictl mg undeploy api -n SwaggerPetstore -v 0.0.1 --environment dev + apictl mg undeploy api --environment dev -n petstore -v 0.0.1 + apictl mg undeploy api -n petstore -v 0.0.1 -e dev --vhost www.pets.com + apictl mg undeploy api -n petstore -v 0.0.1 -e dev -g "Production and Sandbox" -g Label1 -g Label2 + apictl mg undeploy api -n petstore -v 0.0.1 -e dev --vhost www.pets.com --gateway-env "Production and Sandbox" + apictl mg undeploy api -n SwaggerPetstore -v 0.0.1 --environment dev -Note: The flags --name (-n), --version (-v), --environment (-e) are mandatory. The user needs to be logged in to use this command. +Note: The flags --name (-n), --version (-v), --environment (-e) are mandatory. +If the flag (--gateway-env (-g)) is not provided, API will be undeployed from all deployed gateway environments. +If the flag (--vhost (-t)) is not provided, API with all VHosts will be undeployed. +The user needs to be logged in to use this command. ``` ### Options ``` - -e, --environment string Microgateway adapter environment to be undeployed from - -h, --help help for api - -n, --name string API name - -v, --version string API version - -t, --vhost string Virtual host the API needs to be undeployed from + -e, --environment string Microgateway adapter environment to be undeployed from + -g, --gateway-env strings Gateway environments the API needs to be undeployed from + -h, --help help for api + -n, --name string API name + -v, --version string API version + -t, --vhost string Virtual host the API needs to be undeployed from ``` ### Options inherited from parent commands diff --git a/import-export-cli/shell-completions/apictl_bash_completions.sh b/import-export-cli/shell-completions/apictl_bash_completions.sh index a727f57f2..0666b3bf0 100644 --- a/import-export-cli/shell-completions/apictl_bash_completions.sh +++ b/import-export-cli/shell-completions/apictl_bash_completions.sh @@ -2930,6 +2930,12 @@ _apictl_mg_undeploy_api() local_nonpersistent_flags+=("--environment") local_nonpersistent_flags+=("--environment=") local_nonpersistent_flags+=("-e") + flags+=("--gateway-env=") + two_word_flags+=("--gateway-env") + two_word_flags+=("-g") + local_nonpersistent_flags+=("--gateway-env") + local_nonpersistent_flags+=("--gateway-env=") + local_nonpersistent_flags+=("-g") flags+=("--help") flags+=("-h") local_nonpersistent_flags+=("--help")