Skip to content
Snippets Groups Projects
Commit 42065158 authored by David Flitney's avatar David Flitney
Browse files

*** empty log message ***

parent f551f2b1
No related branches found
No related tags found
No related merge requests found
......@@ -40,38 +40,65 @@ ostream& operator<<(ostream &os, const BaseOption& o) {
void OptionParser::usage()
{
cerr << "Usage: " << endl << "\t" << progname_ << " " << example_ << endl;
cerr << endl << "Compulsory arguments:" << endl;
cerr << endl << progname_ << endl << endl;
cerr << "Usage: " << endl << example_ << endl;
for(Options::iterator option = options_.begin(); option != options_.end();
option++)
{
if((*option)->compulsory())
if((*option)->compulsory()) {
static bool banner = true;
if(banner) {
cerr << endl << "Compulsory arguments (You MUST set one or more of):" << endl;
banner = false;
}
cerr << **option << endl;
}
}
cerr << endl << "Optional arguments:" << endl;
for(Options::iterator option = options_.begin(); option != options_.end();
option++)
{
if(!(*option)->compulsory())
if(!(*option)->compulsory()) {
static bool banner = true;
if(banner) {
cerr << endl << "Optional arguments (You may optionally specify one or more of):" << endl;
banner = false;
}
cerr << **option << endl;
}
}
cerr << endl;
cerr << endl;
}
// BaseOption * OptionParser::operator[](const string& key)
// {
// OptionMap::iterator option = options_.find(key);
// if(option != options_.end())
// return option->second;
// else // An unknown option!
// return NULL;
// }
bool OptionParser::check_compulsory_arguments(bool verbose)
{
bool okay = true;
for(Options::iterator option = options_.begin();
option != options_.end();
option++) {
if((*option)->compulsory() && (*option)->unset()) {
if(okay) {
if(verbose) {
cerr << "***************************************************" << endl;
cerr << "The following COMPULSORY options have not been set:" << endl;
}
okay = false;
}
if(verbose)
cerr << **option << endl;
}
}
if(!okay && verbose)
cerr << "***************************************************" << endl;
return okay;
}
unsigned int OptionParser::parse_command_line(unsigned int argc,
char **argv)
......@@ -123,28 +150,6 @@ unsigned int OptionParser::parse_command_line(unsigned int argc,
}
argcount += increments;
}
// Now check that any compulsory options
// have been set
for(Options::iterator option = options_.begin();
option != options_.end();
option++) {
static bool banner = true;
if((*option)->compulsory() && (*option)->unset()) {
if(banner) {
cerr << "***************************************************" << endl;
cerr << "The following COMPULSORY options have not been set!" << endl;
banner = false;
usage_needed = true;
}
cerr << **option << endl;
}
}
if(usage_needed) {
cerr << "***************************************************" << endl;
usage();
exit(-1);
}
return argcount; // User should process any remaining args
}
......@@ -177,11 +182,11 @@ int main(unsigned int argc, char **argv) {
OptionParser options("options",
"-d <number> --mask <filename> --res <filename>");
options.add(&verbose);
options.add(&help);
options.add(&dof);
options.add(&mask);
options.add(&resid);
options.add(verbose);
options.add(help);
options.add(dof);
options.add(mask);
options.add(resid);
for(unsigned int a = options.parse_command_line(argc, argv); a < argc; a++)
cout << argv[a] << endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment