argumentgroup

package
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ARGUMENT_GROUP_TYPE_NORMAL defines a basic group of arguments
	// where each argument is treated independently. There are no specific
	// rules governing which arguments must or must not be set.
	// This is the default behavior for argument groups.
	ARGUMENT_GROUP_TYPE_NORMAL = 0

	// ARGUMENT_GROUP_TYPE_REQUIRED_MUTUALLY_EXCLUSIVE creates a group
	// where exactly one argument must be set. If more than one or none
	// of the arguments in this group are specified, the parser will throw an error.
	// This is useful for scenarios where a user must choose one of several options.
	ARGUMENT_GROUP_TYPE_REQUIRED_MUTUALLY_EXCLUSIVE = 1

	// ARGUMENT_GROUP_TYPE_NOT_REQUIRED_MUTUALLY_EXCLUSIVE defines a group
	// where at most one argument can be set, but it is not mandatory to set any.
	// If multiple arguments from this group are provided, the parser will throw an error.
	// It is designed for optional settings where only one should be active if chosen.
	ARGUMENT_GROUP_TYPE_NOT_REQUIRED_MUTUALLY_EXCLUSIVE = 2

	// ARGUMENT_GROUP_TYPE_DEPENDENT ensures that if one argument in the group
	// is set, all other arguments in the group must also be set. If any are missing,
	// the parser will throw an error. This is useful for scenarios where arguments
	// are interdependent and must be specified together for correct operation.
	ARGUMENT_GROUP_TYPE_DEPENDENT = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgumentGroup

type ArgumentGroup struct {
	// Name is the identifier for the argument group, often used for display purposes.
	Name string

	// Arguments is a list of Argument pointers that belong to this group.
	Arguments []arguments.Argument

	// ShortNameToArgument maps short argument names (e.g., "-f") to their corresponding Argument.
	ShortNameToArgument map[string]arguments.Argument

	// LongNameToArgument maps long argument names (e.g., "--file") to their corresponding Argument.
	LongNameToArgument map[string]arguments.Argument

	// Type is an integer that can represent the type or category of the argument group.
	// This can be used for conditional handling or to differentiate between groups.
	Type int
}

ArgumentGroup represents a group of arguments with associated metadata. It is used to categorize and manage related command-line arguments.

func (*ArgumentGroup) ArgumentIsPresent

func (ag *ArgumentGroup) ArgumentIsPresent(argumentName string) bool

ArgumentIsPresent checks if a given argument is present in the parsed arguments. It supports both short (e.g., -e) and long (e.g., --example) argument names.

Parameters:

  • argumentName: The name of the argument to check. It should start with a dash ('-') for short arguments or two dashes ('--') for long arguments.

Returns: - bool: true if the argument is present; false otherwise.

The function first verifies that the argument name has a valid length and starts with a dash. It then checks if the argument is in the `LongNameToArgument` map for long arguments or `ShortNameToArgument` map for short arguments, returning true if found and false if not.

func (*ArgumentGroup) NewBoolArgument

func (ag *ArgumentGroup) NewBoolArgument(ptr *bool, shortName, longName string, defaultValue bool, help string) error

NewBoolArgument registers a new boolean argument with the argument parser.

Parameters: - ptr: A pointer to the boolean variable where the argument value will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-S"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--use-ldaps"). - defaultValue: The default value of the argument if it is not provided by the user. - help: A description of the argument, which will be displayed in the help message.

The function creates a new BoolArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) NewIntArgument

func (ag *ArgumentGroup) NewIntArgument(ptr *int, shortName, longName string, defaultValue int, required bool, help string) error

NewIntArgument registers a new integer argument with the argument parser.

Parameters: - ptr: A pointer to the integer variable where the argument value will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-i"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--iterations"). - defaultValue: The default value of the argument if it is not provided by the user. - help: A description of the argument, which will be displayed in the help message.

The function creates a new IntArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) NewIntRangeArgument

func (ag *ArgumentGroup) NewIntRangeArgument(ptr *int, shortName, longName string, defaultValue int, min int, max int, required bool, help string) error

