util/CommandLine: make non-option args accessible

The argv list must not be temporary for this, and became a class
member.

Change-Id: I159dd2a0d43768a7926b639f93a4ff9f2bfb7c9a
This commit is contained in:
Horst Schirmeier
2013-05-02 12:21:59 +02:00
parent 950adac80e
commit d937be90ea
2 changed files with 15 additions and 12 deletions

View File

@ -22,9 +22,10 @@ namespace fail {
private:
static CommandLine m_instance;
std::vector<std::string> argv;
std::vector<const char *> argv;
std::vector<option::Descriptor> options;
option::Option *parsed_options, *parsed_buffer;
option::Parser *m_parser;
public:
/// Handle for accessing the parsed data of an option
typedef int option_handle;
@ -45,7 +46,7 @@ namespace fail {
/**
* Add a argument manually
*/
void add_args(char *value) { argv.push_back(value); }
void add_args(const char *value) { argv.push_back(value); }
/**
* Add a option to the command line interface of the fail-client
@ -89,6 +90,12 @@ namespace fail {
int columns = getenv("COLUMNS")? atoi(getenv("COLUMNS")) : 80;
option::printUsage(fwrite, stdout, options.data(), columns);
}
/**
* Return the internal option::Parser object for further usage.
*/
option::Parser *parser() {
return m_parser;
}
};
} // end of namespace