diff --git a/pkg/odo/cli/add/binding/binding.go b/pkg/odo/cli/add/binding/binding.go index 9b2e604e432..2a253bdc54b 100644 --- a/pkg/odo/cli/add/binding/binding.go +++ b/pkg/odo/cli/add/binding/binding.go @@ -195,8 +195,8 @@ func NewCmdBinding(name, fullName string) *cobra.Command { Long: "Add a binding between a service and the component in the devfile", Args: genericclioptions.NoArgsAndSilenceJSON, Example: fmt.Sprintf(addBindingExample, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } bindingCmd.Flags().String(backend.FLAG_NAME, "", "Name of the Binding to create") diff --git a/pkg/odo/cli/alizer/alizer.go b/pkg/odo/cli/alizer/alizer.go index 5cf8bfaabf8..b69701a7cb6 100644 --- a/pkg/odo/cli/alizer/alizer.go +++ b/pkg/odo/cli/alizer/alizer.go @@ -65,8 +65,8 @@ func NewCmdAlizer(name, fullName string) *cobra.Command { Long: "Detect devfile to use based on files present in current directory", Args: cobra.MaximumNArgs(0), Annotations: map[string]string{}, - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(alizerCmd, clientset.ALIZER, clientset.FILESYSTEM) diff --git a/pkg/odo/cli/build_images/build_images.go b/pkg/odo/cli/build_images/build_images.go index 93bde170b5c..b0447f8b5db 100644 --- a/pkg/odo/cli/build_images/build_images.go +++ b/pkg/odo/cli/build_images/build_images.go @@ -74,8 +74,8 @@ func NewCmdBuildImages(name, fullName string) *cobra.Command { Long: "Build images defined in the devfile", Example: fmt.Sprintf(buildImagesExample, fullName), Args: cobra.MaximumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } diff --git a/pkg/odo/cli/create/namespace/namespace.go b/pkg/odo/cli/create/namespace/namespace.go index 25913fb48c2..4ab7a62083f 100644 --- a/pkg/odo/cli/create/namespace/namespace.go +++ b/pkg/odo/cli/create/namespace/namespace.go @@ -125,8 +125,8 @@ func NewCmdNamespaceCreate(name, fullName string) *cobra.Command { Long: createLongDesc, Example: fmt.Sprintf(createExample, fullName), Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, Annotations: map[string]string{"command": "main"}, Aliases: []string{"project"}, diff --git a/pkg/odo/cli/delete/component/component.go b/pkg/odo/cli/delete/component/component.go index 9c4abbb5251..bf53f5e796b 100644 --- a/pkg/odo/cli/delete/component/component.go +++ b/pkg/odo/cli/delete/component/component.go @@ -316,8 +316,8 @@ func NewCmdComponent(name, fullName string) *cobra.Command { Long: "Delete component", Args: genericclioptions.NoArgsAndSilenceJSON, Example: fmt.Sprintf(deleteExample, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } componentCmd.Flags().StringVar(&o.name, "name", "", "Name of the component to delete, optional. By default, the component described in the local devfile is deleted") diff --git a/pkg/odo/cli/delete/namespace/namespace.go b/pkg/odo/cli/delete/namespace/namespace.go index 157583b3f95..6605b1212e1 100644 --- a/pkg/odo/cli/delete/namespace/namespace.go +++ b/pkg/odo/cli/delete/namespace/namespace.go @@ -3,9 +3,10 @@ package namespace import ( "context" "fmt" + "os" + "github.com/spf13/cobra" ktemplates "k8s.io/kubectl/pkg/util/templates" - "os" "github.com/redhat-developer/odo/pkg/log" "github.com/redhat-developer/odo/pkg/odo/cli/ui" @@ -117,8 +118,8 @@ func NewCmdNamespaceDelete(name, fullName string) *cobra.Command { Long: deleteLongDesc, Example: fmt.Sprintf(deleteExample, fullName), Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(do, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(do, cmd, args) }, Annotations: map[string]string{"command": "main"}, Aliases: []string{"project"}, diff --git a/pkg/odo/cli/deploy/deploy.go b/pkg/odo/cli/deploy/deploy.go index 54cfac78429..646d6326efc 100644 --- a/pkg/odo/cli/deploy/deploy.go +++ b/pkg/odo/cli/deploy/deploy.go @@ -99,8 +99,8 @@ func NewCmdDeploy(name, fullName string) *cobra.Command { Long: "Deploy the components defined in the devfile", Example: fmt.Sprintf(deployExample, fullName), Args: cobra.MaximumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(deployCmd, clientset.INIT, clientset.DEPLOY, clientset.FILESYSTEM) diff --git a/pkg/odo/cli/describe/binding.go b/pkg/odo/cli/describe/binding.go index 62460c37672..59de283db10 100644 --- a/pkg/odo/cli/describe/binding.go +++ b/pkg/odo/cli/describe/binding.go @@ -113,8 +113,8 @@ func NewCmdBinding(name, fullName string) *cobra.Command { Long: "Describe bindings", Args: genericclioptions.NoArgsAndSilenceJSON, Example: fmt.Sprintf(describeBindingExample, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } bindingCmd.Flags().StringVar(&o.nameFlag, "name", "", "Name of the binding to describe, optional. By default, the bindings in the local devfile are described") diff --git a/pkg/odo/cli/describe/component.go b/pkg/odo/cli/describe/component.go index c02649e7049..1a084a59f78 100644 --- a/pkg/odo/cli/describe/component.go +++ b/pkg/odo/cli/describe/component.go @@ -286,8 +286,8 @@ func NewCmdComponent(name, fullName string) *cobra.Command { Long: "Describe a component", Args: genericclioptions.NoArgsAndSilenceJSON, Example: fmt.Sprintf(describeExample, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } componentCmd.Flags().StringVar(&o.nameFlag, "name", "", "Name of the component to describe, optional. By default, the component in the local devfile is described") diff --git a/pkg/odo/cli/dev/dev.go b/pkg/odo/cli/dev/dev.go index 92520f9ad64..5b0eb1731fa 100644 --- a/pkg/odo/cli/dev/dev.go +++ b/pkg/odo/cli/dev/dev.go @@ -208,8 +208,8 @@ func NewCmdDev(name, fullName string) *cobra.Command { It forwards endpoints with any exposure values ('public', 'internal' or 'none') to a port on localhost.`, Example: fmt.Sprintf(devExample, fullName), Args: cobra.MaximumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } devCmd.Flags().BoolVar(&o.noWatchFlag, "no-watch", false, "Do not watch for file changes") diff --git a/pkg/odo/cli/init/init.go b/pkg/odo/cli/init/init.go index c468f439c4c..b914b5a3d0c 100644 --- a/pkg/odo/cli/init/init.go +++ b/pkg/odo/cli/init/init.go @@ -256,8 +256,8 @@ func NewCmdInit(name, fullName string) *cobra.Command { Long: "Bootstraps a new project", Example: fmt.Sprintf(initExample, fullName), Args: cobra.MaximumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(initCmd, clientset.PREFERENCE, clientset.FILESYSTEM, clientset.REGISTRY, clientset.INIT) diff --git a/pkg/odo/cli/list/binding/binding.go b/pkg/odo/cli/list/binding/binding.go index d1c4fb29db7..bbb9ea31258 100644 --- a/pkg/odo/cli/list/binding/binding.go +++ b/pkg/odo/cli/list/binding/binding.go @@ -111,8 +111,8 @@ func NewCmdBindingList(name, fullName string) *cobra.Command { Long: listLongDesc, Example: fmt.Sprintf(listExample, fullName), Args: cobra.ExactArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, Aliases: []string{"bindings"}, } diff --git a/pkg/odo/cli/list/component/list.go b/pkg/odo/cli/list/component/list.go index 0b0dd61e615..e0c1fdd0c4e 100644 --- a/pkg/odo/cli/list/component/list.go +++ b/pkg/odo/cli/list/component/list.go @@ -127,8 +127,8 @@ func NewCmdComponentList(name, fullName string) *cobra.Command { Example: fmt.Sprintf(listExample, fullName), Args: genericclioptions.NoArgsAndSilenceJSON, Annotations: map[string]string{"command": "management"}, - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, Aliases: []string{"components"}, } diff --git a/pkg/odo/cli/list/list.go b/pkg/odo/cli/list/list.go index 33537bce5ed..de035a7867c 100644 --- a/pkg/odo/cli/list/list.go +++ b/pkg/odo/cli/list/list.go @@ -146,8 +146,8 @@ func NewCmdList(name, fullName string) *cobra.Command { Example: fmt.Sprintf(listExample, fullName), Args: genericclioptions.NoArgsAndSilenceJSON, Annotations: map[string]string{"command": "management"}, - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(listCmd, clientset.KUBERNETES, clientset.BINDING, clientset.FILESYSTEM) diff --git a/pkg/odo/cli/list/namespace/namespace.go b/pkg/odo/cli/list/namespace/namespace.go index 86b589dc61b..5a4cb6beb87 100644 --- a/pkg/odo/cli/list/namespace/namespace.go +++ b/pkg/odo/cli/list/namespace/namespace.go @@ -109,8 +109,8 @@ func NewCmdNamespaceList(name, fullName string) *cobra.Command { Long: listLongDesc, Example: fmt.Sprintf(listExample, fullName), Args: cobra.ExactArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, Aliases: []string{"namespaces", "project", "projects"}, } diff --git a/pkg/odo/cli/list/services/services.go b/pkg/odo/cli/list/services/services.go index e4ec1b8a9a9..7885bf95788 100644 --- a/pkg/odo/cli/list/services/services.go +++ b/pkg/odo/cli/list/services/services.go @@ -161,8 +161,8 @@ func NewCmdServicesList(name, fullName string) *cobra.Command { Long: listLongDesc, Example: fmt.Sprintf(listExample, fullName), Args: cobra.ExactArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, Aliases: []string{"service"}, } diff --git a/pkg/odo/cli/login/login.go b/pkg/odo/cli/login/login.go index 07ce564a562..50741a988a1 100644 --- a/pkg/odo/cli/login/login.go +++ b/pkg/odo/cli/login/login.go @@ -100,8 +100,8 @@ func NewCmdLogin(name, fullName string) *cobra.Command { Long: "Login to cluster", Example: fmt.Sprintf(loginExample, fullName), Args: cobra.MaximumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } diff --git a/pkg/odo/cli/logout/logout.go b/pkg/odo/cli/logout/logout.go index d5aaf8d883a..ae2909f1915 100644 --- a/pkg/odo/cli/logout/logout.go +++ b/pkg/odo/cli/logout/logout.go @@ -61,8 +61,8 @@ func NewCmdLogout(name, fullName string) *cobra.Command { Long: "Logout of the cluster.", Example: fmt.Sprintf(example, fullName), Args: genericclioptions.NoArgsAndSilenceJSON, - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } diff --git a/pkg/odo/cli/logs/logs.go b/pkg/odo/cli/logs/logs.go index 6855bea911b..9b57ab02f2b 100644 --- a/pkg/odo/cli/logs/logs.go +++ b/pkg/odo/cli/logs/logs.go @@ -234,8 +234,8 @@ func NewCmdLogs(name, fullname string) *cobra.Command { By default it shows logs of all containers running in both Dev and Deploy mode. It prefixes each log message with the container name.`, Example: fmt.Sprintf(logsExample, fullname), Args: cobra.MaximumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } logsCmd.Flags().BoolVar(&o.devMode, string(DevMode), false, "Show logs for containers running only in Dev mode") diff --git a/pkg/odo/cli/preference/add/registry.go b/pkg/odo/cli/preference/add/registry.go index ece05ff19ac..1cd17acb21b 100644 --- a/pkg/odo/cli/preference/add/registry.go +++ b/pkg/odo/cli/preference/add/registry.go @@ -115,8 +115,8 @@ func NewCmdRegistry(name, fullName string) *cobra.Command { Long: addLongDesc, Example: fmt.Sprintf(fmt.Sprint(addExample), fullName), Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(registryCmd, clientset.PREFERENCE) diff --git a/pkg/odo/cli/preference/remove/registry.go b/pkg/odo/cli/preference/remove/registry.go index a3111322dab..34a7e9ebad1 100644 --- a/pkg/odo/cli/preference/remove/registry.go +++ b/pkg/odo/cli/preference/remove/registry.go @@ -97,8 +97,8 @@ func NewCmdRegistry(name, fullName string) *cobra.Command { Long: removeLongDesc, Example: fmt.Sprintf(fmt.Sprint(removeExample), fullName), Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(registryDeleteCmd, clientset.PREFERENCE) diff --git a/pkg/odo/cli/preference/set.go b/pkg/odo/cli/preference/set.go index 6de18a22364..2b32a1bafd3 100644 --- a/pkg/odo/cli/preference/set.go +++ b/pkg/odo/cli/preference/set.go @@ -106,8 +106,8 @@ func NewCmdSet(ctx context.Context, name, fullName string) *cobra.Command { return "\n" + exampleString }(setExample, fullName), Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(preferenceSetCmd, clientset.PREFERENCE) diff --git a/pkg/odo/cli/preference/unset.go b/pkg/odo/cli/preference/unset.go index 9348f8d9a96..1a4d665d830 100644 --- a/pkg/odo/cli/preference/unset.go +++ b/pkg/odo/cli/preference/unset.go @@ -104,8 +104,8 @@ func NewCmdUnset(name, fullName string) *cobra.Command { return "\n" + exampleString + "\n" }(unsetExample, fullName), Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(preferenceUnsetCmd, clientset.PREFERENCE) diff --git a/pkg/odo/cli/preference/view.go b/pkg/odo/cli/preference/view.go index cbc6eb1bbe5..97302bb8392 100644 --- a/pkg/odo/cli/preference/view.go +++ b/pkg/odo/cli/preference/view.go @@ -128,8 +128,8 @@ func NewCmdView(name, fullName string) *cobra.Command { Example: fmt.Sprintf(fmt.Sprint("\n", viewExample), fullName), Args: cobra.ExactArgs(0), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(preferenceViewCmd, clientset.PREFERENCE) diff --git a/pkg/odo/cli/registry/registry.go b/pkg/odo/cli/registry/registry.go index 3743e3bc163..3b326227caf 100644 --- a/pkg/odo/cli/registry/registry.go +++ b/pkg/odo/cli/registry/registry.go @@ -108,8 +108,8 @@ func NewCmdRegistry(name, fullName string) *cobra.Command { Short: "List all components from the Devfile registry", Long: "List all components from the Devfile registry", Example: fmt.Sprintf(Example, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } diff --git a/pkg/odo/cli/remove/binding/binding.go b/pkg/odo/cli/remove/binding/binding.go index 2cc58632f17..1e5659714a5 100644 --- a/pkg/odo/cli/remove/binding/binding.go +++ b/pkg/odo/cli/remove/binding/binding.go @@ -81,8 +81,8 @@ func NewCmdBinding(name, fullName string) *cobra.Command { Long: "Remove a binding between a service and the component from the devfile", Args: genericclioptions.NoArgsAndSilenceJSON, Example: fmt.Sprintf(removeBindingExample, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } bindingCmd.Flags().String(backend.FLAG_NAME, "", "Name of the Binding to create") diff --git a/pkg/odo/cli/set/namespace/namespace.go b/pkg/odo/cli/set/namespace/namespace.go index 4ff5ff5cf5b..c39ef436d5f 100644 --- a/pkg/odo/cli/set/namespace/namespace.go +++ b/pkg/odo/cli/set/namespace/namespace.go @@ -96,8 +96,8 @@ func NewCmdNamespaceSet(name, fullName string) *cobra.Command { Long: setLongDesc, Example: fmt.Sprintf(setExample, fullName), Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, Annotations: map[string]string{"command": "main"}, Aliases: []string{"project"}, diff --git a/pkg/odo/cli/telemetry/telemetry.go b/pkg/odo/cli/telemetry/telemetry.go index 4685208ef19..3320949c28a 100644 --- a/pkg/odo/cli/telemetry/telemetry.go +++ b/pkg/odo/cli/telemetry/telemetry.go @@ -85,8 +85,8 @@ func NewCmdTelemetry(name string) *cobra.Command { DisableFlagsInUseLine: true, DisableSuggestions: true, FParseErrWhitelist: cobra.FParseErrWhitelist{}, - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(telemetryCmd) diff --git a/pkg/odo/cli/version/version.go b/pkg/odo/cli/version/version.go index c97bd9b70cb..4e9e45449f9 100644 --- a/pkg/odo/cli/version/version.go +++ b/pkg/odo/cli/version/version.go @@ -125,8 +125,8 @@ func NewCmdVersion(name, fullName string) *cobra.Command { Short: versionLongDesc, Long: versionLongDesc, Example: fmt.Sprintf(versionExample, fullName), - Run: func(cmd *cobra.Command, args []string) { - genericclioptions.GenericRun(o, cmd, args) + RunE: func(cmd *cobra.Command, args []string) error { + return genericclioptions.GenericRun(o, cmd, args) }, } clientset.Add(versionCmd, clientset.PREFERENCE) diff --git a/pkg/odo/genericclioptions/runnable.go b/pkg/odo/genericclioptions/runnable.go index b0a94a32919..b7d95ac9e40 100644 --- a/pkg/odo/genericclioptions/runnable.go +++ b/pkg/odo/genericclioptions/runnable.go @@ -41,7 +41,6 @@ import ( "github.com/spf13/cobra" "github.com/redhat-developer/odo/pkg/log" - "github.com/redhat-developer/odo/pkg/odo/util" ) type Runnable interface { @@ -79,13 +78,20 @@ const ( defaultAppName = "app" ) -func GenericRun(o Runnable, cmd *cobra.Command, args []string) { +func GenericRun(o Runnable, cmd *cobra.Command, args []string) error { var ( err error startTime = time.Now() ctx = cmd.Context() ) + defer func() { + if err != nil { + cmd.SilenceErrors = true + cmd.SilenceUsage = true + } + }() + userConfig, _ := preference.NewClient(ctx) envConfig := envcontext.GetEnvConfig(ctx) @@ -101,9 +107,8 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { // check for conflicting settings if trackingConsentErr == nil && disableTelemetryEnvSet && trackingConsentEnvSet && disableTelemetry == isTrackingConsentEnabled { //lint:ignore SA1019 We deprecated this env var, but we really want users to know there is a conflict here - util.LogErrorAndExit( - fmt.Errorf("%[1]s and %[2]s values are in conflict. %[1]s is deprecated, please use only %[2]s", - segment.DisableTelemetryEnv, segment.TrackingConsentEnv), "") + return fmt.Errorf("%[1]s and %[2]s values are in conflict. %[1]s is deprecated, please use only %[2]s", + segment.DisableTelemetryEnv, segment.TrackingConsentEnv) } // Prompt the user to consent for telemetry if a value is not set already @@ -154,6 +159,7 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { err = scontext.SetCaller(cmd.Context(), envConfig.TelemetryCaller) if err != nil { klog.V(3).Infof("error handling caller property for telemetry: %v", err) + err = nil } scontext.SetFlags(cmd.Context(), cmd.Flags()) @@ -174,15 +180,25 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { startTelemetry(cmd, err, startTime) }) - util.LogErrorAndExit(commonflags.CheckMachineReadableOutputCommand(&envConfig, cmd), "") - util.LogErrorAndExit(commonflags.CheckRunOnCommand(cmd), "") - util.LogErrorAndExit(commonflags.CheckVariablesCommand(cmd), "") + err = commonflags.CheckMachineReadableOutputCommand(&envConfig, cmd) + if err != nil { + return err + } + err = commonflags.CheckRunOnCommand(cmd) + if err != nil { + return err + } + err = commonflags.CheckVariablesCommand(cmd) + if err != nil { + return err + } cmdLineObj := cmdline.NewCobra(cmd) platform := commonflags.GetRunOnValue(cmdLineObj) deps, err := clientset.Fetch(cmd, platform) if err != nil { - util.LogErrorAndExit(err, "") + return err + } o.SetClientset(deps) @@ -200,13 +216,16 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { cwd, err = deps.FS.Getwd() if err != nil { startTelemetry(cmd, err, startTime) + return err } - util.LogErrorAndExit(err, "") ctx = odocontext.WithWorkingDirectory(ctx, cwd) var variables map[string]string variables, err = commonflags.GetVariablesValues(cmdLineObj) - util.LogErrorAndExit(err, "") + if err != nil { + return err + + } ctx = fcontext.WithVariables(ctx, variables) if preiniter, ok := o.(PreIniter); ok { @@ -214,8 +233,8 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { err = runPreInit(ctx, cwd, deps, cmdLineObj, msg) if err != nil { startTelemetry(cmd, err, startTime) + return err } - util.LogErrorAndExit(err, "") } var devfilePath, componentName string @@ -223,8 +242,8 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { devfilePath, devfileObj, componentName, err = getDevfileInfo(cwd, variables) if err != nil { startTelemetry(cmd, err, startTime) + return err } - util.LogErrorAndExit(err, "") ctx = odocontext.WithDevfilePath(ctx, devfilePath) ctx = odocontext.WithDevfileObj(ctx, devfileObj) ctx = odocontext.WithComponentName(ctx, componentName) @@ -235,14 +254,14 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { err = o.Complete(ctx, cmdLineObj, args) if err != nil { startTelemetry(cmd, err, startTime) + return err } - util.LogErrorAndExit(err, "") err = o.Validate(ctx) if err != nil { startTelemetry(cmd, err, startTime) + return err } - util.LogErrorAndExit(err, "") if jsonOutputter, ok := o.(JsonOutputter); ok && log.IsJSON() { var out interface{} @@ -254,13 +273,10 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) { err = o.Run(ctx) } startTelemetry(cmd, err, startTime) - util.LogError(err, "") if cleanuper, ok := o.(Cleanuper); ok { cleanuper.Cleanup(ctx, err) } - if err != nil { - os.Exit(1) - } + return err } // startTelemetry uploads the data to segment if user has consented to usage data collection and the command is not telemetry