From 8a573681be780af3f203872b967efa818ddba9b7 Mon Sep 17 00:00:00 2001 From: ruinivist Date: Tue, 24 Mar 2026 18:27:55 +0000 Subject: [PATCH] fix: add missing help descriptions on some cmds --- cmd/init.go | 5 +++-- cmd/record.go | 5 +++-- cmd/root.go | 3 +++ cmd/root_test.go | 30 ++++++++++++++++++++++++++++-- cmd/test.go | 5 +++-- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 33a4bad..2dc14e3 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -9,8 +9,9 @@ import ( func newInitCommand() *cobra.Command { return &cobra.Command{ - Use: "init", - Args: cobra.NoArgs, + Use: "init", + Short: "Initialise mire in the current project", + Args: cobra.NoArgs, RunE: func(_ *cobra.Command, _ []string) error { if err := mire.Init(); err != nil { return err diff --git a/cmd/record.go b/cmd/record.go index 4b62618..7767e7d 100644 --- a/cmd/record.go +++ b/cmd/record.go @@ -12,8 +12,9 @@ import ( func newRecordCommand() *cobra.Command { return &cobra.Command{ - Use: "record ", - Args: cobra.ExactArgs(1), + Use: "record ", + Short: "Record a new CLI scenario", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { path := filepath.Clean(args[0]) createdPath, err := mire.Record(path) diff --git a/cmd/root.go b/cmd/root.go index 59fbe26..ac2a581 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,6 +29,9 @@ func newRootCommand() *cobra.Command { rootCmd := &cobra.Command{ Use: "mire", Short: "A lean CLI E2E testing framework.", + CompletionOptions: cobra.CompletionOptions{ + HiddenDefaultCmd: true, + }, RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Help() }, diff --git a/cmd/root_test.go b/cmd/root_test.go index 497446a..e2d8557 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -21,8 +21,34 @@ func TestRunShowsHelpWhenNoArgs(t *testing.T) { if !strings.Contains(stdout, "A lean CLI E2E testing framework.") { t.Fatalf("stdout = %q, want root help", stdout) } - if !strings.Contains(stdout, "init") || !strings.Contains(stdout, "record") || !strings.Contains(stdout, "test") { - t.Fatalf("stdout = %q, want listed subcommands", stdout) + for _, want := range []string{ + "init Initialise mire in the current project", + "record Record a new CLI scenario", + "test Replay recorded CLI scenarios", + } { + if !strings.Contains(stdout, want) { + t.Fatalf("stdout = %q, want listed subcommand %q", stdout, want) + } + } + if strings.Contains(stdout, "completion") { + t.Fatalf("stdout = %q, want hidden completion command", stdout) + } + if stderr != "" { + t.Fatalf("stderr = %q, want empty", stderr) + } +} + +func TestRunCompletionStillWorksWhenHidden(t *testing.T) { + testutil.AddFakeRecordDependencies(t, "bwrap", "bash") + + stdout, stderr := testutil.CaptureOutput(t, func() { + if got := Run([]string{"completion", "bash"}); got != 0 { + t.Fatalf("Run() code = %d, want %d", got, 0) + } + }) + + if !strings.Contains(stdout, "# bash completion V2 for mire") { + t.Fatalf("stdout = %q, want bash completion script", stdout) } if stderr != "" { t.Fatalf("stderr = %q, want empty", stderr) diff --git a/cmd/test.go b/cmd/test.go index 929f634..8e6985d 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -8,8 +8,9 @@ import ( func newTestCommand() *cobra.Command { return &cobra.Command{ - Use: "test [path]", - Args: cobra.MaximumNArgs(1), + Use: "test [path]", + Short: "Replay recorded CLI scenarios", + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { path := "" if len(args) == 1 {