Documentation
¶
Overview ¶
Package szargs provides a minimal and consistent interface for retrieving settings from command-line arguments ([]string) and environment variables.
It supports three types of arguments:
- Flagged: Identified by a single dash (e.g., "-v") for short flags, or a double dash (e.g., "--dir") for long-form flags. Flags may be standalone booleans or followed by a value.
- Positional: Identified by their order in the argument list after all flagged arguments have been processed.
- Settings: A composite configuration mechanism that combines a default value, an environment variable, and a flagged argument—allowing each to override the previous in precedence: default < env < flag.
The package includes built-in parsers for standard Go data types.
Usage centers around the Args type, created using:
szargs.New(programDesc string, programArgs []string)
The `programArgs` slice must include the program name as the first element; this is ignored during argument parsing.
After retrieving all relevant arguments, the `Args.Done()` method must be called to report an error if any unprocessed arguments remain.
This utility reflects a preference for simplicity and clarity in tooling. If it helps your project flow a little more smoothly, it's done its job.
Dedication ¶
This project is dedicated to Reem. Your brilliance, courage, and quiet strength continue to inspire me. Every line is written in gratitude for the light and hope you brought into my life.
NOTE: Documentation reviewed and polished with the assistance of ChatGPT from OpenAI.
Index ¶
- Variables
- type Args
- func (args *Args) AddSynopsis(s string)
- func (args *Args) Args() []string
- func (args *Args) Count(flag, desc string) int
- func (args *Args) Done()
- func (args *Args) Err() error
- func (args *Args) HasErr() bool
- func (args *Args) HasNext() bool
- func (args *Args) Is(flag, desc string) bool
- func (args *Args) NextFloat32(name, desc string) float32
- func (args *Args) NextFloat64(name, desc string) float64
- func (args *Args) NextInt(name, desc string) int
- func (args *Args) NextInt16(name, desc string) int16
- func (args *Args) NextInt32(name, desc string) int32
- func (args *Args) NextInt64(name, desc string) int64
- func (args *Args) NextInt8(name, desc string) int8
- func (args *Args) NextOption(name string, validOptions []string, desc string) string
- func (args *Args) NextString(name, desc string) string
- func (args *Args) NextUint(name, desc string) uint
- func (args *Args) NextUint16(name, desc string) uint16
- func (args *Args) NextUint32(name, desc string) uint32
- func (args *Args) NextUint64(name, desc string) uint64
- func (args *Args) NextUint8(name, desc string) uint8
- func (args *Args) ProgramName() string
- func (args *Args) PushArg(arg string)
- func (args *Args) PushErr(err error)
- func (args *Args) RegisterUsage(item, desc string)
- func (args *Args) SettingFloat32(flag, env string, def float32, desc string) float32
- func (args *Args) SettingFloat64(flag, env string, def float64, desc string) float64
- func (args *Args) SettingInt(flag, env string, def int, desc string) int
- func (args *Args) SettingInt16(flag, env string, def int16, desc string) int16
- func (args *Args) SettingInt32(flag, env string, def int32, desc string) int32
- func (args *Args) SettingInt64(flag, env string, def int64, desc string) int64
- func (args *Args) SettingInt8(flag, env string, def int8, desc string) int8
- func (args *Args) SettingIs(flag, env string, desc string) bool
- func (args *Args) SettingOption(flag, env string, def string, validOptions []string, desc string) string
- func (args *Args) SettingString(flag, env, def, desc string) string
- func (args *Args) SettingUint(flag, env string, def uint, desc string) uint
- func (args *Args) SettingUint16(flag, env string, def uint16, desc string) uint16
- func (args *Args) SettingUint32(flag, env string, def uint32, desc string) uint32
- func (args *Args) SettingUint64(flag, env string, def uint64, desc string) uint64
- func (args *Args) SettingUint8(flag, env string, def uint8, desc string) uint8
- func (args *Args) Usage() string
- func (args *Args) UsageWidth(newLineWidth int)
- func (args *Args) ValueFloat32(flag, desc string) (float32, bool)
- func (args *Args) ValueFloat64(flag, desc string) (float64, bool)
- func (args *Args) ValueInt(flag, desc string) (int, bool)
- func (args *Args) ValueInt16(flag, desc string) (int16, bool)
- func (args *Args) ValueInt32(flag, desc string) (int32, bool)
- func (args *Args) ValueInt64(flag, desc string) (int64, bool)
- func (args *Args) ValueInt8(flag, desc string) (int8, bool)
- func (args *Args) ValueOption(flag string, validOptions []string, desc string) (string, bool)
- func (args *Args) ValueString(flag, desc string) (string, bool)
- func (args *Args) ValueUint(flag, desc string) (uint, bool)
- func (args *Args) ValueUint16(flag, desc string) (uint16, bool)
- func (args *Args) ValueUint32(flag, desc string) (uint32, bool)
- func (args *Args) ValueUint64(flag, desc string) (uint64, bool)
- func (args *Args) ValueUint8(flag, desc string) (uint8, bool)
- func (args *Args) ValuesFloat32(flag, desc string) []float32
- func (args *Args) ValuesFloat64(flag, desc string) []float64
- func (args *Args) ValuesInt(flag, desc string) []int
- func (args *Args) ValuesInt16(flag, desc string) []int16
- func (args *Args) ValuesInt32(flag, desc string) []int32
- func (args *Args) ValuesInt64(flag, desc string) []int64
- func (args *Args) ValuesInt8(flag, desc string) []int8
- func (args *Args) ValuesOption(flag string, validOptions []string, desc string) []string
- func (args *Args) ValuesString(flag, desc string) []string
- func (args *Args) ValuesUint(flag, desc string) []uint
- func (args *Args) ValuesUint16(flag, desc string) []uint16
- func (args *Args) ValuesUint32(flag, desc string) []uint32
- func (args *Args) ValuesUint64(flag, desc string) []uint64
- func (args *Args) ValuesUint8(flag, desc string) []uint8
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoArgs = errors.New("no program arguments provided") ErrSyntax = errors.New("syntax") ErrRange = errors.New("range") ErrInvalidFloat64 = errors.New("invalid float64") ErrInvalidFloat32 = errors.New("invalid float32") ErrInvalidInt64 = errors.New("invalid int64") ErrInvalidInt16 = errors.New("invalid int16") ErrInvalidInt32 = errors.New("invalid int32") ErrInvalidInt8 = errors.New("invalid int8") ErrInvalidInt = errors.New("invalid int") ErrInvalidUint64 = errors.New("invalid uint64") ErrInvalidUint32 = errors.New("invalid uint32") ErrInvalidUint16 = errors.New("invalid uint16") ErrInvalidUint8 = errors.New("invalid uint8") ErrInvalidUint = errors.New("invalid uint") ErrInvalidOption = errors.New("invalid option") ErrInvalidDefault = errors.New("invalid default") ErrInvalidFlag = errors.New("invalid flag") ErrInvalidEnv = errors.New("invalid environment variable") )
Exported errors.
var ( ErrAmbiguous = errors.New("ambiguous argument") ErrMissing = errors.New("missing argument") ErrUnexpected = errors.New("unexpected argument") )
Exported errors.
Functions ¶
This section is empty.
Types ¶
type Args ¶ added in v0.0.4
type Args struct {
// contains filtered or unexported fields
}
Args provides a single point to access and extract program arguments.
func New ¶ added in v0.0.4
New creates a new Args object based in the arguments passed. The first element of the arguments must be the program name.
func (*Args) AddSynopsis ¶ added in v0.0.10
AddSynopsis includes another static synopsis message.
func (*Args) Done ¶ added in v0.0.4
func (args *Args) Done()
Done registers an error if there are any remaining arguments.
func (*Args) Err ¶ added in v0.0.4
Err returns any errors encountered or registered while parsing the arguments.
func (*Args) HasErr ¶ added in v0.0.6
HasErr returns true if any errors have been encountered or registered.
func (*Args) NextFloat32 ¶ added in v0.0.4
NextFloat32 removes and returns the next argument from the argument list, parsing it as a 32 bit floating point number.
If no arguments remain, or if the value has invalid syntax or is out of range for a float32, an error is registered.
Returns the next argument value parsed as a float32.
func (*Args) NextFloat64 ¶ added in v0.0.4
NextFloat64 removes and returns the next argument from the argument list, parsing it as a 64 bit floating point number.
If no arguments remain, or if the value has invalid syntax or is out of range for a float64, an error is registered.
Returns the next argument value parsed as a float64.
func (*Args) NextInt ¶ added in v0.0.4
NextInt removes and returns the next argument from the argument list, parsing it as n signed integer.
If no arguments remain, or if the value has invalid syntax or is out of range for an int, an error is registered.
Returns the next argument value parsed as an int.
func (*Args) NextInt16 ¶ added in v0.0.4
NextInt16 removes and returns the next argument from the argument list, parsing it as a signed 16 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for an int16, an error is registered.
Returns the next argument value parsed as an int16.
func (*Args) NextInt32 ¶ added in v0.0.4
NextInt32 removes and returns the next argument from the argument list, parsing it as a signed 32 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for an int32, an error is registered.
Returns the next argument value parsed as an int32.
func (*Args) NextInt64 ¶ added in v0.0.4
NextInt64 removes and returns the next argument from the argument list, parsing it as a signed 64 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for an int64, an error is registered.
Returns the next argument value parsed as an int64.
func (*Args) NextInt8 ¶ added in v0.0.4
NextInt8 removes and returns the next argument from the argument list, parsing it as a signed 8 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for an int8, an error is registered.
Returns the next argument value parsed as an int8.
func (*Args) NextOption ¶ added in v0.0.6
NextOption removes and returns the next argument from the argument list. The value must match one of the entries in validOptions.
If no arguments remain, or if the value is not found in validOptions, an error is registered.
Returns the next argument value.
func (*Args) NextString ¶ added in v0.0.4
NextString removes and returns the next argument from the argument list.
If no arguments remain, an error is registered.
Returns the next argument value as a string.
func (*Args) NextUint ¶ added in v0.0.4
NextUint removes and returns the next argument from the argument list, parsing it as an unsigned integer.
If no arguments remain, or if the value has invalid syntax or is out of range for a uint, an error is registered.
Returns the next argument value parsed as a uint.
func (*Args) NextUint16 ¶ added in v0.0.4
NextUint16 removes and returns the next argument from the argument list, parsing it as an unsigned 16 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for a uint16, an error is registered.
Returns the next argument value parsed as a uint16.
func (*Args) NextUint32 ¶ added in v0.0.4
NextUint32 removes and returns the next argument from the argument list, parsing it as an unsigned 32 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for a uint32, an error is registered.
Returns the next argument value parsed as a uint32.
func (*Args) NextUint64 ¶ added in v0.0.4
NextUint64 removes and returns the next argument from the argument list, parsing it as an unsigned 64 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for a uint64, an error is registered.
Returns the next argument value parsed as a uint64.
func (*Args) NextUint8 ¶ added in v0.0.4
NextUint8 removes and returns the next argument from the argument list, parsing it as an unsigned 8 bit integer.
If no arguments remain, or if the value has invalid syntax or is out of range for a uint8, an error is registered.
Returns the next argument value parsed as a uint8.
func (*Args) ProgramName ¶ added in v0.1.1
ProgramName returns the configured program name.
func (*Args) PushArg ¶ added in v0.0.6
PushArg places the supplied argument to the end of the internal args list.
func (*Args) PushErr ¶ added in v0.0.4
PushErr registers the provided error if not nil to the Args error stack.
func (*Args) RegisterUsage ¶ added in v0.1.3
RegisterUsage registers a new flag and its description if and only if the flag has not been already registered.
func (*Args) SettingFloat32 ¶ added in v0.0.4
SettingFloat32 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a 32 bit floating point number.
If the final value has invalid syntax or is out of range for a float32, an error is registered.
Returns the final parsed float32 value.
func (*Args) SettingFloat64 ¶ added in v0.0.4
SettingFloat64 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a 64 bit floating point number.
If the final value has invalid syntax or is out of range for a float64, an error is registered.
Returns the final parsed float64 value.
func (*Args) SettingInt ¶ added in v0.0.4
SettingInt returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a signed integer.
If the final value has invalid syntax or is out of range for an int, an error is registered.
Returns the final parsed int value.
func (*Args) SettingInt16 ¶ added in v0.0.4
SettingInt16 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a signed 16 bit integer.
If the final value has invalid syntax or is out of range for an int16, an error is registered.
Returns the final parsed int16 value.
func (*Args) SettingInt32 ¶ added in v0.0.4
SettingInt32 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a signed 32 bit integer.
If the final value has invalid syntax or is out of range for an int32, an error is registered.
Returns the final parsed int32 value.
func (*Args) SettingInt64 ¶ added in v0.0.4
SettingInt64 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a signed 64 bit integer.
If the final value has invalid syntax or is out of range for an int64, an error is registered.
Returns the final parsed int64 value.
func (*Args) SettingInt8 ¶ added in v0.0.4
SettingInt8 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as a signed 8 bit integer.
If the final value has invalid syntax or is out of range for an int8, an error is registered.
Returns the final parsed int8 value.
func (*Args) SettingIs ¶ added in v0.0.6
SettingIs returns true if a specified environment variable is set to a truthy value, or if a corresponding boolean command-line flag is present.
Unlike other Setting methods, there is no default.
The environment variable is considered true if it is set to one of: "", "T", "Y", "TRUE", "YES", "ON" or "1" (case-insensitive). Any other value is considered false.
The command-line flag override takes no value—its presence alone indicates true.
Returns the resulting boolean value.
func (*Args) SettingOption ¶ added in v0.0.6
func (args *Args) SettingOption( flag, env string, def string, validOptions []string, desc string, ) string
SettingOption returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument.
If the final value is not found in the list of validOptions, an error is registered.
Returns the final selected value.
func (*Args) SettingString ¶ added in v0.0.4
SettingString returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument.
Returns the final selected string value.
func (*Args) SettingUint ¶ added in v0.0.4
SettingUint returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as an unsigned integer.
If the final value has invalid syntax or is out of range for a uint, an error is registered.
Returns the final parsed uint value.
func (*Args) SettingUint16 ¶ added in v0.0.4
SettingUint16 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as an unsigned 16 bit integer.
If the final value has invalid syntax or is out of range for a uint16, an error is registered.
Returns the final parsed uint16 value.
func (*Args) SettingUint32 ¶ added in v0.0.4
SettingUint32 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as an unsigned 32 bit integer.
If the final value has invalid syntax or is out of range for a uint32, an error is registered.
Returns the final parsed uint32 value.
func (*Args) SettingUint64 ¶ added in v0.0.4
SettingUint64 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as an unsigned 64 bit integer.
If the final value has invalid syntax or is out of range for a uint64, an error is registered.
Returns the final parsed uint64 value.
func (*Args) SettingUint8 ¶ added in v0.0.4
SettingUint8 returns a configuration value based on a default, optionally overridden by an environment variable, and further overridden by a flagged command-line argument. The value is parsed as an unsigned 8 bit integer.
If the final value has invalid syntax or is out of range for a uint8, an error is registered.
Returns the final parsed uint8 value.
func (*Args) Usage ¶ added in v0.0.4
Usage returns a usage message based on the parsed arguments.
/*
# Usage
Golang to 'github' markdown.
gotomd [options] [path ...]
[-v | --verbose ...]
Provide more information when processing.
*/
func (*Args) UsageWidth ¶ added in v0.0.9
UsageWidth sets the width the usage message. Must be called before any options or arguments are removed otherwise the width will only apply to subsequent additions.
func (*Args) ValueFloat32 ¶ added in v0.0.4
ValueFloat32 scans for a specific flagged argument and parses its value as a 32 bit floating point number. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a float32, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueFloat64 ¶ added in v0.0.4
ValueFloat64 scans for a specific flagged argument and parses its value as a 64 bit floating point number. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a float64, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueInt ¶ added in v0.0.4
ValueInt scans for a specific flagged argument and parses its value as a signed integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for an int, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueInt16 ¶ added in v0.0.4
ValueInt16 scans for a specific flagged argument and parses its value as a signed 16 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for an int16, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueInt32 ¶ added in v0.0.4
ValueInt32 scans for a specific flagged argument and parses its value as a signed 32 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for an int32, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueInt64 ¶ added in v0.0.4
ValueInt64 scans for a specific flagged argument and parses its value as a signed 64 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for an int64, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueInt8 ¶ added in v0.0.4
ValueInt8 scans for a specific flagged argument and parses its value as a signed 8 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for an int8, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueOption ¶ added in v0.0.6
ValueOption scans for a specific flagged argument (e.g., "--mode value") and captures its associated value. The flag and its value are removed from the argument list.
If the flag appears more than once, or if it lacks a following value, an error is registered. If the value is not found in the provided list of validOptions, an error is also registered.
Returns the value and a boolean indicating whether the flag was found.
func (*Args) ValueString ¶ added in v0.0.4
ValueString scans for a specific flagged argument and captures its following value as a string. The flag and its value are removed from the argument list.
If the flag appears more than once or lacks a following value, an error is registered.
Returns the string value and a boolean indicating whether the flag was found.
func (*Args) ValueUint ¶ added in v0.0.4
ValueUint scans for a specific flagged argument and parses its value as an unsigned integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a uint, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueUint16 ¶ added in v0.0.4
ValueUint16 scans for a specific flagged argument and parses its value as an unsigned 16 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a uint16, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueUint32 ¶ added in v0.0.4
ValueUint32 scans for a specific flagged argument and parses its value as an unsigned 32 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a uint32, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueUint64 ¶ added in v0.0.4
ValueUint64 scans for a specific flagged argument and parses its value as an unsigned 64 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a uint64, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValueUint8 ¶ added in v0.0.4
ValueUint8 scans for a specific flagged argument and parses its value as an unsigned 8 bit integer. The flag and its value are removed from the argument list.
If the flag appears more than once, lacks a following value, or if the value has invalid syntax or is out of range for a uint8, an error is registered.
Returns the parsed value and a boolean indicating whether the flag was found.
func (*Args) ValuesFloat32 ¶ added in v0.0.4
ValuesFloat32 scans for repeated instances of the specified flag and parses the following values as 32 bit floating point numbers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a float32, an error is registered.
Returns a slice of the parsed float32 values.
func (*Args) ValuesFloat64 ¶ added in v0.0.4
ValuesFloat64 scans for repeated instances of the specified flag and parses the following values as 64 bit floating point numbers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a float64, an error is registered.
Returns a slice of the parsed float64 values.
func (*Args) ValuesInt ¶ added in v0.0.4
ValuesInt scans for repeated instances of the specified flag and parses the following values as signed integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for an int, an error is registered.
Returns a slice of the parsed int values.
func (*Args) ValuesInt16 ¶ added in v0.0.4
ValuesInt16 scans for repeated instances of the specified flag and parses the following values as signed 16 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for an int16, an error is registered.
Returns a slice of the parsed int16 values.
func (*Args) ValuesInt32 ¶ added in v0.0.4
ValuesInt32 scans for repeated instances of the specified flag and parses the following values as signed 32 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for an int32, an error is registered.
Returns a slice of the parsed int32 values.
func (*Args) ValuesInt64 ¶ added in v0.0.4
ValuesInt64 scans for repeated instances of the specified flag and parses the following values as signed 64 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for an int64, an error is registered.
Returns a slice of the parsed int64 values.
func (*Args) ValuesInt8 ¶ added in v0.0.4
ValuesInt8 scans for repeated instances of the specified flag and parses the following values as signed 8 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for an int8, an error is registered.
Returns a slice of the parsed int8 values.
func (*Args) ValuesOption ¶ added in v0.0.6
ValuesOption scans for repeated instances of the specified flag and captures the following values. Each value must appear in the provided list of validOptions. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value is not found in validOptions, an error is registered.
Returns a slice of the captured values.
func (*Args) ValuesString ¶ added in v0.0.4
ValuesString scans for repeated instances of the specified flag and captures the following values as a slice of strings. The flags and values are removed from the argument list.
If any instance of the flag lacks a following value, an error is registered.
Returns a slice of the captured string values.
func (*Args) ValuesUint ¶ added in v0.0.4
ValuesUint scans for repeated instances of the specified flag and parses the following values as unsigned integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a uint, an error is registered.
Returns a slice of the parsed uint values.
func (*Args) ValuesUint16 ¶ added in v0.0.4
ValuesUint16 scans for repeated instances of the specified flag and parses the following values as unsigned 16 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a uint16, an error is registered.
Returns a slice of the parsed uint16 values.
func (*Args) ValuesUint32 ¶ added in v0.0.4
ValuesUint32 scans for repeated instances of the specified flag and parses the following values as unsigned 32 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a uint32, an error is registered.
Returns a slice of the parsed uint32 values.
func (*Args) ValuesUint64 ¶ added in v0.0.4
ValuesUint64 scans for repeated instances of the specified flag and parses the following values as unsigned 64 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a uint64, an error is registered.
Returns a slice of the parsed uint64 values.
func (*Args) ValuesUint8 ¶ added in v0.0.4
ValuesUint8 scans for repeated instances of the specified flag and parses the following values as unsigned 8 bit integers. The flags and values are removed from the argument list.
If any flag lacks a following value, or if a value has invalid syntax or is out of range for a uint8, an error is registered.
Returns a slice of the parsed uint8 values.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
average
command
Package main implements a simple example of using a flag to provide a list of floating point numbers and returning the sum or average of the list.
|
Package main implements a simple example of using a flag to provide a list of floating point numbers and returning the sum or average of the list. |
|
booleanCount
command
Package main implements a simple example of using szargs.
|
Package main implements a simple example of using szargs. |
|
booleanIs
command
Package main implements a simple example of using szargs.
|
Package main implements a simple example of using szargs. |
|
next
command
Package main implements a simple example of using szargs.
|
Package main implements a simple example of using szargs. |
|
setting
command
Package main implements a simple example of using szargs.
|
Package main implements a simple example of using szargs. |
|
value
command
Package main implements a simple example of using szargs.
|
Package main implements a simple example of using szargs. |
|
values
command
Package main implements a simple example of using szargs.
|
Package main implements a simple example of using szargs. |