From ded2b235c658d70631a95a96daa1aa79e6dd882f Mon Sep 17 00:00:00 2001 From: Michael Finson Date: Mon, 3 Aug 2026 20:20:14 +0300 Subject: [PATCH 1/2] fix: normalize version command output --- main.go | 2 +- main_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6cafdac..d7e0795 100644 --- a/main.go +++ b/main.go @@ -1090,7 +1090,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 8b2ea11..23e39e2 100644 --- a/main_test.go +++ b/main_test.go @@ -121,6 +121,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("%s version %s\n", cli.Root.Name(), version) + if output.String() != want { + t.Fatalf("output = %q, want %q", output.String(), want) + } } func TestRejectProfileFlags(t *testing.T) { From 2e1e2a339bb9d099a1d519eec37c9b5c4ad2d468 Mon Sep 17 00:00:00 2001 From: Michael Finson Date: Tue, 4 Aug 2026 15:11:03 +0300 Subject: [PATCH 2/2] test(version): verify root command naming --- main_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 00e0579..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"}) @@ -124,7 +125,7 @@ func TestRegisterVersionCommand(t *testing.T) { var output strings.Builder command.SetOut(&output) command.Run(command, nil) - want := fmt.Sprintf("%s version %s\n", cli.Root.Name(), version) + want := fmt.Sprintf("custom-dci version %s\n", version) if output.String() != want { t.Fatalf("output = %q, want %q", output.String(), want) }