License
BSD-3-Clause
Install
go get github.com/thegrumpylion/cnc

Documentation

CLI

Struct-based CLI library for Go

Status

This project is alpha. It lacks in documentation, testing and featres. It’s out for feedback and bug reports. Expect bugs and breaking changes.

Example

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 8080
localhost 8080

Or

./cmd --host=localhost --port=8080
localhost 8080

Help

./cmd --help
Usage:
  cmd [--host HOST] [--port PORT]

Flags:
      --host
      --port

Completion

complete -o nospace -C ./cmd ./cmd
$ ./cmd <TAB>
$ ./cmd --<TAB><TAB>
--host   --port
$ ./cmd --