Compare commits
5 commits
main
...
scaffold-g
| Author | SHA1 | Date | |
|---|---|---|---|
| 316df86029 | |||
|
|
b16de316e4 | ||
|
|
37083dd4c1 | ||
|
|
452ef5f1fa | ||
|
|
938b08c734 |
6 changed files with 147 additions and 0 deletions
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
|
|
@ -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
|
||||
*~
|
||||
15
cmd/cli/main.go
Normal file
15
cmd/cli/main.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
15
cmd/testbed2/main.go
Normal file
15
cmd/testbed2/main.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
3
go.mod
Normal file
3
go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/marmaduke/testbed2
|
||||
|
||||
go 1.21
|
||||
25
pkg/cli/cli.go
Normal file
25
pkg/cli/cli.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Package cli provides the core CLI functionality.
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 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 <command>")
|
||||
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
|
||||
}
|
||||
61
pkg/cli/cli_test.go
Normal file
61
pkg/cli/cli_test.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunNoArgs(t *testing.T) {
|
||||
oldStdout := os.Stdout
|
||||
_, 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
|
||||
_, 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")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue