bux API Reference 1.9.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
bux::C_EZArgs Class Reference

#include <EZArgs.h>

Public Member Functions

 C_EZArgs (const std::string &description={})
 
 C_EZArgs (const C_EZArgs &)=delete
 
C_EZArgsoperator= (const C_EZArgs &)=delete
 
C_EZArgsadd_flag (std::string_view name, char short_name, std::string_view description, std::invocable<> auto &&trigger, std::invocable< std::string_view > auto &&parse)
 
C_EZArgsadd_flag (std::string_view name, char short_name, std::string_view description, std::invocable<> auto &&trigger)
 
C_EZArgsadd_flag (std::string_view name, char short_name, std::string_view description, std::invocable< std::string_view > auto &&parse)
 
C_EZArgsadd_flag (std::string_view name, std::string_view description, std::invocable<> auto trigger, std::invocable< std::string_view > auto &&parse)
 
C_EZArgsadd_flag (std::string_view name, std::string_view description, std::invocable<> auto &&trigger)
 
C_EZArgsadd_flag (std::string_view name, std::string_view description, std::invocable< std::string_view > auto &&parse)
 
C_EZArgsadd_flag (char short_name, std::string_view description, std::invocable<> auto &&trigger, std::invocable< std::string_view > auto &&parse)
 
C_EZArgsadd_flag (char short_name, std::string_view description, std::invocable<> auto &&trigger)
 
C_EZArgsadd_flag (char short_name, std::string_view description, std::invocable< std::string_view > auto &&parse)
 
C_EZArgsadd_subcommand (const std::string &name, std::invocable<> auto onParsed, const std::string &description={})
 
void details (std::string_view s)
 
C_EZArgsposition_args (const std::ranges::forward_range auto &arg_names, const std::ranges::forward_range auto &count_optionals, bool unlimited=false)
 
C_EZArgsposition_args (const std::ranges::forward_range auto &arg_names, bool unlimited=false)
 
C_ErrorOrIndex parse (std::integral auto argc, const char *const argv[]) const
 
auto parsed_position_argc () const
 

Detailed Description

  1. C_EZArgs is an argument parser which lays out either subcommands or positional arguments, but not both.
  2. Every subcommand is again an argument parser, and hence follows rule 1.
  3. Rules about flags:
    1. Flags (-x, –xxx) always come after all subcommands and positional arguments. (This one may be loosen in the future)
    2. Flag with value may be given as either –flag=value or –flag value
    3. Adding a flag with both trigger and parse callbacks means the flag has an optional value.
  4. The 9 add_flag() overloaded methods facilitate defining new flags without any optional arguments:
    1. It is ok to call without either name or short_name, but not both;
    2. It is ok to call without either trigger or parse, but not both;
    3. Always call with description
  5. Behaviour of adding duplicate subcommands or flags of the same name is undefined.
Examples
parsergen/ParserGen/GrammarStrip.cpp, parsergen/ParserGen/main.cpp, parsergen/ScannerGen/main.cpp, test/smoke_ezargs.cpp, and test/test_ezargs.cpp.

Definition at line 37 of file EZArgs.h.

Constructor & Destructor Documentation

◆ C_EZArgs() [1/2]

bux::C_EZArgs::C_EZArgs ( const std::string & description = {})
inlineexplicit

Definition at line 54 of file EZArgs.h.

◆ C_EZArgs() [2/2]

bux::C_EZArgs::C_EZArgs ( const C_EZArgs & )
delete

Member Function Documentation

◆ add_flag() [1/9]

C_EZArgs & bux::C_EZArgs::add_flag ( char short_name,
std::string_view description,
std::invocable< std::string_view > auto && parse )
inline

Definition at line 116 of file EZArgs.h.

References parse().

◆ add_flag() [2/9]

C_EZArgs & bux::C_EZArgs::add_flag ( char short_name,
std::string_view description,
std::invocable<> auto && trigger )
inline

Definition at line 110 of file EZArgs.h.

◆ add_flag() [3/9]

C_EZArgs & bux::C_EZArgs::add_flag ( char short_name,
std::string_view description,
std::invocable<> auto && trigger,
std::invocable< std::string_view > auto && parse )
inline

Definition at line 101 of file EZArgs.h.

References parse().

◆ add_flag() [4/9]

C_EZArgs & bux::C_EZArgs::add_flag ( std::string_view name,
char short_name,
std::string_view description,
std::invocable< std::string_view > auto && parse )
inline

Definition at line 74 of file EZArgs.h.

References parse().

◆ add_flag() [5/9]

