Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring, and a usage tweak, for 2580 #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion cmd/podman/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ func noSubArgs(c *cobra.Command, args []string) error {
return nil
}

/// badSubArg complains about unrecognized commands or subcommands
func badSubArg(c *cobra.Command, args []string) error {
var msg string

if len(args) > 0 {
msg = fmt.Sprintf("unrecognized command `%s %s`", c.CommandPath(), args[0])
} else {
msg = fmt.Sprintf("`%s` requires a subcommand", c.CommandPath())
}

return errors.Errorf(msg + "\nTry '%s --help' for more information", c.CommandPath())
}

// getAllOrLatestContainers tries to return the correct list of containers
// depending if --all, --latest or <container-id> is used.
// It requires the Context (c) and the Runtime (runtime). As different
Expand Down Expand Up @@ -537,7 +550,7 @@ Description:
// This blocks the desplaying of the global options. The main podman
// command should not use this.
func UsageTemplate() string {
return `Usage:{{if .Runnable}}
return `Usage:{{if (and .Runnable (not .HasAvailableSubCommands))}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}

Expand Down
1 change: 1 addition & 0 deletions cmd/podman/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
Short: "Manage Containers",
Long: containerDescription,
TraverseChildren: true,
RunE: badSubArg,
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/podman/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
Use: "generate",
Short: "Generated structured data",
Long: generateDescription,
RunE: badSubArg,
}
)

Expand Down
1 change: 1 addition & 0 deletions cmd/podman/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var healthcheckCommand = cliconfig.PodmanCommand{
Use: "healthcheck",
Short: "Manage Healthcheck",
Long: healthcheckDescription,
RunE: badSubArg,
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/podman/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
Use: "image",
Short: "Manage images",
Long: imageDescription,
RunE: badSubArg,
},
}
imagesSubCommand cliconfig.ImagesValues
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ var cmdsNotRequiringRootless = map[*cobra.Command]bool{
var rootCmd = &cobra.Command{
Use: "podman",
Long: "manage pods and images",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
RunE: badSubArg,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return before(cmd, args)
},
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
Use: "play",
Short: "Play a pod",
Long: playDescription,
RunE: badSubArg,
}
)

Expand Down
1 change: 1 addition & 0 deletions cmd/podman/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var podCommand = cliconfig.PodmanCommand{
Use: "pod",
Short: "Manage pods",
Long: podDescription,
RunE: badSubArg,
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/podman/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
Use: "system",
Short: "Manage podman",
Long: systemDescription,
RunE: badSubArg,
},
}
)
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
Use: "trust",
Short: "Manage container image trust policy",
Long: trustDescription,
RunE: badSubArg,
},
}
)
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var volumeCommand = cliconfig.PodmanCommand{
Use: "volume",
Short: "Manage volumes",
Long: volumeDescription,
RunE: badSubArg,
},
}
var volumeSubcommands = []*cobra.Command{
Expand Down