https://github.com/livebud/cli
Build beautiful CLIs in Go.
https://github.com/livebud/cli
Last synced: 2 months ago
JSON representation
Build beautiful CLIs in Go.
- Host: GitHub
- URL: https://github.com/livebud/cli
- Owner: livebud
- License: mit
- Created: 2023-06-21T06:41:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-11-10T22:14:55.000Z (7 months ago)
- Last Synced: 2025-11-11T00:20:15.721Z (7 months ago)
- Language: Go
- Homepage:
- Size: 257 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: License.md
Awesome Lists containing this project
README
# CLI
[](https://pkg.go.dev/github.com/livebud/cli)
Build beautiful CLIs in Go. A simpler alternative to [kingpin](https://github.com/alecthomas/kingpin).

## Features
- Type-safe, fluent API
- Flag, command and argument support
- Required and optional parameters
- Built entirely on the [flag](https://pkg.go.dev/flag) package the standard library
- Supports both space-based and colon-based subcommands (e.g. `controller new` & `controller:new`)
- `SIGINT` context cancellation out-of-the-box
- Custom help messages
- Built-in tab completion with `complete -o nospace -C `
- Respects `NO_COLOR`
## Install
```sh
go get -u github.com/livebud/cli
```
## Example
```go
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
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:
```sh
git clone https://github.com/livebud/cli
cd cli
```
Next, install dependencies:
```sh
go mod tidy
```
Finally, try running the tests:
```sh
go test ./...
```
## License
MIT