cmdr::parameter - Cmdr - (Partially internal) Command parameters
Welcome to the Cmdr project, written by Andreas Kupries.
For availability please read Cmdr - How To Get The Sources.
This package implements parameters, collections of which (see cmdr::config) serve as the configuration of privates (see cmdr::private).
The class API is not public. It is used internally by the framework when parsing a command hierarchy specification to create the necessary parameter instances.
It is described here for use by developers maintaining, modifying and extending the framework itself. A user of the framework has no need for it.
Create an auto-named instance of cmdr::parameter.
Not used.
Create a new instance of cmdr::parameter, named obj. Used by the DSL processing parts of the framework to instantiate parameters.
The (command) name of the new parameter instance.
The instance command of the cmdr::config instance holding the parameter.
Flag. Parameter is specified by order (true: argument), or name (false: option).
Flag. Parameter is visible on the command line (true: option, or argument), or not (false: state).
Flag. Parameter is must be specified by the user at runtime (true), or not (false).
Flag. The internal representation is computed on-demand (true), or in the completion phase (false).
Internal name of the parameter. Also the name used in the help, if not overridden by a label declaration (in spec).
Human-readable help text for the parameter.
Tcl-script specifying the parameter in detail. Please read Cmdr - Parameter Specification Language for the details.
Most of the instance API is not public.
It is described here for use by developers maintaining, modifying and extending the framework itself. A user of the framework has no need for it.
This method validates the string value x against the validation type of the parameter and returns a boolean value indicating success (true), or not (false). The internal representation of x is not kept but released immediately. The parameter itself is not changed either. This is used during runtime by the 'test'-based processing of optional arguments.
This accessor method returns the "cmdline" flag set during parameter construction. A result of true indicates that the parameter is visible on the command line (option, or argument), and otherwise (false) hidden (state).
This method returns a string encoding the flags "required" and "list". The mapping is as follows:
required, scalar
optional, scalar
required, list
optional, list.
This method is part of the main shell command line completion. For the details of its workings please read Cmdr - Internals of command line completion.
Given the completion state parse of a partial command line it returns a list of strings which are the valid completions at this point, for the parameter.
A dictionary holding the current completion state of a partial command line.
This method either returns the cmdr::config instance containing the parameter, or the result of applying the words to that config instance. It is through this method that any script with access to a single parameter instance of a private will have access to all its parameters.
The method and its arguments to apply to the config instance holding the parameter. If none are specified the method self is implied, causing the return of the config instance itself.
This method returns the default value set by the parameter's specification, or the empty string.
This accessor method returns the "defered" flag set during parameter construction. A result of true indicates that the parameter's internal representation is computed on-demand, and otherwise (false) during the completion phase.
This method returns the parameter's help text. If the detail is specified and the name of an automatic option controlled by this parameter its implicit description is returned instead of the description of its primary.
Optional. The name of a automatic option controlled by the parameter.
This accessor method returns the "documented" flag of the parameter. A value of true indicates that the parameter should be included in generated help, otherwise not.
This method disables interactive entry of the parameter's value for one time. I.e. after the information was used (see method value) the flag automatically resets. The result of the method is the empty string.
This method returns the text of the primary flag of the parameter, including leading dashes.
This method releases the internal representation of the parameter's value, if it has any. See also method reset for a stronger form.
This method returns the "generate" command prefix callback, if it was set, and an empty list otherwise.
This method returns a boolean flag indicating if the parameter's specification declared a default value for it (true), or not (false).
This method returns the help information for the parameter. Note that this method does not check the "documented" flag of the parameter. That is the responsibility of the caller. The result of the command is a structure of the form described in section Help Information.
This method returns the "interactive" flag of the parameter. A result of true indicates that the parameter's string representation has to be queried interactively if no value was specified at runtime.
This method interactively queries the string representation of the parameter from the user. If no prompt is specified the parameter's prompt from the specification is used. See also method prompt. The interaction takes the "list"-ness of the parameter into account. Note that the entered string(s) is/are validated and invalid information is rejected.
Optional. The prompt to use for the interaction.
This method returns a boolean value indicating if the parameter uses the standard validation type "boolean" (true) or not (false). The parts of the parameter responsible for processing option arguments use this information to invoke the hard-wired special cases for this type, or not.
This method returns a boolean value indicating if the parameter is of the specified type (true) or not (false).
The type to check the parameter against. Recognized values are
This method returns the human-readable name of the parameter, for use in help. If not specifically overridden by the parameter's specification this is the same as the internal name (See method name).
This accessor method returns the "list" flag of the parameter. A value of true indicates that the parameter's value is a list, otherwise a scalar.
This accessor method returns the string set by method lock below, or the empty string if lock was not used. Note: This information is reset by method reset, but not by forget.
This method locks the parameter against modification by the methods set and setq, and remembers the reason for it. The reason is expected to be the name of another parameter whose use disallows the use of this one. Note: Such a lock is reset by method reset, but not by forget.
The name of the parameter locking this one against further modification.
This method returns the internal name of the parameter.
This method returns the state of the non-promotion flag of the parameter.
This method returns the list of option flags recognized by the parameter.
This accessor method returns the "order" flag set during parameter construction. A result of true indicates that the parameter is specified by order at runtime (argument), and otherwise (false) by name (option).
This method returns a boolean value indicating if the option parameter is set as presence-option (true) or not (false). The parts of the parameter responsible for processing option arguments use this information to invoke the hard-wired special cases for presence, or not.
This method returns a boolean value indicating if the named option is the primary option of this parameter (true), or not (false). An error will be thrown if the named option is not controlled by the parameter.
The name of the option to check.
This method extracts the value of the parameter from the command line. A presence option takes nothing, whereas an isbool option takes the first value in the queue, if it is a proper boolean, and defaults to true if not. Any other argument or option takes the first value in queue.
The name of the parameter, or the option flag referencing it.
The queue instance holding the words of the command line not yet processed by the system.
This method returns the prompt string used by the parameter for interactive entry. If not overridden by the parameter's specification this defaults to a string derived from the internal name of the parameter, i.e. "Enter name:".
This accessor method returns the "required" flag set during parameter construction. A result of true indicates that the parameter must be specified by the user at runtime, and otherwise may be left unspecified (false).
This method sets the parameter into the initial state where it has neither string nor internal representation, nor is it locked. This is a stronger form of forget.
This method returns the parameter instance itself.
This accessor method returns a boolean value indicating if the parameter was given a string representation at runtime (true), or not (false).
This method sets the first element of the queue as the value of the parameter. For a "list" parameter all elements of the queue are taken as the new value of the parameter. This is not quite analogous to method set below. They behave the same for scalar parameters, and differ for "list" parameters.
The queue instance holding the words of the command line not yet processed.
This method sets the value as the new string representation of the parameter. For a "list" parameter the string representation is extended with the value. This action triggers the execution of the "when-set" callback. A previously existing internal representation is forgotten (See forget).
The new value of the parameter, or an extension of the existing value.
This accessor method returns the string representation of the parameter. If such was not set an error will be thrown (See method undefined!).
This method specifies the minimum number of words needed after the optional argument parameter for it to accept the current word for itself. Parameters which are not optional arguments ignore this method. The result of the method is the empty string.
The acceptance threshold for the parameter.
This method returns the threshold set on the parameter. An empty string indicates a parameter without threshold. A value of -1 indicates that the optional argument accepts based on validation (See method accept) instead of using a threshold.
This accessor method returns the type of the parameter, one of argument, option, or state. See also method is for type-checking.
This method explicitly throws a "parameter undefined" error for this parameter.
This method returns the "validate" command prefix callback (i.e. the parameter's validation type).
This accessor method returns the internal representation of the parameter. If necessary the data is computed from the parameter's string representation, "default" value, or "generate" callback. An error is thrown if the value could not be determined. (See method undefined!). If the value is newly computed the action triggers the execution of the "when-complete" callback.
A parameter asked for its internal representation goes through the following steps to deliver the value:
If the internal representation is already known, simply deliver it as is. In other words, the result of the following steps is cached, and the steps are run only once.
If the internal representation has been declared as undefined already, simply error out (again). This is still part of caching the result generated by the following steps.
If the parameter has a string representation use the parameter's validation type to convert it to the proper internal representation, and return it.
If interactive entry is possible (per the parameter's specification) perform the interaction. This saves the entered data as string representation which is then validated as per the previous step. Aborting the interaction leaves the parameter as undefined (which is thrown as error).
If a generate callback exists use it to obtain the internal representation, and return it.
If a default value exists make it the internal representation, and return it.
Side note: As the parameter DSL only allows the declaration of one of default or generate only one of these steps can trigger.
If the parameter is optional use the empty string as the internal representation and return it.
Note that this rule should never trigger as the parameter DSL enforces that optional parameters always have one of default or generate.
Leave the parameter is undefined and fail (throw an error).
This method returns the "when-complete" command prefix callback, if it was set, and an empty list otherwise.
This method returns the "when-set" command prefix callback, if it was set, and an empty list otherwise.
The help information generated for parameters is a dictionary containing the keys below:
Output of method cmdline.
Output of method code.
Output of method default.
Output of method defered.
Output of method description.
Output of method documented.
A dictionary mapping flag names to flag types, i.e. primary, alias, or inverted.
Output of method generator.
Output of method interactive.
Output of method isbool.
Output of method label.
Output of method list.
Output of method ordered.
Output of method presence.
Output of method prompt.
Output of method required.
Output of method threshold.
Output of method type.
Output of method validator.
Both the package(s) and this documentation will undoubtedly contain bugs and other problems. Please report such at Cmdr Tickets.
Please also report any ideas you may have for enhancements of either package(s) and/or documentation.
arguments, command hierarchy, command line completion, command line handling, command tree, editing command line, help for command line, hierarchy of commands, interactive command shell, optional arguments, options, parameters, processing command line, tree of commands
Copyright © 2013-2016 Andreas Kupries
Copyright © 2013-2016 Documentation, Andreas Kupries