NewIntRangeArgument registers a new integer range argument with the argument parser.

Parameters: - ptr: A pointer to the integer variable where the argument value will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-i"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--iterations"). - defaultValue: The default value of the argument if it is not provided by the user. - min: The minimum value of the argument. - max: The maximum value of the argument. - required: Indicates whether the argument must be specified by the user. - help: A description of the argument, which will be displayed in the help message.

The function creates a new IntRangeArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) NewListOfIntsArgument

func (ag *ArgumentGroup) NewListOfIntsArgument(ptr *[]int, shortName, longName string, defaultValue []int, required bool, help string) error

NewListOfIntsArgument registers a new list of integers argument with the argument parser.

Parameters: - ptr: A pointer to the slice of int variables where the argument values will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-n"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--numbers"). - defaultValue: The default list of integers if the argument is not provided by the user. - required: A boolean indicating if the argument is mandatory. - help: A description of the argument, which will be displayed in the help message.

The function creates a new ListOfIntsArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) NewListOfStringsArgument

func (ag *ArgumentGroup) NewListOfStringsArgument(ptr *[]string, shortName, longName string, defaultValue []string, required bool, help string) error

NewListOfStringsArgument registers a new list of strings argument with the argument parser.

Parameters: - ptr: A pointer to the slice of string variables where the argument values will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-s"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--strings"). - defaultValue: The default list of strings if the argument is not provided by the user. - required: A boolean indicating if the argument is mandatory. - help: A description of the argument, which will be displayed in the help message.

The function creates a new ListOfStringsArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) NewMapOfHttpHeadersArgument

func (ag *ArgumentGroup) NewMapOfHttpHeadersArgument(ptr *map[string]string, shortName, longName string, defaultValue map[string]string, required bool, help string) error

NewMapOfHttpHeadersArgument registers a new list of HTTP headers argument with the argument parser.

Parameters: - ptr: A pointer to the slice of string variables where the argument values will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-H"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--header"). - required: A boolean indicating if the argument is mandatory. - help: A description of the argument, which will be displayed in the help message.

The function creates a new MapOfHttpHeadersArgument with the provided parameters and adds it to the argument group. Each header should be passed in the format "Key: Value".

func (*ArgumentGroup) NewStringArgument

func (ag *ArgumentGroup) NewStringArgument(ptr *string, shortName, longName string, defaultValue string, required bool, help string) error

NewStringArgument registers a new string argument with the argument parser.

Parameters: - ptr: A pointer to the string variable where the argument value will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-u"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--username"). - defaultValue: The default value of the argument if it is not provided by the user. - help: A description of the argument, which will be displayed in the help message.

The function creates a new StringArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) NewTcpPortArgument

func (ag *ArgumentGroup) NewTcpPortArgument(ptr *int, shortName, longName string, defaultValue int, required bool, help string) error

NewTcpPortArgument registers a new integer argument with the argument parser.

Parameters: - ptr: A pointer to the integer variable where the argument value will be stored. - shortName: The short name (single character) of the argument, prefixed with a dash (e.g., "-i"). - longName: The long name of the argument, prefixed with two dashes (e.g., "--iterations"). - defaultValue: The default value of the argument if it is not provided by the user. - help: A description of the argument, which will be displayed in the help message.

The function creates a new IntArgument with the provided parameters and adds it to the argument group.

func (*ArgumentGroup) PrintArgumentTree

func (ag *ArgumentGroup) PrintArgumentTree(indent int)

PrintArgumentTree prints the argument tree for the argument group.

Parameters: - indent: The indentation level for the printed output.

The function prints the name of the argument group and its arguments in a tree-like structure, with each level of indentation represented by " │ ". The output includes the group name and the names of the arguments within the group.

func (*ArgumentGroup) Register

func (ag *ArgumentGroup) Register(arg arguments.Argument) error

Register registers a new argument with the argument group if it does not already exist.

Parameters: - arg: The argument to be registered.

The function checks if the argument's short name and long name are already present in the ShortNameToArgument and LongNameToArgument maps. If not, it adds the argument to these maps and appends it to the Arguments slice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL