28 #include <cmdLine/cmdLineInterface.h>
31 #include <cmdLine/cmdUnlabeledValueArg.h>
32 #include <cmdLine/cmdUnlabeledMultiArg.h>
34 #include <cmdLine/cmdXorHandler.h>
35 #include <cmdLine/cmdHelpVisitor.h>
36 #include <cmdLine/cmdVersionVisitor.h>
37 #include <cmdLine/cmdIgnoreRestVisitor.h>
39 #include <cmdLine/cmdLineOutput.h>
40 #include <cmdLine/cmdStdOutput.h>
49 #include <vlutil/vlProcessControl.h>
50 #include <vlutil/vlKeyboard.h>
51 #include <vlutil/vlPrint.h>
62 class CmdLine :
public DtCmdLine::CmdLineInterface
170 CmdLine(
const std::string& name,
171 const std::string& message,
172 const std::string& version =
"none",
174 bool pressAnyKey =
true);
176 bool pressAnyKey =
false);
189 CmdLine(
const std::string& message,
190 const char delimiter =
' ',
191 const std::string& version =
"none",
193 bool pressAnyKey =
true);
195 bool pressAnyKey =
false);
207 void add( DtCmdLine::Arg& a );
213 void add( DtCmdLine::Arg* a );
221 void xorAdd( DtCmdLine::Arg& a, DtCmdLine::Arg& b );
228 void xorAdd( std::vector<DtCmdLine::Arg*>& xors );
235 void parse(
int argc,
char** argv,
bool printOnError =
true);
245 void setOutput(DtCmdLine::CmdLineOutput* co);
284 const std::string& m,
285 const std::string& v,
292 myPressAnyKey(pressAnyKey),
293 _userSetOutput(false)
300 const std::string& v,
302 : _progName(
"not_set_yet"),
307 myPressAnyKey(pressAnyKey),
308 _userSetOutput(false)
315 DtCmdLine::ArgListIterator argIter;
316 DtCmdLine::VisitorListIterator visIter;
334 _output =
new DtCmdLine::StdOutput;
336 DtCmdLine::Visitor *v;
342 "Displays usage information and exits.",
350 "Displays version information and exits.",
356 v =
new DtCmdLine::IgnoreRestVisitor();
358 DtCmdLine::Arg::ignoreNameString(),
359 "Ignores the rest of the labeled arguments following this flag.",
370 for (DtCmdLine::ArgVectorIterator it = ors.begin(); it != ors.end(); ++it)
372 (*it)->forceRequired();
373 (*it)->setRequireLabel(
"OR required" );
381 std::vector<DtCmdLine::Arg*> ors;
394 for( DtCmdLine::ArgListIterator it =
_argList.begin(); it !=
_argList.end(); ++it )
396 throw( DtCmdLine::SpecificationException(
"Argument with same flag/name already exists!",
401 if ( a->isRequired() )
412 std::vector<std::string> args;
414 for (i = 1; i < argc; i++)
415 args.push_back(argv[i]);
417 int requiredCount = 0;
419 for (i = 0; (
unsigned int)i < args.size(); i++)
421 bool matched =
false;
422 for (DtCmdLine::ArgListIterator it =
_argList.begin(); it !=
_argList.end(); ++it)
426 if(!(*it)->isIgnoreable() || !DtCmdLine::Arg::ignoreRest())
428 if ( (*it)->processArg( &i, args ) )
443 if ( !matched && !DtCmdLine::Arg::ignoreRest() )
444 throw(DtCmdLine::CmdLineParseException(
"Couldn't find match for argument",
449 throw(DtCmdLine::CmdLineParseException(
"One or more required arguments missing!"));
452 throw(DtCmdLine::CmdLineParseException(
"Too many arguments!"));
454 }
catch ( DtCmdLine::ArgException& e ) {
457 int oldNotifyLevel = DtNotifyLevel;
462 DtInfo <<
"Press any key to continue" << std::endl;
464 while (DtPollBlockingInputChar() ==
'\0')
470 DtNotifyLevel = oldNotifyLevel;
478 if ( s[0] != DtCmdLine::Arg::flagStartChar() )
481 for (
int i = 1; (
unsigned int)i < s.length(); i++ )
482 if ( s[i] != DtCmdLine::Arg::blankChar() )