GitHub - livebud/cli: Build beautiful CLIs in Go.
Build beautiful CLIs in Go. A simpler alternative to kingpin.
Features
- Type-safe, fluent API
- Flag, command and argument support
- Required and optional parameters
- Built entirely on the flag package the standard library
- Supports both space-based and colon-based subcommands (e.g.
controller new&controller:new) SIGINTcontext cancellation out-of-the-box- Custom help messages
- Built-in tab completion with
complete -o nospace -C <cmd> <cmd> - Respects
NO_COLOR
Install
go get -u github.com/livebud/cli
Example
package main import ( "context" "fmt" "os" "github.com/livebud/cli" ) func main() { flag := new(Flag) cli := cli.New("app", "your awesome cli").Writer(os.Stdout) cli.Flag("log", "log level").Short('L').String(&flag.Log).Default("info") cli.Flag("embed", "embed the code").Bool(&flag.Embed).Default(false) { // new <dir> cmd := &New{Flag: flag} cli := cli.Command("new", "create a new project") cli.Arg("dir").String(&cmd.Dir) cli.Run(cmd.Run) } ctx := context.Background() if err := cli.Parse(ctx, os.Args[1:]...); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } type Flag struct { Log string Embed bool } type New struct { Flag *Flag Dir string } // Run new func (n *New) Run(ctx context.Context) error { return nil }
Contributing
First, clone the repo:
git clone https://github.com/livebud/cli
cd cliNext, install dependencies:
Finally, try running the tests:
License
MIT