E-MailRelay
|
A class which holds a represention of the argc/argv command line array, and supports simple command-line parsing. More...
#include <garg.h>
Public Member Functions | |
Arg (int argc, char **argv) | |
Constructor taking argc/argv directly from main(). More... | |
Arg (const G::StringArray &) | |
Constructor taking an array of command-line arguments. More... | |
Arg (const std::string &full_command_line) | |
Constructor taking a full command-line. More... | |
Arg (const Path &exe, const std::string &command_line_tail) | |
Constructor taking argv0 and a command-line tail. More... | |
std::size_t | c () const |
Returns the number of tokens in the command line, including the program name. More... | |
std::string | v (std::size_t i) const |
Returns the i'th argument. More... | |
std::string | v (std::size_t i, const std::string &default_) const |
Returns the i'th argument or the default if out of range. More... | |
std::string | prefix () const |
Returns the basename of v(0) without any extension. More... | |
bool | contains (std::string_view option, std::size_t option_args=0U, bool case_sensitive=true) const |
Returns true if the command line contains the given option with enough command line arguments left to satisfy the required number of option arguments. More... | |
std::size_t | count (std::string_view option) const |
Returns the number of times the given string appears in the list of arguments. More... | |
std::size_t | index (std::string_view option, std::size_t option_args=0U, std::size_t default_=0U) const |
Returns the index of the given option. More... | |
std::size_t | match (const std::string &prefix) const |
Returns the index of the first argument that matches the given prefix. More... | |
bool | remove (std::string_view option, std::size_t option_args=0U) |
Removes the given option and its arguments. More... | |
std::string | removeValue (std::string_view option, const std::string &default_={}) |
Removes the given single-valued option and its value. More... | |
std::string | removeAt (std::size_t option_index, std::size_t option_args=0U) |
Removes the given argument and the following 'option_args' ones. More... | |
StringArray | array (unsigned int shift=0U) const |
Returns the arguments as a string array, with an optional shift. More... | |
StringArray::const_iterator | cbegin () const |
Returns a begin iterator, advanced to exclude argv0. More... | |
StringArray::const_iterator | cend () const |
Returns the end iterator. More... | |
Static Public Member Functions | |
static Arg | windows () |
Factory function for Windows using GetCommandLineW(). More... | |
static Path | v0 () |
Returns a copy of argv[0] from the first call to the argc/argv constructor overload or windows(). More... | |
static Path | exe () |
Returns Process::exe() or in exceptional circumstances an absolute path constructed from v0() and the captured cwd. More... | |
static Path | exe (std::nothrow_t) |
Returns Process::exe() or in exceptional circumstances an absolute path constructed from v0() and the captured cwd. More... | |
static const char * | prefix (char **argv) noexcept |
An exception-free version of prefix() which can be used in main() outside of the outermost try block. More... | |
A class which holds a represention of the argc/argv command line array, and supports simple command-line parsing.
A copy of argv[0] is squirrelled away and made accessible via a static method.
G::Arg::Arg | ( | int | argc, |
char ** | argv | ||
) |
|
explicit |
|
explicit |
G::Arg::Arg | ( | const Path & | exe, |
const std::string & | command_line_tail | ||
) |
G::StringArray G::Arg::array | ( | unsigned int | shift = 0U | ) | const |
std::size_t G::Arg::c | ( | ) | const |
G::StringArray::const_iterator G::Arg::cbegin | ( | ) | const |
G::StringArray::const_iterator G::Arg::cend | ( | ) | const |
bool G::Arg::contains | ( | std::string_view | option, |
std::size_t | option_args = 0U , |
||
bool | case_sensitive = true |
||
) | const |
Returns true if the command line contains the given option with enough command line arguments left to satisfy the required number of option arguments.
(By convention an option starts with a dash, but that is not required here; it's just a string that is matched against command-line arguments.)
std::size_t G::Arg::count | ( | std::string_view | option | ) | const |
|
static |
Returns Process::exe() or in exceptional circumstances an absolute path constructed from v0() and the captured cwd.
Throws on error. See also v0().
|
static |
Returns Process::exe() or in exceptional circumstances an absolute path constructed from v0() and the captured cwd.
Returns the empty path on error. See also v0().
std::size_t G::Arg::index | ( | std::string_view | option, |
std::size_t | option_args = 0U , |
||
std::size_t | default_ = 0U |
||
) | const |
std::size_t G::Arg::match | ( | const std::string & | prefix | ) | const |
std::string G::Arg::prefix | ( | ) | const |
|
staticnoexcept |
bool G::Arg::remove | ( | std::string_view | option, |
std::size_t | option_args = 0U |
||
) |
std::string G::Arg::removeAt | ( | std::size_t | option_index, |
std::size_t | option_args = 0U |
||
) |
std::string G::Arg::removeValue | ( | std::string_view | option, |
const std::string & | default_ = {} |
||
) |
std::string G::Arg::v | ( | std::size_t | i | ) | const |
std::string G::Arg::v | ( | std::size_t | i, |
const std::string & | default_ | ||
) | const |
|
static |
|
static |