Skip to content

Commit

Permalink
Do not call LogErrorAndExit but return err in GenericRun (#6352)
Browse files Browse the repository at this point in the history
* Do not call LogErrorAndExit but return err in GenericRun

* Review
  • Loading branch information
feloy authored Nov 30, 2022
1 parent aba1515 commit 3fc9f97
Show file tree
Hide file tree
Showing 30 changed files with 95 additions and 78 deletions.
4 changes: 2 additions & 2 deletions pkg/odo/cli/add/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/alizer/alizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/build_images/build_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/create/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/delete/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions pkg/odo/cli/delete/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/describe/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/list/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/list/component/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/list/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,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"},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/list/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/preference/add/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/preference/remove/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/preference/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/preference/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/preference/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/remove/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/set/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 3fc9f97

Please sign in to comment.