BOA¶
Declarative Go CLI Framework built on Cobra
BOA adds a declarative layer on top of cobra, making CLI creation as simple as defining a struct.
Features¶
- Declarative parameters - Define CLI flags as struct fields with tags
- Automatic flag generation - Field names become kebab-case flags
- Environment variable binding - Auto-generated or custom env var names
- Built-in validation - Required fields, alternatives, custom validators
- Cobra compatible - Access underlying Cobra commands when needed
Quick Example¶
package main
import (
"fmt"
"github.com/GiGurra/boa/pkg/boa"
"github.com/spf13/cobra"
)
type Params struct {
Name string `descr:"User name"`
Port int `descr:"Port number" default:"8080" optional:"true"`
Verbose bool `short:"v" optional:"true"`
}
func main() {
boa.CmdT[Params]{
Use: "myapp",
Short: "A simple CLI application",
RunFunc: func(params *Params, cmd *cobra.Command, args []string) {
fmt.Printf("Hello %s on port %d\n", params.Name, params.Port)
},
}.Run()
}
package main
import (
"fmt"
"github.com/GiGurra/boa/pkg/boa"
)
type Params struct {
Name string `descr:"User name"`
Port int `descr:"Port number" default:"8080" optional:"true"`
Verbose bool `short:"v" optional:"true"`
}
func main() {
boa.NewCmdT[Params]("myapp").
WithShort("A simple CLI application").
WithRunFunc(func(params *Params) {
fmt.Printf("Hello %s on port %d\n", params.Name, params.Port)
}).
Run()
}
This generates:
A simple CLI application
Usage:
myapp [flags]
Flags:
-n, --name string User name (env: NAME, required)
-p, --port int Port number (env: PORT) (default 8080)
-v, --verbose (env: VERBOSE)
-h, --help help for myapp
Installation¶
Next Steps¶
- Quickstart - Get a CLI running in 60 seconds with Claude Code
- Getting Started - Installation and basic usage
- Struct Tags - Complete reference for all struct tags
- Lifecycle Hooks - Customize behavior at different stages
- Error Handling - Run() vs RunE() and error propagation
- Cobra Interoperability - Access Cobra primitives and migrate incrementally
- Migration Guide - Migrating from deprecated wrapper types