Documentation ¶
Index ¶
- Variables
- type Opts
- func (o *Opts) Author(author string) *Opts
- func (o *Opts) ConfigPath(path string) *Opts
- func (o *Opts) DocAfter(target, newid, template string) *Opts
- func (o *Opts) DocBefore(target, newid, template string) *Opts
- func (o *Opts) DocSet(id, template string) *Opts
- func (o *Opts) Help() string
- func (o *Opts) Name(name string) *Opts
- func (o *Opts) Parse() *Opts
- func (o *Opts) ParseArgs(args []string) *Opts
- func (o *Opts) PkgAuthor() *Opts
- func (o *Opts) PkgRepo() *Opts
- func (o *Opts) Process(args []string) error
- func (o *Opts) Repo(repo string) *Opts
- func (o *Opts) UseEnv() *Opts
- func (o *Opts) Version(version string) *Opts
Constants ¶
This section is empty.
Variables ¶
var DefaultOrder = []string{
"usage",
"args",
"arglist",
"options",
"cmds",
"author",
"version",
"repo",
"errmsg",
}
var DefaultTemplates = map[string]string{
"help": `{{ $root := . }}` +
`{{range $t := .Order}}{{ templ $t $root }}{{end}}`,
"usage": `Usage: {{.Name }}` +
`{{template "usageoptions" .}}` +
`{{template "usageargs" .}}` +
`{{template "usagearglist" .}}` +
`{{template "usagecmd" .}}` + "\n",
"usageoptions": `{{if .Opts}} [options]{{end}}`,
"usageargs": `{{range .Args}} {{.Name}}{{end}}`,
"usagearglist": `{{if .ArgList}} {{.ArgList.Name}}{{end}}`,
"usagecmd": `{{if .Cmds}} <command>{{end}}`,
"helpextra": `{{if .Def}}default {{.Def}}{{end}}` +
`{{if and .Def .Env}}, {{end}}` +
`{{if .Env}}env {{.Env}}{{end}}`,
"args": `{{range .Args}}{{template "arg" .}}{{end}}`,
"arg": "{{if .Help}}\n{{.Help}}\n{{end}}",
"arglist": "{{if .ArgList}}{{ if .ArgList.Help}}\n{{.ArgList.Help}}\n{{end}}{{end}}",
"options": `{{if .Opts}}` + "\nOptions:\n" +
`{{ range $opt := .Opts}}{{template "option" $opt}}{{end}}{{end}}`,
"option": `{{.Name}}{{if .Help}}{{.Pad}}{{.Help}}{{end}}` + "\n",
"cmds": "{{if .Cmds}}\nCommands:\n" +
`{{ range $sub := .Cmds}}{{template "cmd" $sub}}{{end}}{{end}}`,
"cmd": "• {{ .Name }}{{if .Help}} - {{ .Help }}{{end}}\n",
"version": "{{if .Version}}\nVersion:\n{{.Pad}}{{.Version}}\n{{end}}",
"repo": "{{if .Repo}}\nRead more:\n{{.Pad}}{{.Repo}}\n{{end}}",
"author": "{{if .Author}}\nAuthor:\n{{.Pad}}{{.Author}}\n{{end}}",
"errmsg": "{{if .ErrMsg}}\nError:\n{{.Pad}}{{.ErrMsg}}\n{{end}}",
}
Functions ¶
This section is empty.
Types ¶
type Opts ¶
type Opts struct { //LineWidth defines where new-lines //are inserted into the help text //(defaults to 42) LineWidth int //PadAll enables padding around the //help text (defaults to true) PadAll bool //PadWidth defines the amount padding //when rendering help text (defaults to 2) PadWidth int // contains filtered or unexported fields }
Opts is the main class, it contains all parsing state for a single set of arguments
func Parse ¶
func Parse(config interface{}) *Opts
Parse(&config) is shorthand for New(&config).Parse()
func (*Opts) Author ¶
Author sets the author of the program and renders the 'author' template in the help text
func (*Opts) ConfigPath ¶
ConfigPath defines a path to a JSON file which matches the structure of the provided config. Environment variables override JSON Config variables.
func (*Opts) PkgAuthor ¶
PkgRepo infers the repository link of the program from the package import path of the struct (So note, this will not work for 'main' packages)
func (*Opts) PkgRepo ¶
PkgRepo infers the repository link of the program from the package import path of the struct (So note, this will not work for 'main' packages)
func (*Opts) Repo ¶
Repo sets the repository link of the program and renders the 'repo' template in the help text