From e812e3a4115c6629718f38f7a19bc4bc58442a1f Mon Sep 17 00:00:00 2001 From: Byron Guina Date: Sun, 15 Mar 2026 22:45:13 -0500 Subject: [PATCH 1/2] feat: add hello command that prints hello world Adds a simple 'af hello' subcommand that prints "hello world" to stdout. Includes a unit test verifying the output. --- cmd/af/cmd/hello.go | 19 +++++++++++++++++++ cmd/af/cmd/hello_test.go | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 cmd/af/cmd/hello.go create mode 100644 cmd/af/cmd/hello_test.go diff --git a/cmd/af/cmd/hello.go b/cmd/af/cmd/hello.go new file mode 100644 index 0000000..6a1b6ab --- /dev/null +++ b/cmd/af/cmd/hello.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var helloCmd = &cobra.Command{ + Use: "hello", + Short: "Print a greeting", + Run: func(cmd *cobra.Command, args []string) { + fmt.Fprintln(cmd.OutOrStdout(), "hello world") + }, +} + +func init() { + rootCmd.AddCommand(helloCmd) +} diff --git a/cmd/af/cmd/hello_test.go b/cmd/af/cmd/hello_test.go new file mode 100644 index 0000000..b97976f --- /dev/null +++ b/cmd/af/cmd/hello_test.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "bytes" + "testing" +) + +func TestHelloCmdPrintsHelloWorld(t *testing.T) { + var buf bytes.Buffer + helloCmd.SetOut(&buf) + + helloCmd.Run(helloCmd, nil) + + got := buf.String() + want := "hello world\n" + if got != want { + t.Fatalf("hello output = %q, want %q", got, want) + } +} From 3dffa82167a1534ec41d5f34f2680f4ec02b131a Mon Sep 17 00:00:00 2001 From: Byron Guina Date: Sun, 15 Mar 2026 22:46:18 -0500 Subject: [PATCH 2/2] chore: add test cleanup for helloCmd output buffer Review finding: SetOut on package-level command should be reset after test to prevent state leakage between tests. --- cmd/af/cmd/hello_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/af/cmd/hello_test.go b/cmd/af/cmd/hello_test.go index b97976f..c8afa93 100644 --- a/cmd/af/cmd/hello_test.go +++ b/cmd/af/cmd/hello_test.go @@ -8,6 +8,7 @@ import ( func TestHelloCmdPrintsHelloWorld(t *testing.T) { var buf bytes.Buffer helloCmd.SetOut(&buf) + t.Cleanup(func() { helloCmd.SetOut(nil) }) helloCmd.Run(helloCmd, nil)