Struct-based CLI library for Go
This project is alpha. It lacks in documentation, testing and featres. It’s out for feedback and bug reports. Expect bugs and breaking changes.
package main
import (
"context"
"fmt"
"log"
"github.com/thegrumpylion/cli"
)
type rootCmd struct {
Host string
Port int
}
func (c *rootCmd) Run(ctx context.Context) error {
fmt.Println(c.Host, c.Port)
return nil
}
func main() {
c := &rootCmd{}
if err := cli.ParseCommandAndExecute(context.Background(), c); err != nil {
log.Fatalln("error:", err)
}
}./cmd --host localhost --port 8080localhost 8080
Or
./cmd --host=localhost --port=8080localhost 8080