WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::ArgumentParser Class Reference

#include <wpi/argparse.h>

Classes

class  MutuallyExclusiveGroup
 

Public Member Functions

 ArgumentParser (std::string program_name={}, std::string version="1.0", default_arguments add_args=default_arguments::all, bool exit_on_default_arguments=true, std::ostream &os=std::cout)
 
 ~ArgumentParser ()=default
 
 ArgumentParser (const ArgumentParser &other)=delete
 
ArgumentParseroperator= (const ArgumentParser &other)=delete
 
 ArgumentParser (ArgumentParser &&) noexcept=delete
 
ArgumentParseroperator= (ArgumentParser &&)=delete
 
 operator bool () const
 
template<typename... Targs>
Argumentadd_argument (Targs... f_args)
 
MutuallyExclusiveGroupadd_mutually_exclusive_group (bool required=false)
 
template<typename... Targs>
ArgumentParseradd_parents (const Targs &... f_args)
 
ArgumentParseradd_usage_newline ()
 
ArgumentParseradd_group (std::string group_name)
 
ArgumentParseradd_description (std::string description)
 
ArgumentParseradd_epilog (std::string epilog)
 
ArgumentParseradd_hidden_alias_for (Argument &arg, std::string_view alias)
 
template<typename T = Argument>
T & at (std::string_view name)
 
ArgumentParserset_prefix_chars (std::string prefix_chars)
 
ArgumentParserset_assign_chars (std::string assign_chars)
 
void parse_args (const std::vector< std::string > &arguments)
 
std::vector< std::string > parse_known_args (const std::vector< std::string > &arguments)
 
void parse_args (int argc, const char *const argv[])
 
auto parse_known_args (int argc, const char *const argv[])
 
template<typename T = std::string>
get (std::string_view arg_name) const
 
template<typename T = std::string>
auto present (std::string_view arg_name) const -> std::optional< T >
 
auto is_used (std::string_view arg_name) const
 
auto is_subcommand_used (std::string_view subcommand_name) const
 
auto is_subcommand_used (const ArgumentParser &subparser) const
 
Argumentoperator[] (std::string_view arg_name) const
 
auto help () const -> std::stringstream
 
ArgumentParserset_usage_max_line_width (size_t w)
 
ArgumentParserset_usage_break_on_mutex ()
 
auto usage () const -> std::string
 
std::string print_help () const
 
void add_subparser (ArgumentParser &parser)
 
void set_suppress (bool suppress)
 

Protected Types

using argument_it = std::list<Argument>::iterator
 
using mutex_group_it = std::vector<MutuallyExclusiveGroup>::iterator
 
using argument_parser_it
 

Protected Member Functions

const MutuallyExclusiveGroupget_belonging_mutex (const Argument *arg) const
 
bool is_valid_prefix_char (char c) const
 
char get_any_valid_prefix_char () const
 
std::vector< std::string > preprocess_arguments (const std::vector< std::string > &raw_arguments) const
 
void parse_args_internal (const std::vector< std::string > &raw_arguments)
 
std::vector< std::string > parse_known_args_internal (const std::vector< std::string > &raw_arguments)
 
std::size_t get_length_of_longest_argument () const
 
void index_argument (argument_it it)
 

Protected Attributes

std::string m_program_name
 
std::string m_version
 
std::string m_description
 
std::string m_epilog
 
bool m_exit_on_default_arguments = true
 
std::string m_prefix_chars {"-"}
 
std::string m_assign_chars {"="}
 
bool m_is_parsed = false
 
std::list< Argumentm_positional_arguments
 
std::list< Argumentm_optional_arguments
 
std::map< std::string, argument_itm_argument_map
 
std::string m_parser_path
 
std::list< std::reference_wrapper< ArgumentParser > > m_subparsers
 
std::map< std::string, argument_parser_itm_subparser_map
 
std::map< std::string, bool > m_subparser_used
 
std::vector< MutuallyExclusiveGroupm_mutually_exclusive_groups
 
bool m_suppress = false
 
std::size_t m_usage_max_line_width = (std::numeric_limits<std::size_t>::max)()
 
bool m_usage_break_on_mutex = false
 
int m_usage_newline_counter = 0
 
std::vector< std::string > m_group_names
 

Friends

auto operator<< (std::ostream &stream, const ArgumentParser &parser) -> std::ostream &
 

Member Typedef Documentation

