mglib

Personal IDL library for M. Galloy

single page | use frames     summary     class     fields     routine details     file attributes

dist_tools/

mg_options__define.pro


An 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
or:
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

Other file information

Requires:

IDL 6.2

Uses:

MGcoHashTable

Class description for mg_opt

Properties

Properties in mg_opt

boolean get init
default init
help init
help_header get
key_column_width get
long_name get init
metavar get init
short_name get set

Class description for mg_options

Properties

Properties in mg_options

app_name init
version init

Routines

Routines from mg_options__define.pro

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, nparamsRange

Add a range of positional parameters.

mg_options::cleanup

Free resources.

result = mg_options::init( [app_name=string] [, version=string])

Create option parsing object.

mg_options__define

Define instance variables.

Routine details

top 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 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 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 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

top mg_options::cleanup

mg_options::cleanup

Free resources.

top mg_options::init

result = mg_options::init( [app_name=string] [, version=string])

Create option parsing object.

Return value

1 for success, 0 for failure

Keywords

app_name in optional type=string

application name

version in optional type=string

version of the application

top mg_options__define

mg_options__define

Define instance variables.

File attributes

Modification date: Wed May 14 15:07:14 2014
Lines: 293
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.