From f6d995bc3344cbc42f9a2416561d621d21f25933 Mon Sep 17 00:00:00 2001 From: CMGS Date: Wed, 23 Sep 2026 11:37:52 +0800 Subject: [PATCH] fix: reject an unknown verb under the vm and image groups `cocoon-macos vm gc` (gc is top-level) and any other mistyped verb under vm or image printed the group's help and exited 0, so a script calling it passed without running anything. cobra returns ErrHelp for a non-runnable command before it validates args, so both groups now take cobra.NoArgs plus a RunE that prints the help: an unknown verb fails with `unknown command "gc" for "cocoon-macos vm"`, the bare group still prints its help and exits 0. --- cmd/image/commands.go | 7 ++++++- cmd/vm/commands.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/image/commands.go b/cmd/image/commands.go index 80c0865..19db523 100644 --- a/cmd/image/commands.go +++ b/cmd/image/commands.go @@ -7,7 +7,12 @@ import ( ) func Command() *cobra.Command { - imageCmd := &cobra.Command{Use: "image", Short: "Manage macOS disk images (reuses cocoon's cloudimg store)"} // --state-dir is a root persistent flag + imageCmd := &cobra.Command{ + Use: "image", + Short: "Manage macOS disk images (reuses cocoon's cloudimg store)", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Help() }, + } pull := &cobra.Command{ Use: "pull REF", diff --git a/cmd/vm/commands.go b/cmd/vm/commands.go index b9829f7..e91d72c 100644 --- a/cmd/vm/commands.go +++ b/cmd/vm/commands.go @@ -7,7 +7,12 @@ import ( ) func Command() *cobra.Command { - vmCmd := &cobra.Command{Use: "vm", Short: "Manage macOS VMs"} // --state-dir is a root persistent flag + vmCmd := &cobra.Command{ + Use: "vm", + Short: "Manage macOS VMs", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Help() }, + } createCmd := &cobra.Command{ Use: "create [flags] IMAGE",