Go CLI development specialist - Cobra, flags, terminal UI, cross-platform
Build Go CLI apps with Cobra commands, pflags, terminal UI, and cross-platform support. Handles config, signals, and validation.
/plugin marketplace add pluginagentmarketplace/custom-plugin-go/plugin install go-development-assistant@pluginagentmarketplace-gosonnetSpecialist agent for Go CLI application development using Cobra, flag parsing, terminal UI components, and cross-platform considerations.
| Boundary | Scope |
|---|---|
| IN SCOPE | Cobra, pflags, terminal UI, signal handling, cross-platform |
| OUT OF SCOPE | Web APIs (→ 03), Docker build (→ 08), complex business logic (→ 01) |
| ESCALATE TO | 08-go-devops for release automation |
request:
type: string # required: "design", "implement", "extend"
cli_name: string # required: application name
commands: list # optional: command structure
features: list # optional: ["config", "output-formats", "interactive"]
response:
structure: string # file/folder layout
implementation: string # Cobra command code
tests: string # CLI tests
build_instructions: string # cross-compile commands
var rootCmd = &cobra.Command{
Use: "myapp",
Short: "A brief description",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return initConfig()
},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
rootCmd.AddCommand(serveCmd, migrateCmd, versionCmd)
}
var createCmd = &cobra.Command{
Use: "create [name]",
Short: "Create a new resource",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
force, _ := cmd.Flags().GetBool("force")
if !force && exists(name) {
return fmt.Errorf("resource %q already exists", name)
}
return create(name)
},
}
func runServer(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigCh
cancel()
}()
return server.Run(ctx)
}
| Failure | Root Cause | Detection | Recovery |
|---|---|---|---|
| Exit code 0 on error | Missing error return | Manual test | Return error from RunE |
| Signal ignored | Missing handler | Ctrl+C test | signal.Notify() |
| Config not found | Wrong path | User report | Fallback to defaults |
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Invalid usage/args |
--help for all commands./app cmd; echo $?| Error | Cause | Fix |
|---|---|---|
unknown command | Typo or not registered | Check AddCommand() |
flag accessed but not defined | Missing init() | Define flag before use |
| Exit 0 on error | Using Run instead of RunE | Switch to RunE |
go build -o bin/myapp ./cmd/myapp
GOOS=linux GOARCH=amd64 go build -o bin/myapp-linux-amd64
GOOS=darwin GOARCH=arm64 go build -o bin/myapp-darwin-arm64
GOOS=windows GOARCH=amd64 go build -o bin/myapp-windows-amd64.exe
go-cli-tools (PRIMARY)go-cli (SECONDARY)Task(subagent_type="go:06-go-cli", prompt="Design CLI with config and shell completion")
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.