Documentation
¶
Index ¶
- type Argument
- type BoolArgument
- func (arg *BoolArgument) Consume(arguments []string) ([]string, error)
- func (arg BoolArgument) GetDefaultValue() any
- func (arg BoolArgument) GetHelp() string
- func (arg BoolArgument) GetLongName() string
- func (arg BoolArgument) GetShortName() string
- func (arg BoolArgument) GetValue() any
- func (arg *BoolArgument) Init(value *bool, shortName, longName string, defaultValue bool, help string)
- func (arg BoolArgument) IsPresent() bool
- func (arg BoolArgument) IsRequired() bool
- func (arg *BoolArgument) ResetDefaultValue()
- func (arg *BoolArgument) SetValue(value any)
- type IntArgument
- func (arg *IntArgument) Consume(arguments []string) ([]string, error)
- func (arg IntArgument) GetDefaultValue() any
- func (arg IntArgument) GetHelp() string
- func (arg IntArgument) GetLongName() string
- func (arg IntArgument) GetShortName() string
- func (arg IntArgument) GetValue() any
- func (arg *IntArgument) Init(value *int, shortName, longName string, defaultValue int, required bool, ...)
- func (arg IntArgument) IsPresent() bool
- func (arg IntArgument) IsRequired() bool
- func (arg *IntArgument) ResetDefaultValue()
- func (arg *IntArgument) SetValue(value any)
- type IntRangeArgument
- func (arg *IntRangeArgument) Consume(arguments []string) ([]string, error)
- func (arg IntRangeArgument) GetDefaultValue() any
- func (arg IntRangeArgument) GetHelp() string
- func (arg IntRangeArgument) GetLongName() string
- func (arg IntRangeArgument) GetShortName() string
- func (arg IntRangeArgument) GetValue() any
- func (arg *IntRangeArgument) Init(value *int, shortName, longName string, ...)
- func (arg IntRangeArgument) IsPresent() bool
- func (arg IntRangeArgument) IsRequired() bool
- func (arg *IntRangeArgument) ResetDefaultValue()
- func (arg *IntRangeArgument) SetValue(value any)
- type ListOfIntsArgument
- func (arg *ListOfIntsArgument) Consume(arguments []string) ([]string, error)
- func (arg ListOfIntsArgument) GetDefaultValue() any
- func (arg ListOfIntsArgument) GetHelp() string
- func (arg ListOfIntsArgument) GetLongName() string
- func (arg ListOfIntsArgument) GetShortName() string
- func (arg ListOfIntsArgument) GetValue() any
- func (arg *ListOfIntsArgument) Init(value *[]int, shortName, longName string, defaultValue []int, required bool, ...)
- func (arg ListOfIntsArgument) IsPresent() bool
- func (arg ListOfIntsArgument) IsRequired() bool
- func (arg *ListOfIntsArgument) ResetDefaultValue()
- func (arg *ListOfIntsArgument) SetValue(value any)
- type ListOfStringsArgument
- func (arg *ListOfStringsArgument) Consume(arguments []string) ([]string, error)
- func (arg ListOfStringsArgument) GetDefaultValue() any
- func (arg ListOfStringsArgument) GetHelp() string
- func (arg ListOfStringsArgument) GetLongName() string
- func (arg ListOfStringsArgument) GetShortName() string
- func (arg ListOfStringsArgument) GetValue() any
- func (arg *ListOfStringsArgument) Init(value *[]string, shortName, longName string, defaultValue []string, ...)
- func (arg ListOfStringsArgument) IsPresent() bool
- func (arg ListOfStringsArgument) IsRequired() bool
- func (arg *ListOfStringsArgument) ResetDefaultValue()
- func (arg *ListOfStringsArgument) SetValue(value any)
- type MapOfHttpHeadersArgument
- func (arg *MapOfHttpHeadersArgument) Consume(arguments []string) ([]string, error)
- func (arg MapOfHttpHeadersArgument) GetDefaultValue() any
- func (arg MapOfHttpHeadersArgument) GetHelp() string
- func (arg MapOfHttpHeadersArgument) GetLongName() string
- func (arg MapOfHttpHeadersArgument) GetShortName() string
- func (arg MapOfHttpHeadersArgument) GetValue() any
- func (arg *MapOfHttpHeadersArgument) Init(value *map[string]string, shortName, longName string, ...)
- func (arg MapOfHttpHeadersArgument) IsPresent() bool
- func (arg MapOfHttpHeadersArgument) IsRequired() bool
- func (arg *MapOfHttpHeadersArgument) ResetDefaultValue()
- func (arg *MapOfHttpHeadersArgument) SetValue(value any)
- type StringArgument
- func (arg *StringArgument) Consume(arguments []string) ([]string, error)
- func (arg StringArgument) GetDefaultValue() any
- func (arg StringArgument) GetHelp() string
- func (arg StringArgument) GetLongName() string
- func (arg StringArgument) GetShortName() string
- func (arg StringArgument) GetValue() any
- func (arg *StringArgument) Init(value *string, shortName, longName string, defaultValue string, required bool, ...)
- func (arg StringArgument) IsPresent() bool
- func (arg StringArgument) IsRequired() bool
- func (arg *StringArgument) ResetDefaultValue()
- func (arg *StringArgument) SetValue(value any)
- type TcpPortArgument
- func (arg *TcpPortArgument) Consume(arguments []string) ([]string, error)
- func (arg TcpPortArgument) GetDefaultValue() any
- func (arg TcpPortArgument) GetHelp() string
- func (arg TcpPortArgument) GetLongName() string
- func (arg TcpPortArgument) GetShortName() string
- func (arg TcpPortArgument) GetValue() any
- func (arg *TcpPortArgument) Init(value *int, shortName, longName string, defaultValue int, required bool, ...)
- func (arg TcpPortArgument) IsPresent() bool
- func (arg TcpPortArgument) IsRequired() bool
- func (arg *TcpPortArgument) ResetDefaultValue()
- func (arg *TcpPortArgument) SetValue(value any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument interface {
// GetShortName returns the short name (single-character) representation
// of the argument (e.g., "-h" for help).
GetShortName() string
// GetLongName returns the long name (multi-character) representation
// of the argument (e.g., "--help").
GetLongName() string
// GetHelp returns a help message or description for the argument.
// This information is displayed when the user requests help or
// usage information for the program.
GetHelp() string
// GetValue retrieves the current value of the argument after parsing.
// This returns the actual value specified by the user during program execution.
GetValue() any
// SetValue sets the value of the argument.
SetValue(value any)
// GetDefaultValue returns the default value assigned to the argument.
// This value is used if the user does not provide an explicit value for the argument.
GetDefaultValue() any
// ResetDefaultValue resets the value of the argument to the default value.
ResetDefaultValue()
// IsRequired checks if the argument is marked as required.
// If true, the program will enforce that this argument must be provided
// by the user, otherwise an error will be thrown.
IsRequired() bool
// IsPresent checks if the argument was set in the command line.
IsPresent() bool
// Consume processes the command-line arguments, identifying and extracting
// values that correspond to this specific argument. The method returns
// a slice of the remaining unprocessed arguments after consuming the relevant ones.
Consume(arguments []string) ([]string, error)
}
Argument defines the essential methods that all command-line argument types must implement. This interface allows different types of arguments (e.g., strings, integers, booleans) to be parsed and handled uniformly within the program.
type BoolArgument ¶
type BoolArgument struct {
// ShortName is the short flag (e.g., "-b") used to specify the boolean argument.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--boolean") used to specify the boolean argument.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual boolean value provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *bool
// DefaultValue is the boolean to be used if the argument is not provided by the user.
DefaultValue bool
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
BoolArgument represents a command-line argument that expects a boolean value. It provides information about the argument's short and long flag names, help message, the default value, and whether the argument is required.
func (*BoolArgument) Consume ¶
func (arg *BoolArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the BoolArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the BoolArgument. If a match is found, it sets the value of the BoolArgument to true and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the BoolArgument.
func (BoolArgument) GetDefaultValue ¶
func (arg BoolArgument) GetDefaultValue() any
GetDefaultValue returns the default boolean value as an interface{}. This is used when the argument is not specified by the user.
func (BoolArgument) GetHelp ¶
func (arg BoolArgument) GetHelp() string
GetHelp returns the help message of the argument. This provides a description of how to use the argument.
func (BoolArgument) GetLongName ¶
func (arg BoolArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (BoolArgument) GetShortName ¶
func (arg BoolArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (BoolArgument) GetValue ¶
func (arg BoolArgument) GetValue() any
GetValue returns the current boolean value as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*BoolArgument) Init ¶
func (arg *BoolArgument) Init(value *bool, shortName, longName string, defaultValue bool, help string)
Init initializes the BoolArgument with the provided parameters. It sets the flag names, help message, actual value, and default value.
func (BoolArgument) IsPresent ¶
func (arg BoolArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (BoolArgument) IsRequired ¶
func (arg BoolArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*BoolArgument) ResetDefaultValue ¶
func (arg *BoolArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*BoolArgument) SetValue ¶
func (arg *BoolArgument) SetValue(value any)
SetValue sets the value of the BoolArgument. This is the boolean provided by the user or set by default.
type IntArgument ¶
type IntArgument struct {
// ShortName is the short flag (e.g., "-i") used to specify the integer argument.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--integer") used to specify the integer argument.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual integer value provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *int
// DefaultValue is the integer to be used if the argument is not provided by the user.
DefaultValue int
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
IntArgument represents a command-line argument that expects an integer value. It provides information about the argument's short and long flag names, help message, the default value, and whether the argument is required.
func (*IntArgument) Consume ¶
func (arg *IntArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the IntArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the IntArgument. If a match is found, it sets the value of the IntArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the IntArgument.
func (IntArgument) GetDefaultValue ¶
func (arg IntArgument) GetDefaultValue() any
GetDefaultValue returns the default integer value as an interface{}. This is used when the argument is not specified by the user.
func (IntArgument) GetHelp ¶
func (arg IntArgument) GetHelp() string
GetHelp returns the help message of the argument. This provides a description of how to use the argument.
func (IntArgument) GetLongName ¶
func (arg IntArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (IntArgument) GetShortName ¶
func (arg IntArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (IntArgument) GetValue ¶
func (arg IntArgument) GetValue() any
GetValue returns the current integer value as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*IntArgument) Init ¶
func (arg *IntArgument) Init(value *int, shortName, longName string, defaultValue int, required bool, help string)
Init initializes the IntArgument with the provided parameters. It sets the flag names, required status, help message, actual value, and default value.
func (IntArgument) IsPresent ¶
func (arg IntArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (IntArgument) IsRequired ¶
func (arg IntArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*IntArgument) ResetDefaultValue ¶
func (arg *IntArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*IntArgument) SetValue ¶
func (arg *IntArgument) SetValue(value any)
SetValue sets the value of the IntArgument. This is the integer provided by the user or set by default.
type IntRangeArgument ¶
type IntRangeArgument struct {
// ShortName is the short flag (e.g., "-i") used to specify the integer argument.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--integer") used to specify the integer argument.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual integer value provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *int
// DefaultValue is the integer to be used if the argument is not provided by the user.
DefaultValue int
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
// RangeStart defines the inclusive lower bound of the valid range for the integer argument.
RangeStart int
// RangeStop defines the inclusive upper bound of the valid range for the integer argument.
RangeStop int
}
IntRangeArgument represents a command-line argument that expects an integer value within a specified range. It provides information about the argument's short and long flag names, help message, the default value, whether the argument is required, and the valid range for the integer.
func (*IntRangeArgument) Consume ¶
func (arg *IntRangeArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the IntRangeArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the IntRangeArgument. If a match is found, it sets the value of the IntRangeArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the IntRangeArgument.
func (IntRangeArgument) GetDefaultValue ¶
func (arg IntRangeArgument) GetDefaultValue() any
GetDefaultValue returns the default integer value as an interface{}. This is used when the argument is not specified by the user.
func (IntRangeArgument) GetHelp ¶
func (arg IntRangeArgument) GetHelp() string
GetHelp returns the help message of the argument. This provides a description of how to use the argument.
func (IntRangeArgument) GetLongName ¶
func (arg IntRangeArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (IntRangeArgument) GetShortName ¶
func (arg IntRangeArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (IntRangeArgument) GetValue ¶
func (arg IntRangeArgument) GetValue() any
GetValue returns the current integer value as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*IntRangeArgument) Init ¶
func (arg *IntRangeArgument) Init(value *int, shortName, longName string, defaultValue, rangeStart, rangeStop int, required bool, help string)
Init initializes the IntRangeArgument with the provided parameters. It sets the flag names, required status, help message, actual value, and default value.
func (IntRangeArgument) IsPresent ¶
func (arg IntRangeArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (IntRangeArgument) IsRequired ¶
func (arg IntRangeArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*IntRangeArgument) ResetDefaultValue ¶
func (arg *IntRangeArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*IntRangeArgument) SetValue ¶
func (arg *IntRangeArgument) SetValue(value any)
SetValue sets the value of the IntRangeArgument. This is the integer provided by the user or set by default.
type ListOfIntsArgument ¶
type ListOfIntsArgument struct {
// ShortName is the short flag (e.g., "-i") used to specify the list of integers.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--ints") used to specify the list of integers.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual list of integers provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *[]int
// DefaultValue is the list of integers to be used if the argument is not provided by the user.
DefaultValue []int
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
ListOfIntsArgument represents a command-line argument that expects a list of integers. It provides information about the argument's short and long flag names, help message, the default value, and whether the argument is required.
func (*ListOfIntsArgument) Consume ¶
func (arg *ListOfIntsArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the ListOfIntsArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the ListOfIntsArgument. If a match is found, it sets the value of the ListOfIntsArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the ListOfIntsArgument.
func (ListOfIntsArgument) GetDefaultValue ¶
func (arg ListOfIntsArgument) GetDefaultValue() any
GetDefaultValue returns the default list of integers as an interface{}. This is used when the argument is not specified by the user.
func (ListOfIntsArgument) GetHelp ¶
func (arg ListOfIntsArgument) GetHelp() string
GetHelp returns the help message of the argument. This provides a description of how to use the argument.
func (ListOfIntsArgument) GetLongName ¶
func (arg ListOfIntsArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (ListOfIntsArgument) GetShortName ¶
func (arg ListOfIntsArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (ListOfIntsArgument) GetValue ¶
func (arg ListOfIntsArgument) GetValue() any
GetValue returns the current list of integers as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*ListOfIntsArgument) Init ¶
func (arg *ListOfIntsArgument) Init(value *[]int, shortName, longName string, defaultValue []int, required bool, help string)
Init initializes the ListOfIntsArgument with the provided parameters. It sets the flag names, required status, help message, actual value, and default value.
func (ListOfIntsArgument) IsPresent ¶
func (arg ListOfIntsArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (ListOfIntsArgument) IsRequired ¶
func (arg ListOfIntsArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*ListOfIntsArgument) ResetDefaultValue ¶
func (arg *ListOfIntsArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*ListOfIntsArgument) SetValue ¶
func (arg *ListOfIntsArgument) SetValue(value any)
SetValue sets the value of the ListOfIntsArgument. This is the list of integers provided by the user or set by default.
type ListOfStringsArgument ¶
type ListOfStringsArgument struct {
// ShortName is the short flag (e.g., "-s") used to specify the list of strings.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--strings") used to specify the list of strings.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual list of strings provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *[]string
// DefaultValue is the list of strings to be used if the argument is not provided by the user.
DefaultValue []string
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
ListOfStringsArgument represents a command-line argument that expects a list of strings. It provides information about the argument's short and long flag names, help message, the default value, and whether the argument is required.
func (*ListOfStringsArgument) Consume ¶
func (arg *ListOfStringsArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the ListOfStringsArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the ListOfStringsArgument. If a match is found, it sets the value of the ListOfStringsArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the ListOfStringsArgument.
func (ListOfStringsArgument) GetDefaultValue ¶
func (arg ListOfStringsArgument) GetDefaultValue() any
GetDefaultValue returns the default list of strings as an interface{}. This is used when the argument is not specified by the user.
func (ListOfStringsArgument) GetHelp ¶
func (arg ListOfStringsArgument) GetHelp() string
GetHelp returns the help message of the argument. This provides a description of how to use the argument.
func (ListOfStringsArgument) GetLongName ¶
func (arg ListOfStringsArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (ListOfStringsArgument) GetShortName ¶
func (arg ListOfStringsArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (ListOfStringsArgument) GetValue ¶
func (arg ListOfStringsArgument) GetValue() any
GetValue returns the current list of strings as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*ListOfStringsArgument) Init ¶
func (arg *ListOfStringsArgument) Init(value *[]string, shortName, longName string, defaultValue []string, required bool, help string)
Init initializes the ListOfStringsArgument with the provided values.
The function sets the short name, long name, help message, value, and default value for the ListOfStringsArgument. It ensures that the short name and long name are properly formatted with leading dashes.
Parameters:
- value: A pointer to a string where the value of the argument will be stored.
- shortName: The short name of the argument (single character). If empty, it will be set to an empty string.
- longName: The long name of the argument (string). If empty, it will be set to an empty string.
- defaultValue: The default value of the argument.
- help: The help message describing the argument.
The function uses the utils.StripLeftDashes function to remove any leading dashes from the short name and long name before adding a single dash for the short name and a double dash for the long name.
func (ListOfStringsArgument) IsPresent ¶
func (arg ListOfStringsArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (ListOfStringsArgument) IsRequired ¶
func (arg ListOfStringsArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*ListOfStringsArgument) ResetDefaultValue ¶
func (arg *ListOfStringsArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*ListOfStringsArgument) SetValue ¶
func (arg *ListOfStringsArgument) SetValue(value any)
SetValue sets the value of the ListOfStringsArgument. This is the list of strings provided by the user or set by default.
type MapOfHttpHeadersArgument ¶
type MapOfHttpHeadersArgument struct {
// ShortName is the short flag (e.g., "-H") used to specify the HTTP headers.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--headers") used to specify the HTTP headers.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual map of HTTP headers provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *map[string]string
// DefaultValue is the map of HTTP headers to be used if the argument is not provided by the user.
DefaultValue map[string]string
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
MapOfHttpHeadersArgument represents a command-line argument that expects a map of HTTP headers. It contains information about the argument's short and long flag names, help message, the default value, and whether the argument is required.
func (*MapOfHttpHeadersArgument) Consume ¶
func (arg *MapOfHttpHeadersArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the MapOfHttpHeadersArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the MapOfHttpHeadersArgument. If a match is found, it sets the value of the MapOfHttpHeadersArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the MapOfHttpHeadersArgument.
func (MapOfHttpHeadersArgument) GetDefaultValue ¶
func (arg MapOfHttpHeadersArgument) GetDefaultValue() any
GetDefaultValue returns the default map of HTTP headers as an interface{}. This is used when the argument is not specified by the user.
func (MapOfHttpHeadersArgument) GetHelp ¶
func (arg MapOfHttpHeadersArgument) GetHelp() string
GetHelp returns the help message of the argument. This provides a description of how to use the argument.
func (MapOfHttpHeadersArgument) GetLongName ¶
func (arg MapOfHttpHeadersArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (MapOfHttpHeadersArgument) GetShortName ¶
func (arg MapOfHttpHeadersArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (MapOfHttpHeadersArgument) GetValue ¶
func (arg MapOfHttpHeadersArgument) GetValue() any
GetValue returns the current map of HTTP headers as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*MapOfHttpHeadersArgument) Init ¶
func (arg *MapOfHttpHeadersArgument) Init(value *map[string]string, shortName, longName string, defaultValue map[string]string, required bool, help string)
Init initializes the MapOfHttpHeadersArgument with the provided values.
The function sets the short name, long name, help message, value, and default value for the MapOfHttpHeadersArgument. It ensures that the short name and long name are properly formatted with leading dashes.
Parameters:
- value: A pointer to a string where the value of the argument will be stored.
- shortName: The short name of the argument (single character). If empty, it will be set to an empty string.
- longName: The long name of the argument (string). If empty, it will be set to an empty string.
- defaultValue: The default value of the argument.
- help: The help message describing the argument.
The function uses the utils.StripLeftDashes function to remove any leading dashes from the short name and long name before adding a single dash for the short name and a double dash for the long name.
func (MapOfHttpHeadersArgument) IsPresent ¶
func (arg MapOfHttpHeadersArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (MapOfHttpHeadersArgument) IsRequired ¶
func (arg MapOfHttpHeadersArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*MapOfHttpHeadersArgument) ResetDefaultValue ¶
func (arg *MapOfHttpHeadersArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*MapOfHttpHeadersArgument) SetValue ¶
func (arg *MapOfHttpHeadersArgument) SetValue(value any)
SetValue sets the value of the MapOfHttpHeadersArgument. This is the map of HTTP headers provided by the user or set by default.
type StringArgument ¶
type StringArgument struct {
// ShortName is the short flag (e.g., "-n") used to specify the string value.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--name") used to specify the string value.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual string value provided by the user.
// If no value is specified by the user, Value will hold the DefaultValue.
Value *string
// DefaultValue is the string to be used if the argument is not provided by the user.
DefaultValue string
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
StringArgument represents a command-line argument that expects a string value. It contains information about the argument's short and long flag names, help message, the default value, and whether the argument is required.
func (*StringArgument) Consume ¶
func (arg *StringArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the StringArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the StringArgument. If a match is found, it sets the value of the StringArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the StringArgument.
func (StringArgument) GetDefaultValue ¶
func (arg StringArgument) GetDefaultValue() any
GetDefaultValue returns the default value of the argument as an interface{}. This is used when the argument is not specified by the user.
func (StringArgument) GetHelp ¶
func (arg StringArgument) GetHelp() string
GetHelp returns the help message of the argument. If the argument is optional, it appends the default value to the message.
func (StringArgument) GetLongName ¶
func (arg StringArgument) GetLongName() string
GetLongName returns the long flag name of the argument. If no long flag is defined, it returns an empty string.
func (StringArgument) GetShortName ¶
func (arg StringArgument) GetShortName() string
GetShortName returns the short flag name of the argument. If no short flag is defined, it returns an empty string.
func (StringArgument) GetValue ¶
func (arg StringArgument) GetValue() any
GetValue returns the current value of the argument as an interface{}. It will return the actual value provided by the user or the default value if none was specified.
func (*StringArgument) Init ¶
func (arg *StringArgument) Init(value *string, shortName, longName string, defaultValue string, required bool, help string)
Init initializes the StringArgument with the provided values.
The function sets the short name, long name, help message, value, and default value for the StringArgument. It ensures that the short name and long name are properly formatted with leading dashes.
Parameters:
- value: A pointer to a string where the value of the argument will be stored.
- shortName: The short name of the argument (single character). If empty, it will be set to an empty string.
- longName: The long name of the argument (string). If empty, it will be set to an empty string.
- defaultValue: The default value of the argument.
- help: The help message describing the argument.
The function uses the utils.StripLeftDashes function to remove any leading dashes from the short name and long name before adding a single dash for the short name and a double dash for the long name.
func (StringArgument) IsPresent ¶
func (arg StringArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (StringArgument) IsRequired ¶
func (arg StringArgument) IsRequired() bool
IsRequired returns whether the argument is required. If true, the argument must be specified when running the program.
func (*StringArgument) ResetDefaultValue ¶
func (arg *StringArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*StringArgument) SetValue ¶
func (arg *StringArgument) SetValue(value any)
SetValue sets the value of the StringArgument. This is the string provided by the user or set by default.
type TcpPortArgument ¶
type TcpPortArgument struct {
// ShortName is the short flag (e.g., "-p") used to specify the TCP port.
// It can be empty if no short flag is defined.
ShortName string
// LongName is the long flag (e.g., "--port") used to specify the TCP port.
// It can be empty if no long flag is defined.
LongName string
// Help provides a description of what this argument represents.
// This message is displayed when showing help/usage information.
Help string
// Value stores the actual TCP port number provided by the user.
// If no port is specified by the user, the Value will hold the DefaultValue.
Value *int
// DefaultValue is the port number to be used if the argument is not provided by the user.
DefaultValue int
// Required indicates whether this argument must be specified by the user.
// If true, the argument must be included when running the program.
Required bool
// Present indicates whether this argument was set by the user during execution.
// This can be used to differentiate between arguments that were provided and those that were not,
// allowing for different handling of default values or other logic in the program.
Present bool
}
TcpPortArgument represents a command-line argument that specifies a TCP port. It holds information about the argument's short and long flag names, help message, and whether it is required or optional with a default value.
func (*TcpPortArgument) Consume ¶
func (arg *TcpPortArgument) Consume(arguments []string) ([]string, error)
Consume processes the command-line arguments and sets the value of the TcpPortArgument.
The function iterates through the provided arguments and checks if any of them match the short or long name of the TcpPortArgument. If a match is found, it sets the value of the TcpPortArgument to the next argument in the list and returns the remaining arguments. If the argument is required and not found, it returns an error.
Parameters:
- arguments: A slice of strings representing the command-line arguments.
Returns: - A slice of strings representing the remaining arguments after processing the TcpPortArgument.
func (TcpPortArgument) GetDefaultValue ¶
func (arg TcpPortArgument) GetDefaultValue() any
GetDefaultValue returns the default value of the TcpPortArgument.
func (TcpPortArgument) GetHelp ¶
func (arg TcpPortArgument) GetHelp() string
GetHelp returns the help message associated with the TcpPortArgument. If the argument is optional, the default value is appended to the help message.
func (TcpPortArgument) GetLongName ¶
func (arg TcpPortArgument) GetLongName() string
GetLongName returns the long flag name (e.g., "--port") of the TcpPortArgument. If the long name is not set, it returns an empty string.
func (TcpPortArgument) GetShortName ¶
func (arg TcpPortArgument) GetShortName() string
GetShortName returns the short flag name (e.g., "-p") of the TcpPortArgument. If the short name is not set, it returns an empty string.
func (TcpPortArgument) GetValue ¶
func (arg TcpPortArgument) GetValue() any
GetValue retrieves the value of the TcpPortArgument. This is the port number provided by the user or set by default.
func (*TcpPortArgument) Init ¶
func (arg *TcpPortArgument) Init(value *int, shortName, longName string, defaultValue int, required bool, help string)
Init initializes the TcpPortArgument with the provided values.
Parameters:
- value (*int): Pointer to store the value of the argument.
- shortName (string): Short flag (e.g., "-p").
- longName (string): Long flag (e.g., "--port").
- defaultValue (int): Default value if the argument is not provided.
- required (bool): Indicates whether the argument is required.
- help (string): Help message to describe the argument.
func (TcpPortArgument) IsPresent ¶
func (arg TcpPortArgument) IsPresent() bool
IsPresent checks if the argument was set in the command line.
func (TcpPortArgument) IsRequired ¶
func (arg TcpPortArgument) IsRequired() bool
IsRequired checks if the TcpPortArgument is marked as required.
func (*TcpPortArgument) ResetDefaultValue ¶
func (arg *TcpPortArgument) ResetDefaultValue()
ResetDefaultValue resets the value of the argument to the default value.
func (*TcpPortArgument) SetValue ¶
func (arg *TcpPortArgument) SetValue(value any)
SetValue sets the value of the TcpPortArgument. This is the port number provided by the user or set by default.