Class Args

Summary

The Args class accepts a list of strings corresponding to the program parameter list, separates options (parameters starting with 1 or more hyphens ["-"]) from arguments (parameters) that don't start with a hyphen) and provides convenient and efficient separate handling of those options and arguments. Options may have values as in --cmd=write. If an option is duplicated, the values (if any) are kept in order. Arguments are also kept in order.

The class may also be given a set of valid option names (without the leading hyphens. If given such a set, then any options that are not in the set are flagged to standard error and program execution is halted. The class can also be given a procedure to call prior to program termination when bad options are found. Usually, this is used to display a help message.

Superclasses:
Object

Package:
util
File:
args.icn
Methods:
genArgs, genOptDefs, genOptNames, getArgs, getOpt, getOptDef, getOptDefs

Methods inherited from Object:
Type, className, clone, equals, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField, to_string

Fields:
argList, badOptions, optionMap

Source code.

Details
Constructor

Args(params, validOptions, helpMesg)

Parameters:
params
List of parametes
validOptions
Option set of valid option names
helpMesg
Optional help message procedure to be called if any invalid options are found

Accept a list of arguments and process for efficient handling

Methods:

genArgs()

Generates:
arguments

Generate the arguments (with options stripped out).


genOptDefs(option, defValue)

Parameters:
option
name of option
defValue
default value to use if option does not exist Defaults to &null
Generates:
all values given to option

Generate the value[s] of an option.


genOptNames()

Generates:
the names of all the options in alphabetic order

Generate the names of all options.


getArgs()

Returns:
list of arguments

Produce the list of arguments (with options stripped out).


getOpt(option, defValue)

Parameters:
option
name of option
defValue
default value to use if option exists, but has no value. Defaults to &null
Returns:
first value given to option
Fails:
if this option doesn't exist

Produce the value of an option.


getOptDef(option, defValue)

Parameters:
option
name of option
defValue
default value to use if option does not exist Defaults to &null
Returns:
first value given to option

Produce the value of an option.


getOptDefs(option, defValue)

Parameters:
option
name of option
defValue
default value to use if option does not exist Defaults to &null
Returns:
all values given to option as a list

Produce the value[s] of an option.


Fields:
argList

badOptions

optionMap


This page produced by UniDoc on 2021/04/15 @ 23:59:53.