Skip to content

Electron7-7/getargs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 

Repository files navigation

getargs

A simple C++ header-only library for easily parsing command line arguments. Querying the version can be done via three pre-processor definitions: GETARGS_VERSION_MAJOR, GETARGS_VERSION_MINOR, and GETARGS_VERSION_PATCH.

Index


Function Reference

template<String_t... Args> void set_valid_args(Args...)

int get_args(int const& argc, char** const& argv)

Parses command-line arguments from argv, initializes the parsed argument containers, and returns a status indicator (0 if successful). See GETARGS_HANDLE_HELP_FLAG, GETARGS_HANDLE_VERSION_FLAG, and GETARGS_HANDLE_INVALID_ARGS for more information on other return values.


const GETARGS_STRING_t get_bad_arg()

Requires [GETARGS_HANDLE_INVALID_ARGS] to be defined. If an invalid argument is parsed during getargs::get_args, getargs::get_bad_arg will return the invalid argument. Otherwise, an empty GETARGS_STRING_t will be returned instead.


bool get_flag(const GETARGS_STRING_t&)

Returns true if the flag was called in the command line, and false if not.


bool get_option(const GETARGS_STRING_t&, GETARGS_STRING_t&)

If the option was called in the command line, the output GETARGS_STRING_t argument will be set to the value assigned to the option and the function will return true. Otherwise, the argument is untouched and false is returned.


const GETARGS_STRING_t& get_option(const GETARGS_STRING_t&)

If the option was called in the command line, the value assigned to the option will be returned. Otherwise, an empty GETARGS_STRING_t is returned instead.


bool argument_exists(const GETARGS_STRING_t&)

Returns true if the argument was called in the command line. If an option was called but no value was given, this will still return true. Returns false otherwise.


bool option_has_value(const GETARGS_STRING_t&)

Returns true if the option was called in the command line and a value was assigned to it. Returns false otherwise.


Pre-Processor Definition Reference

GETARGS_IMPLEMENTATION

Must be defined before including the library.


GETARGS_NAMESPACE_NAME_OVERRIDE

Overrides the library's namespace name, which is getargs by default.


GETARGS_HANDLE_HELP_FLAG

Enables the handling of arguments matching GETARGS_LONG_HELP_FLAG and, if it's been defined, GETARGS_SHORT_HELP_FLAG. By default, handling is done by printing GETARGS_HELP_PRINTOUT, and returning getargs::HELP_CALLED from getargs::get_args which has had its return value changed from int to getargs::Status.


GETARGS_EXIT_ON_HELP

If GETARGS_HANDLE_HELP_FLAG is defined, handling is instead done by exiting the program via exit(0); after the printout.


GETARGS_LONG_HELP_FLAG

If GETARGS_HANDLE_HELP_FLAG is defined, arguments are matched against GETARGS_LONG_HELP_FLAG during getargs::get_args to determine whether or not the help flag has appeared. By default, this is set to "--help".


GETARGS_SHORT_HELP_FLAG

If GETARGS_HANDLE_HELP_FLAG is defined, arguments are also matched against GETARGS_SHORT_HELP_FLAG during getargs::get_args to determine whether or not the help flag has appeared. By default, this is undefined and not used.


GETARGS_HELP_PRINTOUT

If GETARGS_HANDLE_HELP_FLAG is defined, GETARGS_HELP_PRINTOUT will be printed to the console when the help flag has been parsed.


GETARGS_HANDLE_VERSION_FLAG

Enables the handling of arguments matching GETARGS_LONG_VERSION_FLAG and, if it's been defined, GETARGS_SHORT_VERSION_FLAG. By default, handling is done by printing GETARGS_VERSION_PRINTOUT, and returning getargs::VERSION_CALLED from getargs::get_args, which has had its return value changed from int to getargs::Status.


GETARGS_EXIT_ON_VERSION

If GETARGS_HANDLE_VERSION_FLAG is defined, handling is instead done by exiting the program via exit(0); after the printout.


GETARGS_LONG_VERSION_FLAG

If GETARGS_HANDLE_VERSION_FLAG is defined, arguments are matched against GETARGS_LONG_VERSION_FLAG during getargs::get_args to determine whether or not the version flag has appeared. By default, this is set to "--version".


GETARGS_SHORT_VERSION_FLAG

If GETARGS_HANDLE_VERSION_FLAG is defined, arguments are also matched against GETARGS_SHORT_VERSION_FLAG during getargs::get_args to determine whether or not the version flag has appeared. By default, this is undefined and not used.


GETARGS_VERSION_PRINTOUT

If GETARGS_HANDLE_VERSION_FLAG is defined, GETARGS_VERSION_PRINTOUT will be printed to the console when the help flag has been parsed.


GETARGS_HANDLE_INVALID_ARGS

Enables the handling of invalid arguments. Now, before arguments can be parsed, valid arguments must be passed to getargs::set_valid_args. By default, handling is done by printing an error message to stderr, and returning getargs::INVALID_ARGUMENT from getargs::get_args, which has had its return value changed from int to getargs::Status.


GETARGS_EXIT_ON_INVALID_ARG

If GETARGS_HANDLE_INVALID_ARGS is defined, handling is instead done by exiting the program via exit(-1); after the printout.


GETARGS_STRING_t

Defines the class used to handle strings. By default, this is set to std::string


GETARGS_MAP_t

Defines the class used to handle maps. By default, this is set to std::map


GETARGS_SET_t

Defines the class used to handle sets. By default, this is set to std::set


GETARGS_VECTOR_t

Defines the class used to handle vectors. By default, this is set to std::vector


GETARGS_SAMEAS_c

Defines one of the constraints used by getargs::set_valid_args when GETARGS_HANDLE_INVALID_ARGS is defined. By default, this is set to std::same_as<T, U>


GETARGS_CONVERTIBLE_TO_c

Defines one of the constraints used by getargs::set_valid_args when GETARGS_HANDLE_INVALID_ARGS is defined. By default, this is set to std::convertible_to<From, To>

About

A simple C++ single-header library for easily parsing command line arguments.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages