Qore DebugCmdLine Module Reference  0.1.2
 All Classes Namespaces Functions Variables Groups Pages
DebugCmdLine::WrapperGetOpt Class Reference

Inherits GetOpt.

Public Member Functions

 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

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:
1 hash opts = (
2  'help': 'h,help',
3  'verbose': 'v,verbose',
4  'listen': 'l,listen=s@',
5 );
6 WrapperGetOpt g(opts);
7 list dargs;
8 hash opt;
9 *string fileName;
10 g.split(ARGV, \dargs, \fileName, \ARGV);
11 
12 try {
13  opt = g.parse2(\dargs);
14 } catch (hash<ExceptionInfo> ex) {
15  stderr.printf("%s: %s\n", ex.err, ex.desc);
16  help(-1);
17 }
18 
19 if (exists fileName) {
20  stderr.print("No input file\n");
21  exit(-1);
22 }