Documentation
¶
Overview ¶
package cmdline provides an interface for defining and accessing arguments to a go program that are specified on the command line of the program execution
Index ¶
- func FlagTypeString(type_name FlagArgType) string
- type CmdParser
- func (cp *CmdParser) AddFlag(arg_type FlagArgType, arg_name string, arg_req bool)
- func (cp *CmdParser) GetVar(name string) any
- func (cp *CmdParser) IsFlag(name string) bool
- func (cp *CmdParser) IsLoaded(name string) bool
- func (cp *CmdParser) IsRequired(name string) bool
- func (cp *CmdParser) Parse() bool
- func (cp *CmdParser) ParseFromCmdLine() bool
- func (cp *CmdParser) ParseFromFile(filename string) bool
- func (cp *CmdParser) ParseFromString(cmd_string string) bool
- func (cp *CmdParser) SetVar(name string, value string)
- type FlagArgType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlagTypeString ¶
func FlagTypeString(type_name FlagArgType) string
FlagTypeString converts a command line argument enumerated type into a string representation
Types ¶
type CmdParser ¶
type CmdParser struct {
// contains filtered or unexported fields
}
A CmdParser struct maps the flag names of command variables to their type specific representations
func NewCmdParser ¶
func NewCmdParser() *CmdParser
NewCmdParser is a constructor, initializes an empty CmdParser data structure
func (*CmdParser) AddFlag ¶
func (cp *CmdParser) AddFlag(arg_type FlagArgType, arg_name string, arg_req bool)
AddFlag includes a new command flag to the parser. The arguments give the type of the flag in enumerated type form, the name of the flag, and whether the flag is required
func (*CmdParser) GetVar ¶
GetVar returns the type-unspecified value of a command variable that was created in the CmdParser, and given a value from the command line. It is assumed that the application calls IsLoaded before GetVar to ascertain that a value is indeed present
func (*CmdParser) IsFlag ¶
IsFlag returns a bool indicating whether the input argument string 'name' has been used to create a command variable in the CmdParser
func (*CmdParser) IsLoaded ¶
IsLoaded returns a bool indicating whether a command variable with the input argument string 'name' was recognized on the command line and so had a value stored
func (*CmdParser) IsRequired ¶
IsRequired returns a bool indicating whether a command variable with the input argument 'name' was declared to be required
func (*CmdParser) Parse ¶
Parse looks for a leading "-is" on the command line to determine whether to parse from a file (e.g., "-is" is present), or get the arguments from the command line itself
func (*CmdParser) ParseFromCmdLine ¶
ParseFromCmdLine gets the command line string from os.Args, i.e., the run-time command line
func (*CmdParser) ParseFromFile ¶
ParseFromFile gets the command line flags from a file. This enables separation across lines and comments
func (*CmdParser) ParseFromString ¶
ParseFromString separates the command line string into individual command statements and stores them in the CmdParser
type FlagArgType ¶
type FlagArgType int
FlagArgType is the type basis for an enumerated type of command-line flags
const ( IntFlag FlagArgType = iota Int64Flag FloatFlag StringFlag BoolFlag None )
IntFlag, Int64Flag, FloatFlag, StringFlag, and BoolFlag are the enumerated types of scalar types of arguments declared on the command line