Make a mistyped subcommand under a group command an error (closes #319)
check / check (push) Waiting to run
check / check (push) Waiting to run
snapshot, config, remote, database and completion had no Run, and cobra checks a command's arguments only when it has one, so `vaultik snapshot craete` printed the group's help and exited 0. Each group now prints its help only when given no argument; any other word fails as an unknown command with exit 1, as at the top level. cobra adds the completion command only when Execute runs, so the root command now adds it itself to give it a Run. Its scripts then go to os.Stdout as it was at that moment; a later SetOut does not redirect them. Judgement call: the error has no "Did you mean" suggestion, which the top level gives. Model: opus-5-5
This commit is contained in:
@@ -41,6 +41,12 @@ func NewSnapshotCommand() *cobra.Command {
|
||||
Use: "snapshot",
|
||||
Short: "Snapshot management commands",
|
||||
Long: "Commands for creating, listing, and managing snapshots",
|
||||
// cobra checks Args only on a command that has a Run: without
|
||||
// one, a mistyped subcommand printed help and exited 0.
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
_ = cmd.Help()
|
||||
},
|
||||
}
|
||||
|
||||
// Add subcommands
|
||||
|
||||
Reference in New Issue
Block a user