Qore DebugUtil Module Reference  0.1
 All Classes Namespaces Functions Variables Groups Pages
DebugUtil::WrapperGetOpt Class Reference

class supporting argument parsing for executing programs to debug More...

Inherits GetOpt.

Public Member Functions

 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

class supporting argument parsing for executing programs to debug

When implementing a wrapper that executes a program whose name is passed on the command line, we can divide the arguments usually into 3 groups:

  • internal wrapper arguments
  • target program filename
  • 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 xxx -v -l    # the second xxx is target program name
    wrapper-prog -v -h xxx xxx          # the first xxx is target program name
    wrapper-prog -v --listen=xxx xxx    # the second xxx is target program name
    wrapper-prog -v --listen xxx xxx    # the second xxx is target program name

Member Function Documentation

DebugUtil::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 target program filename. "" is considered as special file name (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 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 }