A simple command-line argument parsing library for Go with a builder pattern interface.
⚠️ Draft Status: This library is currently in development and the API may change.
- Builder pattern for easy CLI definition
- Support for positional arguments and flags (short and long)
- Subcommands support
- Automatic help and version flags
- Simple argument parsing and value retrieval
go get github.com/JamesPatrickGill/applause
package main
import (
"fmt"
"os"
"github.com/JamesPatrickGill/applause"
)
func main() {
// Define your CLI
cmd := applause.NewCommand("greet").
Version("1.0.0").
About("A simple greeting application").
Arg(applause.NewArg("name").Help("Name to greet")).
Arg(applause.NewArg("greeting").Short("g").Long("greeting").Help("Custom greeting"))
// Parse arguments
matches := cmd.GetMatchesFrom(os.Args)
// Get values
name := "World"
if n, ok := matches.GetPositional(0); ok {
name = n
}
greeting := "Hello"
if g, ok := matches.GetOne("greeting"); ok {
greeting = g
}
fmt.Printf("%s, %s!\n", greeting, name)
}
Usage:
$ greet Alice
Hello, Alice!
$ greet Bob --greeting "Hi"
Hi, Bob!
$ greet --help
greet 1.0.0
A simple greeting application
...
This project is open source and available under the MIT License.