diff --git a/main.go b/main.go index 974550c..9c948ef 100644 --- a/main.go +++ b/main.go @@ -1097,7 +1097,7 @@ func registerVersionCommand() { Short: "Print the DCI CLI version", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - fmt.Fprintln(os.Stdout, version) + fmt.Fprintf(cmd.OutOrStdout(), "%s version %s\n", cmd.Root().Name(), version) }, }) } diff --git a/main_test.go b/main_test.go index 7c065ac..1b14dd2 100644 --- a/main_test.go +++ b/main_test.go @@ -109,6 +109,7 @@ func TestNormalizeArgs(t *testing.T) { func TestRegisterVersionCommand(t *testing.T) { setupTestRoot(t) + cli.Root.Use = "custom-dci" registerVersionCommand() command, _, err := cli.Root.Find([]string{"version"}) @@ -121,6 +122,13 @@ func TestRegisterVersionCommand(t *testing.T) { if command.Short != "Print the DCI CLI version" { t.Fatalf("short description = %q", command.Short) } + var output strings.Builder + command.SetOut(&output) + command.Run(command, nil) + want := fmt.Sprintf("custom-dci version %s\n", version) + if output.String() != want { + t.Fatalf("output = %q, want %q", output.String(), want) + } } func TestRejectProfileFlags(t *testing.T) {