◆ argument_it

using wpi::ArgumentParser::argument_it = std::list<Argument>::iterator
protected

◆ argument_parser_it

Initial value:
std::list<std::reference_wrapper<ArgumentParser>>::iterator

◆ mutex_group_it

using wpi::ArgumentParser::mutex_group_it = std::vector<MutuallyExclusiveGroup>::iterator
protected

Constructor & Destructor Documentation

◆ ArgumentParser() [1/3]

wpi::ArgumentParser::ArgumentParser ( std::string program_name = {},
std::string version = "1.0",
default_arguments add_args = default_arguments::all,
bool exit_on_default_arguments = true,
std::ostream & os = std::cout )
inlineexplicit

◆ ~ArgumentParser()

wpi::ArgumentParser::~ArgumentParser ( )
default

◆ ArgumentParser() [2/3]

wpi::ArgumentParser::ArgumentParser ( const ArgumentParser & other)
delete

◆ ArgumentParser() [3/3]

wpi::ArgumentParser::ArgumentParser ( ArgumentParser && )
deletenoexcept

Member Function Documentation

◆ add_argument()

template<typename... Targs>
Argument & wpi::ArgumentParser::add_argument ( Targs... f_args)
inline

◆ add_description()

ArgumentParser & wpi::ArgumentParser::add_description ( std::string description)
inline

◆ add_epilog()

ArgumentParser & wpi::ArgumentParser::add_epilog ( std::string epilog)
inline

◆ add_group()

ArgumentParser & wpi::ArgumentParser::add_group ( std::string group_name)
inline

◆ add_hidden_alias_for()

ArgumentParser & wpi::ArgumentParser::add_hidden_alias_for ( Argument & arg,
std::string_view alias )
inline

◆ add_mutually_exclusive_group()

MutuallyExclusiveGroup & wpi::ArgumentParser::add_mutually_exclusive_group ( bool required = false)
inline

◆ add_parents()

template<typename... Targs>
ArgumentParser & wpi::ArgumentParser::add_parents ( const Targs &... f_args)
inline

◆ add_subparser()

void wpi::ArgumentParser::add_subparser ( ArgumentParser & parser)
inline

◆ add_usage_newline()

ArgumentParser & wpi::ArgumentParser::add_usage_newline ( )
inline

◆ at()

template<typename T = Argument>
T & wpi::ArgumentParser::at ( std::string_view name)
inline

◆ get()

template<typename T = std::string>
T wpi::ArgumentParser::get ( std::string_view arg_name) const
inline

◆ get_any_valid_prefix_char()

char wpi::ArgumentParser::get_any_valid_prefix_char ( ) const
inlineprotected

◆ get_belonging_mutex()

const MutuallyExclusiveGroup * wpi::ArgumentParser::get_belonging_mutex ( const Argument * arg) const
inlineprotected

◆ get_length_of_longest_argument()

std::size_t wpi::ArgumentParser::get_length_of_longest_argument ( ) const
inlineprotected

◆ help()

auto wpi::ArgumentParser::help ( ) const -> std::stringstream
inline

◆ index_argument()

void wpi::ArgumentParser::index_argument ( argument_it it)
inlineprotected

◆ is_subcommand_used() [1/2]

auto wpi::ArgumentParser::is_subcommand_used ( const ArgumentParser & subparser) const
inline

◆ is_subcommand_used() [2/2]

auto wpi::ArgumentParser::is_subcommand_used ( std::string_view subcommand_name) const
inline

◆ is_used()

auto wpi::ArgumentParser::is_used ( std::string_view arg_name) const
inline

◆ is_valid_prefix_char()

bool wpi::ArgumentParser::is_valid_prefix_char ( char c) const
inlineprotected

◆ operator bool()

wpi::ArgumentParser::operator bool ( ) const
inlineexplicit

◆ operator=() [1/2]

ArgumentParser & wpi::ArgumentParser::operator= ( ArgumentParser && )
delete

◆ operator=() [2/2]

ArgumentParser & wpi::ArgumentParser::operator= ( const ArgumentParser & other)
delete

◆ operator[]()

Argument & wpi::ArgumentParser::operator[] ( std::string_view arg_name) const
inline

◆ parse_args() [1/2]

void wpi::ArgumentParser::parse_args ( const std::vector< std::string > & arguments)
inline

◆ parse_args() [2/2]

