Documentation ¶
Overview ¶
Self documenting CLI options parser for Go
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
func MustParse ¶
MustParse() is a wrapper for Parse() for assigning global variables. When an error occures this function will panic.
func Parse ¶
Parse a spec string and return a Spec object.
The spec string must have the following format:
usage: example-tool A short description of the command -- flag --flag,-f,FLAG A description for this flag option= --option=,-o=,OPTION= A description for this option the description continues here !required= --required,-r=,REQUIRED= A required option -- env_var= ENV_VAR= An environment variable -- help help,h Show this help message run run Run some function -- More freestyle text
Example ¶
spec, err := Parse(` usage: example-tool A short description of the command -- flag --flag,-f,FLAG A description for this flag option= --option=,-o=,OPTION= A description for this option the description continues here !required= --required,-r=,REQUIRED= A required option -- env_var= ENV_VAR= An environment variable -- help help,h Show this help message run run Run some function -- More freestyle text `) if err != nil { spec.PrintUsageWithError(err) } opts, err := spec.Interpret([]string{"example-tool", "--required", "hello world"}, []string{}) if err != nil { spec.PrintUsageWithError(err) } fmt.Printf("required: %s", opts.Get("required"))
Output: required: hello world
func (*Spec) MustInterpret ¶
func (*Spec) PrintUsage ¶
func (spec *Spec) PrintUsage()
func (*Spec) PrintUsageAndExit ¶
func (spec *Spec) PrintUsageAndExit()
func (*Spec) PrintUsageWithError ¶
Click to show internal directories.
Click to hide internal directories.