C_EZArgs & bux::C_EZArgs::add_flag ( std::string_view name,
char short_name,
std::string_view description,
std::invocable<> auto && trigger )
inline

Definition at line 68 of file EZArgs.h.

◆ add_flag() [6/9]

C_EZArgs & bux::C_EZArgs::add_flag ( std::string_view name,
char short_name,
std::string_view description,
std::invocable<> auto && trigger,
std::invocable< std::string_view > auto && parse )
inline
Examples
test/test_ezargs.cpp.

Definition at line 59 of file EZArgs.h.

References parse().

◆ add_flag() [7/9]

C_EZArgs & bux::C_EZArgs::add_flag ( std::string_view name,
std::string_view description,
std::invocable< std::string_view > auto && parse )
inline

Definition at line 95 of file EZArgs.h.

References parse().

◆ add_flag() [8/9]

C_EZArgs & bux::C_EZArgs::add_flag ( std::string_view name,
std::string_view description,
std::invocable<> auto && trigger )
inline

Definition at line 89 of file EZArgs.h.

◆ add_flag() [9/9]

C_EZArgs & bux::C_EZArgs::add_flag ( std::string_view name,
std::string_view description,
std::invocable<> auto trigger,
std::invocable< std::string_view > auto && parse )
inline

Definition at line 80 of file EZArgs.h.

References parse().

◆ add_subcommand()

C_EZArgs & bux::C_EZArgs::add_subcommand ( const std::string & name,
std::invocable<> auto onParsed,
const std::string & description = {} )
Parameters
[in]nameThe verb
[in]onParsedCalled when the flag is fiven without value
[in]descriptionDecribe the subcommand
Exceptions
std::runtime_errorif position_args() has been called.
Returns
The newly constructed subcommand as a C_EZArgs instance
Examples
test/test_ezargs.cpp.

Definition at line 193 of file EZArgs.h.

References RUNTIME_ERROR.

◆ details()

void bux::C_EZArgs::details ( std::string_view s)
inline

Definition at line 124 of file EZArgs.h.

◆ operator=()

C_EZArgs & bux::C_EZArgs::operator= ( const C_EZArgs & )
delete

◆ parse()

C_ErrorOrIndex bux::C_EZArgs::parse ( std::integral auto argc,
const char *const argv[] ) const
nodiscard
Parameters
[in]argcTypically the same argc from main(int argc, char *argv[])
[in]argvTypically the same argv from main(int argc, char *argv[])
Returns
On success, the returned value can be implicitly cast to true; otherwise, call message() method to get help or error message.
Postcondition
Call parsed_position_argc() to get number of positional arguments including argv[0] and subcommand(s)
Examples
parsergen/ParserGen/GrammarStrip.cpp, parsergen/ParserGen/main.cpp, parsergen/ScannerGen/main.cpp, test/smoke_ezargs.cpp, and test/test_ezargs.cpp.

Definition at line 264 of file EZArgs.h.

Referenced by add_flag(), add_flag(), add_flag(), add_flag(), add_flag(), and add_flag().

Here is the caller graph for this function:

◆ parsed_position_argc()

auto bux::C_EZArgs::parsed_position_argc ( ) const
inline
Examples
test/test_ezargs.cpp.

Definition at line 133 of file EZArgs.h.

◆ position_args() [1/2]

C_EZArgs & bux::C_EZArgs::position_args ( const std::ranges::forward_range auto & arg_names,
bool unlimited = false )
inline

Definition at line 128 of file EZArgs.h.

References position_args().

◆ position_args() [2/2]

C_EZArgs & bux::C_EZArgs::position_args ( const std::ranges::forward_range auto & arg_names,
const std::ranges::forward_range auto & count_optionals,
bool unlimited = false )
Parameters
[in]arg_namesArgument display names and the implied maximal count of positional arguments when unlimited is false.
[in]count_optionalsValid argument counts, automatically extended with all intergers greater than max(count_optionals) when unlimited is true.
[in]unlimitedIf count of positional arguments grater than max(count_optionals) is valid.
Exceptions
std::runtime_errorif add_subcommand() has been called.
Returns
*this

Together with another overload, only arg_names is mandatory. When only arg_names is provided, exactly std::size(arg_names) postional arguments are expected.

Examples
parsergen/ParserGen/GrammarStrip.cpp, parsergen/ParserGen/main.cpp, parsergen/ScannerGen/main.cpp, and test/test_ezargs.cpp.

Definition at line 220 of file EZArgs.h.

References RUNTIME_ERROR.

Referenced by position_args().

Here is the caller graph for this function:

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