Using the parseargs Procedure
Task objects and scripts that take arguments or options can call the parseargs procedure to parse arguments passed along with the object or script invocation. The
parseargs procedure is a script in a separate file which provides a convenient and reusable method for argument parsing within a dcecp script. The basic syntax is:
parseargs {parse_options local_args args}
The procedure relies on arguments passed to it by the calling script. The parseargs procedure requires the following inputs:
parse_options the argument table (arg_table) describing the parsing options. The parse_options can consist of five elements as in the script's top level argument table
or four elements as in lower-level argument tables for called procedures within a script. The two syntaxes for parse_options are:
verb command variable command_name "help string" -options type variable "help string"
verb provides top-level parsing. Typically an operation contains an object and a verb. The verb portion generally calls another procedure.
command a keyword indicating that the procedure being defined is a verb of an object.
variable the name of the variable which hold the value of the option. When parsing verbs, the variable is named function call. When parsing options, the variable is
named for the option being parsed. For example, if the option name is -alias, the variable is named alias.
command_name the procedure name to store in the variable
help string the string which describes the use of the verb or option.
-options the actual string value of the option to be parsed such as -attribute or -mypwd.
type the type of variable to be associated with -option. Acceptable types are: integer, string, float, boolean, command,
and help.
local_args the arguments to be parsed. The parseargs procedure extracts all of the recognized entries into a list and resets local_args with the values that were not
parsed (or not parsable). For instance, a top level command like user create includes options that are parsed later when the procedure implementing the create operation is invoked
within the script.
args one of two flags:
-found_one tells the parser to return when one procedure argument has been found. So in user create, the parser would return after create command had been found and
processed.
-no_leftovers looks for extra options and generates an error if one is found.
|