|
Boost : |
From: Petr Ovchenkov (ptr_at_[hidden])
Date: 2001-11-19 04:31:23
Ok.
Now I have following args parser (I print only usage sample):
...
int main( int argc, char * const * argv )
{
using namespace std;
string fname;
bool turn;
try {
Argv arg;
arg.copyright( "Copyright (C) SomeNiceCompany Ltd., 2001" );
arg.brief( "VRML 1.0 Monoshape Splitter" );
arg.option( "-h", false, "print this help message" );
arg.option( "-f", string(""), "process VRML 1.0 file" );
arg.option( "-p", false, "Use preprocessed files" );
try {
arg.parse( argc, argv );
}
catch ( invalid_argument& err ) {
cerr << err.what() << endl;
arg.print_help( cerr );
throw 1;
}
if ( arg.assign( "-h", turn ) ) {
arg.print_help( cerr );
throw 0;
}
arg.assign( "-f", fname );
arg.assign( "-p", turn );
if ( fname.length() == 0 ) {
arg.print_help( cerr );
throw 0;
}
}
catch ( int r ) {
return r;
}
....
}
This parser process only command line options.
IMO, parser for configuration file (<xml> or not) and command line
parser are different parsers.
For command line parser the improvement will be
Argv arg( Argv::use_some_options_style );
...
arg.option( "h", false, "print this help message" );
...
with usage
cmd --help
or
cmd -h
or
cmd /H
in dependence of enum Argv::use_some_options_style.
- ptr
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk