Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit a510528

Browse files
authored
Merge pull request #56 from mnottale/cli-no-usage-on-error
cmd: Silence usage on error, except on command line error.
2 parents b338369 + 59ea628 commit a510528

File tree

11 files changed

+25
-20
lines changed

11 files changed

+25
-20
lines changed

cmd/helm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"strings"
77

8+
"github.com/docker/cli/cli"
89
"github.com/docker/lunchbox/internal"
910
"github.com/docker/lunchbox/renderer"
1011
"github.com/spf13/cobra"
@@ -13,7 +14,7 @@ import (
1314
var helmCmd = &cobra.Command{
1415
Use: "helm <app-name> [-c <compose-files>...] [-e key=value...] [-f settings-file...]",
1516
Short: "Render the Compose file for this app as an Helm package",
16-
Args: cobra.MaximumNArgs(1),
17+
Args: cli.RequiresMaxArgs(1),
1718
RunE: func(cmd *cobra.Command, args []string) error {
1819
d := make(map[string]string)
1920
for _, v := range helmEnv {

cmd/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/docker/cli/cli"
67
"github.com/docker/lunchbox/packager"
78
"github.com/spf13/cobra"
89
)
@@ -11,7 +12,7 @@ import (
1112
var initCmd = &cobra.Command{
1213
Use: "init <app-name> [-c <compose-file>]",
1314
Short: "Initialize an app package in the current working directory",
14-
Args: cobra.ExactArgs(1),
15+
Args: cli.ExactArgs(1),
1516
RunE: func(cmd *cobra.Command, args []string) error {
1617
fmt.Println("init called")
1718
return packager.Init(args[0], composeFile)

cmd/inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/docker/cli/cli"
45
"github.com/docker/lunchbox/packager"
56
"github.com/spf13/cobra"
67
)
@@ -9,7 +10,7 @@ import (
910
var inspectCmd = &cobra.Command{
1011
Use: "inspect <app-name>",
1112
Short: "Retrieve metadata for a given app package",
12-
Args: cobra.MaximumNArgs(1),
13+
Args: cli.RequiresMaxArgs(1),
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
app := ""
1516
if len(args) > 0 {

cmd/load.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/docker/cli/cli"
45
"github.com/docker/lunchbox/internal"
56
"github.com/docker/lunchbox/packager"
67
"github.com/spf13/cobra"
@@ -9,7 +10,7 @@ import (
910
var loadCmd = &cobra.Command{
1011
Use: "load <repotag>",
1112
Short: "Load an app from docker",
12-
Args: cobra.MaximumNArgs(1),
13+
Args: cli.RequiresMaxArgs(1),
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
app := ""
1516
if len(args) > 0 {

cmd/pack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/docker/cli/cli"
45
"github.com/docker/lunchbox/internal"
56
"github.com/docker/lunchbox/packager"
67
"github.com/spf13/cobra"
@@ -9,7 +10,7 @@ import (
910
var packCmd = &cobra.Command{
1011
Use: "pack <app-name> [-o output_file]",
1112
Short: "Pack this app as a single file",
12-
Args: cobra.MaximumNArgs(1),
13+
Args: cli.RequiresMaxArgs(1),
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
app := ""
1516
if len(args) > 0 {

cmd/pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/docker/cli/cli"
45
"github.com/docker/lunchbox/internal"
56
"github.com/docker/lunchbox/packager"
67
"github.com/spf13/cobra"
@@ -9,7 +10,7 @@ import (
910
var pullCmd = &cobra.Command{
1011
Use: "pull <repotag>",
1112
Short: "Pull an app from a registry",
12-
Args: cobra.ExactArgs(1),
13+
Args: cli.ExactArgs(1),
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
return packager.Pull(args[0])
1516
},

cmd/push.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/docker/cli/cli"
45
"github.com/docker/lunchbox/internal"
56
"github.com/docker/lunchbox/packager"
67
"github.com/spf13/cobra"
@@ -9,7 +10,7 @@ import (
910
var pushCmd = &cobra.Command{
1011
Use: "push <app-name>",
1112
Short: "Push the application to a registry",
12-
Args: cobra.MaximumNArgs(1),
13+
Args: cli.RequiresMaxArgs(1),
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
if pushTag == "" {
1516
pushTag = "latest"

cmd/render.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"strings"
77

8+
"github.com/docker/cli/cli"
89
"github.com/docker/lunchbox/internal"
910
"github.com/docker/lunchbox/renderer"
1011
"github.com/spf13/cobra"
@@ -21,7 +22,7 @@ Override is provided in different ways:
2122
- Individual settings values can be passed directly on the command line with the
2223
-s flag. These value takes precedence over all settings files.
2324
`,
24-
Args: cobra.MaximumNArgs(1),
25+
Args: cli.RequiresMaxArgs(1),
2526
RunE: func(cmd *cobra.Command, args []string) error {
2627
d := make(map[string]string)
2728
for _, v := range renderEnv {

cmd/root.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
"os"
6-
74
"github.com/spf13/cobra"
85
)
96

107
// rootCmd represents the base command when called without any subcommands
118
var rootCmd = &cobra.Command{
12-
Use: "docker-app",
13-
Short: "Docker App Packages",
14-
Long: "",
9+
Use: "docker-app",
10+
Short: "Docker App Packages",
11+
Long: "",
12+
SilenceUsage: true,
1513
}
1614

1715
// Execute adds all child commands to the root command and sets flags appropriately.
1816
// This is called by main.main(). It only needs to happen once to the rootCmd.
1917
func Execute() {
20-
if err := rootCmd.Execute(); err != nil {
21-
fmt.Println(err)
22-
os.Exit(1)
23-
}
18+
rootCmd.Execute()
2419
}
2520

2621
func init() {

cmd/save.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/docker/cli/cli"
45
"github.com/docker/lunchbox/internal"
56
"github.com/docker/lunchbox/packager"
67
"github.com/spf13/cobra"
@@ -9,7 +10,7 @@ import (
910
var saveCmd = &cobra.Command{
1011
Use: "save <app-name>",
1112
Short: "Save the application to docker (in preparation for push)",
12-
Args: cobra.MaximumNArgs(1),
13+
Args: cli.RequiresMaxArgs(1),
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
if saveTag == "" {
1516
saveTag = "latest"

0 commit comments

Comments
 (0)