Documentation ¶
Index ¶
- Variables
- func Add(name, desc string, cmd Command)
- func Args() (*Positional, *Optional)
- func Help(pos *Positional, opt *Optional) string
- func Run(name, desc string, cmd Command) int
- func Usage(pos *Positional, opt *Optional) string
- type Argument
- type ArgumentType
- type Arguments
- type BoolValue
- type Command
- type CommandDescription
- type Context
- type CreateValue
- type FloatValue
- type IntValue
- type OpenSliceValue
- type OpenValue
- type Optional
- func (opt *Optional) Create(short rune, long string, init *os.File, usage string) *os.File
- func (opt *Optional) Float(short rune, long string, init float64, usage string) *float64
- func (opt *Optional) Int(short rune, long string, init int, usage string) *int
- func (opt *Optional) Open(short rune, long string, init *os.File, usage string) *os.File
- func (opt *Optional) OpenSlice(short rune, long string, init []*os.File, usage string) *[]*os.File
- func (opt *Optional) Register(short rune, long string, value Value, usage string)
- func (opt *Optional) String(short rune, long, init, usage string) *string
- func (opt *Optional) StringSlice(short rune, long string, init []string, usage string) *[]string
- func (opt *Optional) Switch(short rune, long string, usage string) *bool
- type Parser
- type Positional
- func (pos *Positional) Bool(name, usage string) *bool
- func (pos *Positional) Create(name, usage string) *os.File
- func (pos *Positional) Input(usage string) *os.File
- func (pos *Positional) Int(name, usage string) *int
- func (pos Positional) Len() int
- func (pos *Positional) Open(name, usage string) *os.File
- func (pos *Positional) Output(usage string) *os.File
- func (pos *Positional) Register(name string, value Value, usage string)
- func (pos *Positional) String(name, usage string) *string
- type Program
- type SliceValue
- type StringSliceValue
- type StringValue
- type Value
Constants ¶
This section is empty.
Variables ¶
var Main = NewProgram()
Main is the main program.
Functions ¶
func Args ¶
func Args() (*Positional, *Optional)
Args creates a pair of empty positional and optional argument definitions.
func Help ¶
func Help(pos *Positional, opt *Optional) string
Help creaes a help string for the given argument definitions.
func Usage ¶
func Usage(pos *Positional, opt *Optional) string
Usage creates a usage string for the given argument definitions.
Types ¶
type ArgumentType ¶
type ArgumentType int
ArgumentType represents the type of argument.
const ( // LongType represents a long flag argument. LongType ArgumentType = iota // ShortType represents a short flag argument. ShortType // ValueType represents a plain value argument. ValueType )
type BoolValue ¶
type BoolValue bool
BoolValue represents a boolean argument value.
type CommandDescription ¶
CommandDescription carries a command and its description.
type Context ¶
Context carries the name, description, and arguments given to a command.
type CreateValue ¶
CreateValue represents a file argument value for creating.
func NewCreateValue ¶
func NewCreateValue(init *os.File) *CreateValue
NewCreateValue creates a new CreateValue.
func (*CreateValue) Set ¶
func (p *CreateValue) Set(s string) error
Set will set attempt to convert the given string to a value.
func (*CreateValue) String ¶
func (p *CreateValue) String() string
String satisfies the fmt.Stringer interface.
type FloatValue ¶
type FloatValue float64
FloatValue represents a float argument value.
func NewFloatValue ¶
func NewFloatValue(init float64) *FloatValue
NewFloatValue creates a new FloatValue.
func (*FloatValue) Set ¶
func (p *FloatValue) Set(s string) error
Set will set attempt to convert the given string to a value.
func (FloatValue) String ¶
func (p FloatValue) String() string
String satisfies the fmt.Stringer interface.
type IntValue ¶
type IntValue int
IntValue represents a integer argument value.
type OpenSliceValue ¶ added in v1.1.0
OpenSliceValue represents a variable number open argument value.
func NewOpenSliceValue ¶ added in v1.1.0
func NewOpenSliceValue(init []*os.File) *OpenSliceValue
NewOpenSliceValue creates a new OpenSliceValue.
func (OpenSliceValue) Len ¶ added in v1.1.0
func (v OpenSliceValue) Len() int
Len will return the length of the slice value.
func (*OpenSliceValue) Set ¶ added in v1.1.0
func (p *OpenSliceValue) Set(s string) error
Set will set attempt to convert and append the given string to the slice.
func (OpenSliceValue) String ¶ added in v1.1.0
func (v OpenSliceValue) String() string
String satisfies the fmt.Stringer interface.
type OpenValue ¶
OpenValue represents a file argument value for opening.
func NewOpenValue ¶
NewOpenValue creates a new OpenValue.
type Optional ¶
Optional represents the optional command line arguments.
func (*Optional) Create ¶ added in v1.2.0
Create adds a file for writing to the positional argument list.
func (*Optional) OpenSlice ¶ added in v1.1.0
OpenSlice adds a string slice flag to the optional argument list.
func (*Optional) StringSlice ¶
StringSlice adds a string slice flag to the optional argument list.
type Parser ¶
type Parser struct { Pos *Positional Opt *Optional }
Parser will parse a list of arguments with the given Positional and Optional argument definitions.
func NewParser ¶
func NewParser(pos *Positional, opt *Optional) Parser
NewParser returns a new Parser.
type Positional ¶
Positional represents the positional command line arguments.
func (*Positional) Bool ¶
func (pos *Positional) Bool(name, usage string) *bool
Bool adds a string value to the positional argument list.
func (*Positional) Create ¶
func (pos *Positional) Create(name, usage string) *os.File
Create adds a file for writing to the positional argument list.
func (*Positional) Input ¶
func (pos *Positional) Input(usage string) *os.File
Input adds a file which when omitted will read from os.Stdin.
func (*Positional) Int ¶
func (pos *Positional) Int(name, usage string) *int
Int adds a string value to the positional argument list.
func (Positional) Len ¶
func (pos Positional) Len() int
Len returns the number of positional arguments.
func (*Positional) Open ¶
func (pos *Positional) Open(name, usage string) *os.File
Open adds a file for reading to the positional argument list.
func (*Positional) Output ¶
func (pos *Positional) Output(usage string) *os.File
Output adds a file which when omitted will read from os.Stdout.
func (*Positional) Register ¶
func (pos *Positional) Register(name string, value Value, usage string)
Regsiter the name with the given value and usage.
func (*Positional) String ¶
func (pos *Positional) String(name, usage string) *string
String adds a string value to the positional argument list.
type Program ¶
type Program struct {
Map map[string]CommandDescription
}
Program represents a list of named commands.
func (Program) ListCommands ¶ added in v1.3.1
ListCommands lists the commands registered to the given program.
type SliceValue ¶
SliceValue represents a variable length command line argument value.
type StringSliceValue ¶
type StringSliceValue []string
StringSliceValue represents a variable number string argument value.
func NewStringSliceValue ¶
func NewStringSliceValue(init []string) *StringSliceValue
NewStringSliceValue creates a new StringSliceValue.
func (StringSliceValue) Len ¶
func (v StringSliceValue) Len() int
Len will return the length of the slice value.
func (*StringSliceValue) Set ¶
func (p *StringSliceValue) Set(s string) error
Set will set attempt to convert and append the given string to the slice.
func (StringSliceValue) String ¶
func (p StringSliceValue) String() string
String satisfies the fmt.Stringer interface.
type StringValue ¶
type StringValue string
StringValue represents a string argument value.
func NewStringValue ¶
func NewStringValue(init string) *StringValue
NewStringValue creates a new StringValue.
func (*StringValue) Set ¶
func (p *StringValue) Set(s string) error
Set will set attempt to convert the given string to a value.
func (StringValue) String ¶
func (p StringValue) String() string
String satisfies the fmt.Stringer interface.