Qore DebugUtil Module Reference 0.1.1
Loading...
Searching...
No Matches
DebugUtil::WrapperGetOpt Class Reference

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

#include <DebugUtil.qm.dox.h>

Inherits GetOpt.

Public Member Methods

 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

◆ split()

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:
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 ex) {
stderr.printf("%s: %s\n", ex.err, ex.desc);
help(-1);
}
if (exists fileName) {
stderr.print("No input file\n");
exit(-1);
}