= go-cli image:https://travis-ci.org/motemen/go-cli.svg?branch=master["Build Status", link="https://travis-ci.org/motemen/go-cli"] image:http://godoc.org/github.com/motemen/go-cli?status.svg["GoDoc", link="http://godoc.org/github.com/motemen/go-cli"] image:http://gocover.io/_badge/github.com/motemen/go-cli["Test Coverage", link="http://gocover.io/github.com/motemen/go-cli"]
Yet another CLI app builder with commands, based on documentation.
== Example
package main
import ( "flag" "os"
"github.com/motemen/go-cli"
)
func main() { cli.Use(&cli.Command{ Name: "foo", Short: "description in one line", Long: `foo [-v]
Description in paragraphs, starting with a usage line. Blah blah blah`, Action: func(flags *flag.FlagSet, args []string) error { // Initialize and parse flags inside Action verbose := flags.Bool("v", false, "set verbosity") flags.Parse(args)
args = flags.Args()
if len(args) < 1 {
// Return cli.ErrUsage to show the command usage to the user
return cli.ErrUsage
}
...
return nil
},
})
cli.Run(os.Args[1:])
Example output:
% prog Usage: prog []
% prog foo -h Usage: foo [-v]
Description in paragraphs, starting with a usage line. Blah blah blah
== Registering commands using documentation
You may use github.com/motemen/go-cli/gen to automatically register commands and their usages using comment documentation. An example documentation for the example above:
You can use gen.Generate() to generate a source file like below:
// auto-generated file
package main
import "github.com/motemen/go-cli"
Include this file to the build and you can maintain CLI commands using documentation. For complete example, refer to the _example directory.
== Author
motemen [email protected]