Command-line arguments handler.
More...
#include <getopt.hxx>
Public Types |
|
typedef std::vector< std::string > | OptionValues |
typedef std::map< std::string,
OptionValues > | OptionsMap |
Public Member Functions |
| | Getopt (int argc, char *const *argv, const char *documentation="Usage: %c [options]") |
| | Constructor.
|
| void | add (const char *longOpt, char shortOpt, int argument, const char *description="", const char *argDescription="") |
| | Define an option.
|
| void | get () |
| | Process options from the command-line.
|
|
std::string | usage () |
| | Get usage string.
|
| std::string | operator[] (std::string opt) const |
| | Get the value of a command-line option If the switch was given multiple times, only return the last value.
|
| int | getCount (std::string opt) const |
| | Get the number of times a command-line switch was given.
|
| const OptionValues & | getAll (std::string opt) const |
| | Get all provided values for a command-line option.
|
| std::string | shift () |
| | Shift remaining positional arguments.
|
|
int | argc () const |
| | Get number of remaining positional arguments.
|
|
char const *const * | argv () const |
| | Get remaining positional arguments.
|
|
std::string | argv (int i) const |
| | Get remaining positional arguments.
|
Detailed Description
Command-line arguments handler.
opt.add ("help", 'h', 0, "Show this help");
if (opt["help"] != "") {
std::cout << opt.usage();
}
Constructor & Destructor Documentation
| Getopt::Getopt |
( |
int |
argc, |
|
|
char *const * |
argv, |
|
|
const char * |
documentation = "Usage: %c [options]" |
|
) |
| |
Constructor.
- Parameters
-
| argc | number of command-line arguments |
| argv | command-line arguments |
| arguments | description of non-switch command-line arguments |
Member Function Documentation
| void Getopt::add |
( |
const char * |
longOpt, |
|
|
char |
shortOpt, |
|
|
int |
argument, |
|
|
const char * |
description = "", |
|
|
const char * |
argDescription = "" |
|
) |
| |
Define an option.
- Parameters
-
| longOpt | long option name |
| shortOpt | short option switch |
| argument | 0 (none), 1 (required), 2 (optional) |
| description | long description of the option |
| argDescription | argument description if applicable |
Process options from the command-line.
This method must be called after all calls to 'add'.
| const Getopt::OptionValues & Getopt::getAll |
( |
std::string |
opt | ) |
const |
|
inline |
Get all provided values for a command-line option.
- Returns
- a vector of values
| int Getopt::getCount |
( |
std::string |
opt | ) |
const |
|
inline |
Get the number of times a command-line switch was given.
- Returns
- count
| std::string Getopt::operator[] |
( |
std::string |
opt | ) |
const |
|
inline |
Get the value of a command-line option If the switch was given multiple times, only return the last value.
- Returns
- "" if the switch is unset
| std::string Getopt::shift |
( |
| ) |
|
|
inline |
Shift remaining positional arguments.
- Returns
- the first remaining positional argument, "" if there are no more positional args
The documentation for this class was generated from the following files:
- /home/francois/projets/git/clang-tags/src/getopt++/getopt.hxx
- /home/francois/projets/git/clang-tags/src/getopt++/getopt.cxx