./
mg_options__define.pro
includes main-level programAn object to facilitate parsing of command line options.
Execute this program with something like:
  idl -IDL_QUIET 1 -quiet -e ".run mg_options__define" -args --verbose --name=Mike
  idl -IDL_QUIET 1 -quiet -e ".run mg_options__define" -args --help
Examples
Try:
  ; create options object
  opts = obj_new('mg_options', app_name='mg_options_example', version='1.0')
  ; setup options
  opts->addOption, 'verbose', 'v', $
                   /boolean, $
                   help='set to print a verbose greeting'
  opts->addOption, 'name', 'n', help='name of user to greet', default='Mike', $
                   metavar='user''s name'
  ; parse the options
  opts->parseArgs, error_message=errorMsg
  if (errorMsg ne '') then begin
    oldQuiet = !quiet
    !quiet = 0
    message, errorMsg, /informational, /noname
    !quiet = oldQuiet
  end
  if (errorMsg eq '' && ~opts->get('help') && ~opts->get('version')) then begin
    print, (opts->get('verbose') ? 'Greetings and salutations' : 'Hello'), $
           opts->get('name'), $
           format='(%"%s, %s!")'
  endif
  ; destroy the options when done
  obj_destroy, opts
Class description for mg_opt
Properties
- help init
 - short_name get set
 - boolean get init
 - metavar get init
 - key_column_width get
 - help_header get
 - default init
 - long_name get init
 
Class description for mg_options
Properties
- app_name init
 - version init
 
Other file information
- Requires:
 IDL 6.2
- Uses:
 
Routines
result = mg_options::get(optname [, /params] [, n_params=long] [, /present])Get value of option.
mg_options::parseArgs [, args] [, error_message=string]Parse arguments.
mg_options::addOption, longForm [, shortForm] [, help=string] [, default=string] [, /boolean] [, metavar=string]Add the definition of an option to the parser.
mg_options::addParams, nparamsRangeAdd a range of positional parameters.
mg_options::cleanupFree resources.
result = mg_options::init( [app_name=string] [, version=string])Create option parsing object.
mg_options__defineDefine instance variables.
Routine details
top source mg_options::get
result = mg_options::get(optname [, /params] [, n_params=long] [, /present])
Get value of option.
Return value
string
Parameters
- optname in required type=string
 long name of option
Keywords
- params in optional type=boolean
 set to return parameters
- n_params out optional type=long
 number of parameters returned, only used if PARAMS is set
- present out optional type=boolean
 set to a named variable to determine if the option was present
top source mg_options::parseArgs
mg_options::parseArgs [, args] [, error_message=string]
Parse arguments.
Parameters
- args in optional type=strarr default=command_line_args()
 string array of arguments
Keywords
- error_message out optional type=string
 set to a named variable to receive any error message generated from parsing the parameters
top source mg_options::addOption
mg_options::addOption, longForm [, shortForm] [, help=string] [, default=string] [, /boolean] [, metavar=string]
Add the definition of an option to the parser.
Parameters
- longForm in required type=string
 long name of the option, used with two dashes i.e. --help
- shortForm in optional type=string
 single character name of an option, used with a single dash i.e. -h
Keywords
- help in optional type=string
 help text for the option
- default in optional type=string
 default value
- boolean in optional type=boolean
 set to indicate the option is a boolean switch
- metavar in optional type=string
 text to display in the help for non-boolean option values
top source mg_options::addParams
mg_options::addParams, nparamsRange
Add a range of positional parameters.
Parameters
- nparamsRange in required type=lonarr(2)
 valid range for number of positional parameters, use -1 for the max value to allow an unlimited number of parameters
File attributes
| Modification date: | Mon Nov 29 18:31:29 2010 | 
| Lines: | 647 | 
| Docformat: | rst rst | 
![[attach.png]](idldoc-resources/attach.png)