Qore DebugCmdLine Module Reference 0.1.2
Loading...
Searching...
No Matches
DebugCmdLine::WrapperGetOpt Class Reference

#include <DebugCmdLine.qm.dox.h>

Inherits GetOpt.

Public Member Methods

 constructor (hash options)
 create the object with the given GetOpt option hash
 
 split (list< string > args, reference< list< string > > wrp_args, reference< *string > pgm_name, reference< list< string > > pgm_args)
 Parses input arguments until a standalone argument is found. More...
 

Detailed Description

When implementing a wrapper which executes program whose name is passed at command line then we can divide arguments usually into 3 groups, internal wrapper arguments, target program filename and program arguments. The class support argument parsing for such a case.

Examples: ( # GetOpt options 'help': 'h,help', 'verbose': 'v,verbose', 'listen': 'l,listen=s@', ); wrapper-prog -v -l xxx trg -v -l # trg is the target program name wrapper-prog -v -h trg xxx # trg is the target program name wrapper-prog -v –listen=xxx trg # trg is the target program name wrapper-prog -v –listen xxx trg # trg is the target program name

Member Function Documentation

◆ split()

DebugCmdLine::WrapperGetOpt::split ( list< string >  args,
reference< list< string > >  wrp_args,
reference< *string >  pgm_name,
reference< list< string > >  pgm_args 
)

Parses input arguments until a standalone argument is found.

Parameters
argsList of arguments passed to wrapper, typically ARGV
wrp_argsreturns list of wrapper arguments
pgm_namereturns the target program filename; "" is considered a special file name (meaning stdin), NOTHING when no name provided
pgm_argsreturn List of target program arguments
Example:
hash opts = (
'help': 'h,help',
'verbose': 'v,verbose',
'listen': 'l,listen=s@',
);
WrapperGetOpt g(opts);
list dargs;
hash opt;
*string fileName;
g.split(ARGV, \dargs, \fileName, \ARGV);
try {
opt = g.parse2(\dargs);
} catch (hash<ExceptionInfo> ex) {
stderr.printf("%s: %s\n", ex.err, ex.desc);
help(-1);
}
if (exists fileName) {
stderr.print("No input file\n");
exit(-1);
}