From 938b08c734d580bd31effbf1aee0de472a19e974 Mon Sep 17 00:00:00 2001 From: Fordjent Agent Date: Thu, 21 May 2026 14:48:58 +0000 Subject: [PATCH] [agent-automation] scaffold Go CLI project --- .gitignore | 28 +++++++++++++++++++++ cmd/cli/main.go | 15 +++++++++++ go.mod | 3 +++ pkg/cli/cli.go | 26 +++++++++++++++++++ pkg/cli/cli_test.go | 61 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/cli/main.go create mode 100644 go.mod create mode 100644 pkg/cli/cli.go create mode 100644 pkg/cli/cli_test.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f77ad5f --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Binaries +*.exe +*.exe~ +*.dll +*.so +*.dylib +test +test.exe +test.test + +# Test binary +*.test + +# Output of the go coverage +profile.out + +# Go build directory +vendor/ + +# Binary directory +bin/ + +# IDE +.idea/ +.vscode/ +*.swp +*.swo +*~ diff --git a/cmd/cli/main.go b/cmd/cli/main.go new file mode 100644 index 0000000..80db96e --- /dev/null +++ b/cmd/cli/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "os" + + "github.com/marmaduke/testbed2/pkg/cli" +) + +func main() { + if err := cli.Run(os.Args[1:]); err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1abf670 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/marmaduke/testbed2 + +go 1.21 diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go new file mode 100644 index 0000000..523d0be --- /dev/null +++ b/pkg/cli/cli.go @@ -0,0 +1,26 @@ +// Package cli provides the core CLI functionality. +package cli + +import ( + "fmt" + "os" +) + +// Run executes the CLI with the given arguments. +func Run(args []string) error { + if len(args) == 0 { + fmt.Println("testbed2 CLI") + fmt.Println("Usage: testbed2 ") + return nil + } + + switch args[0] { + case "help", "--help", "-h": + fmt.Println("Available commands:") + fmt.Println(" help Show this help message") + default: + return fmt.Errorf("unknown command: %s", args[0]) + } + + return nil +} diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go new file mode 100644 index 0000000..1f8fe57 --- /dev/null +++ b/pkg/cli/cli_test.go @@ -0,0 +1,61 @@ +package cli + +import ( + "bytes" + "os" + "testing" +) + +func TestRunNoArgs(t *testing.T) { + oldStdout := os.Stdout + r, w, _ := os.Pipe() + os.Stdout = w + + err := Run([]string{}) + + w.Close() + os.Stdout = oldStdout + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } +} + +func TestRunHelp(t *testing.T) { + oldStdout := os.Stdout + r, w, _ := os.Pipe() + os.Stdout = w + + err := Run([]string{"help"}) + + w.Close() + os.Stdout = oldStdout + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } +} + +func TestRunUnknownCommand(t *testing.T) { + err := Run([]string{"unknown"}) + if err == nil { + t.Fatal("expected error for unknown command") + } +} + +func TestRunOutput(t *testing.T) { + oldStdout := os.Stdout + r, w, _ := os.Pipe() + os.Stdout = w + + Run([]string{}) + + w.Close() + os.Stdout = oldStdout + + buf := new(bytes.Buffer) + buf.ReadFrom(r) + if buf.Len() == 0 { + t.Fatal("expected output") + } +}