Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/ts-command-line > CommandLineParameter > environmentVariable

CommandLineParameter.environmentVariable property

The name of an environment variable that the parameter value will be read from, if it was omitted from the command-line. An error will be reported if the environment value cannot be parsed.

Signature:

readonly environmentVariable: string | undefined;

Remarks

The environment variable name must consist only of upper-case letters, numbers, and underscores. It may not start with a number.

This feature cannot be used when IBaseCommandLineDefinition.required is true, because in that case the environmentVariable would never be used.

Syntax notes for environment variable values:

  • Choice Parameter: The value must match one of the defined choices, otherwise a validation error is reported. An empty string causes the environment variable to be ignored.

  • Flag Parameter: The value must be 1 for true, or 0 for false, otherwise a validation error is reported. An empty string causes the environment variable to be ignored.

  • Integer Parameter: The value must be an integer number, otherwise a validation error is reported. An empty string causes the environment variable to be ignored.

  • String Parameter: Any value is accepted, including an empty string.

  • String List Parameter: If the string starts with [ (ignoring whitespace) then it will be parsed as a JSON array, whose elements must be strings, numbers, or boolean values. If the string does not start with [, then it behaves like an ordinary String Parameter: Any value is accepted, including an empty string.