@versionzero/configurator / configuration-sources / CommandLineSource
Class: CommandLineSource
Defined in: configuration-sources/command-line-source.js:43
CommandLineSource - parse configuration assignments from the command line
This source converts the schema into a set of kebab-cased options, aliases, and flags. If an appName is provided in the context, and it matches a top-level property name, this is truncated for aesthetics.
- Options and aliases are specified with double hyphen (
--optionor--xy) and flags with a single hyphen (-F). - Values may be defined after the option or flag (
--option valueor-F value) or inline with an equals sign (--option=valueor-F=value). - Boolean schemas make the "true" value optional (
--debug true,--debug=true, and--debugall do the same thing, as with-D true,-D=true, or-D). - Flags may be consolidated,
-x -yis the same as-xyfor boolean flags. - If you specify an inline value for the consolidated flags, they all share the value;
--xy=falseis the same as-x false -y false. - If a flag requires an argument, it needs to be the last flag in the sequence.
Flag and alias allocation is on an opportunistic basis for "non-advanced" options based on the sequence of definition.
A schema can define flagHint metadata to request a specific flag. Otherwise, options at the "top level"
(either at the schema top level or within the appName child) are allocated a single character flag, first
checking for the availability of the lower-case flag, then the upper-case version.
Schemas at deeper hierarchy levels get allocated an alias based on the leading characters of their kebab-cased option.
This source pays special attention to schema selectors and selections; whenever a selector is defined, it establishes independent parsing contexts for each possible selection. Selections do not require a leading hyphen, and thus look like "commands".
Additional Metadata
advanced- only list with --help advancedhidden- option exists, but does not show up in --help or --help advancedgeneral- mark as a bare option without hyphen; typically used for gathering array valuesinternal- do not generate a command-line option at alldescription- help description of the propertyvalueDescription- help description of the value and its constraintsdefaultValueDescription- help description of the default value (set to empty string to suppress default)
Extends
Constructors
Constructor
new CommandLineSource(
options?):CommandLineSource
Defined in: configuration-sources/command-line-source.js:54
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | CommandLineSourceOptions | - |
Returns
CommandLineSource
Overrides
ConfigurationSource.constructor
Methods
load()
load(
schema,context,loadOptions?):Promise<Map<string,any>>
Defined in: configuration-sources/command-line-source.js:136
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | CompiledSchema | - |
context | any | - |
loadOptions? | { strict: [boolean]; } | - |
loadOptions.strict? | [boolean] | - |
Returns
Promise<Map<string, any>>
Overrides
_help()
_help(
schema,context,showAdvanced?):string
Defined in: configuration-sources/command-line-source.js:434
Generate help text based on configurator schema
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
schema | CompiledSchema | undefined | - |
context | any | undefined | collection of source-specific properties (argv, env, etc.) |
showAdvanced | boolean | false | Whether to show advanced options |
Returns
string
Formatted help text