cobra icon indicating copy to clipboard operation
cobra copied to clipboard

proper message for wrong sub-command

Open thomasmckay opened this issue 1 year ago • 0 comments

In the run of rosa below the error message is unknown flag: --prefix, however the true error message should be something like unknown sub-command: ocm-roles (proper sub-command is singular).

Is there an initialization pattern that would properly report the error?

$ rosa create ocm-roles --prefix testprf --mode auto -y
Error: unknown flag: --prefix
Usage:
  rosa create [command]

Aliases:
  create, add

Available Commands:
  account-roles   Create account-wide IAM roles before creating your cluster.
  ...snip...
  ocm-role        Create role used by OCM

Flags:
  -h, --help             help for create
      --profile string   Use a specific AWS profile from your credential file.
      --region string    Use a specific AWS region, overriding the AWS_REGION environment variable.
  -y, --yes              Automatically answer yes to confirm operation.

Global Flags:
      --color string   Surround certain characters with escape sequences to display them in color on the terminal. Allowed options are [auto never always] (default "auto")
      --debug          Enable debug mode.

Use "rosa create [command] --help" for more information about a command.
var Cmd = &cobra.Command{
	Use:     "create",
	Aliases: []string{"add"},
	Short:   "Create a resource from stdin",
	Long:    "Create a resource from stdin",
}

func init() {
	Cmd.AddCommand(accountroles.Cmd)
        ...snip...
	Cmd.AddCommand(ocmrole.Cmd)

	flags := Cmd.PersistentFlags()
	arguments.AddProfileFlag(flags)
	arguments.AddRegionFlag(flags)
	confirm.AddFlag(flags)

	globallyAvailableCommands := []*cobra.Command{
		accountroles.Cmd, operatorroles.Cmd,
		userrole.Cmd, ocmrole.Cmd,
		oidcprovider.Cmd,
	}
	arguments.MarkRegionHidden(Cmd, globallyAvailableCommands)
}

thomasmckay avatar Sep 07 '23 18:09 thomasmckay