void wpi::ArgumentParser::parse_args ( int argc,
const char *const argv[] )
inline

◆ parse_args_internal()

void wpi::ArgumentParser::parse_args_internal ( const std::vector< std::string > & raw_arguments)
inlineprotected

◆ parse_known_args() [1/2]

std::vector< std::string > wpi::ArgumentParser::parse_known_args ( const std::vector< std::string > & arguments)
inline

◆ parse_known_args() [2/2]

auto wpi::ArgumentParser::parse_known_args ( int argc,
const char *const argv[] )
inline

◆ parse_known_args_internal()

std::vector< std::string > wpi::ArgumentParser::parse_known_args_internal ( const std::vector< std::string > & raw_arguments)
inlineprotected

◆ preprocess_arguments()

std::vector< std::string > wpi::ArgumentParser::preprocess_arguments ( const std::vector< std::string > & raw_arguments) const
inlineprotected

◆ present()

template<typename T = std::string>
auto wpi::ArgumentParser::present ( std::string_view arg_name) const -> std::optional<T>
inline

◆ print_help()

std::string wpi::ArgumentParser::print_help ( ) const
inline

◆ set_assign_chars()

ArgumentParser & wpi::ArgumentParser::set_assign_chars ( std::string assign_chars)
inline

◆ set_prefix_chars()

ArgumentParser & wpi::ArgumentParser::set_prefix_chars ( std::string prefix_chars)
inline

◆ set_suppress()

void wpi::ArgumentParser::set_suppress ( bool suppress)
inline

◆ set_usage_break_on_mutex()

ArgumentParser & wpi::ArgumentParser::set_usage_break_on_mutex ( )
inline

◆ set_usage_max_line_width()

ArgumentParser & wpi::ArgumentParser::set_usage_max_line_width ( size_t w)
inline

◆ usage()

auto wpi::ArgumentParser::usage ( ) const -> std::string
inline

Friends And Related Symbol Documentation

◆ operator<<

auto operator<< ( std::ostream & stream,
const ArgumentParser & parser ) -> std::ostream &
friend

Member Data Documentation

◆ m_argument_map

std::map<std::string, argument_it> wpi::ArgumentParser::m_argument_map
protected

◆ m_assign_chars

std::string wpi::ArgumentParser::m_assign_chars {"="}
protected

◆ m_description

std::string wpi::ArgumentParser::m_description
protected

◆ m_epilog

std::string wpi::ArgumentParser::m_epilog
protected

◆ m_exit_on_default_arguments

bool wpi::ArgumentParser::m_exit_on_default_arguments = true
protected

◆ m_group_names

std::vector<std::string> wpi::ArgumentParser::m_group_names
protected

◆ m_is_parsed

bool wpi::ArgumentParser::m_is_parsed = false
protected

◆ m_mutually_exclusive_groups

std::vector<MutuallyExclusiveGroup> wpi::ArgumentParser::m_mutually_exclusive_groups
protected

◆ m_optional_arguments

std::list<Argument> wpi::ArgumentParser::m_optional_arguments
protected

◆ m_parser_path

std::string wpi::ArgumentParser::m_parser_path
protected

◆ m_positional_arguments

std::list<Argument> wpi::ArgumentParser::m_positional_arguments
protected

◆ m_prefix_chars

std::string wpi::ArgumentParser::m_prefix_chars {"-"}
protected

◆ m_program_name

std::string wpi::ArgumentParser::m_program_name
protected

◆ m_subparser_map

std::map<std::string, argument_parser_it> wpi::ArgumentParser::m_subparser_map
protected

◆ m_subparser_used

std::map<std::string, bool> wpi::ArgumentParser::m_subparser_used
protected

◆ m_subparsers

std::list<std::reference_wrapper<ArgumentParser> > wpi::ArgumentParser::m_subparsers
protected

◆ m_suppress

bool wpi::ArgumentParser::m_suppress = false
protected

◆ m_usage_break_on_mutex

bool wpi::ArgumentParser::m_usage_break_on_mutex = false
protected

◆ m_usage_max_line_width

std::size_t wpi::ArgumentParser::m_usage_max_line_width = (std::numeric_limits<std::size_t>::max)()
protected

◆ m_usage_newline_counter

int wpi::ArgumentParser::m_usage_newline_counter = 0
protected

◆ m_version

std::string wpi::ArgumentParser::m_version
protected

The documentation for this class was generated from the following file: