Cli Utils contains a set of static methods/helpers that are CLI related (forming options, censoring args, etc.)

export

### Hierarchy

- CliUtils

## Index

### Properties

- CENSORED_OPTIONS
- CENSOR_RESPONSE

### Methods

- buildBaseArgs
- censorCLIArgs
- censorYargsArguments
- extractArrayFromEnvValue
- extractEnvForOptions
- formatHelpHeader
- generateDeprecatedMessage
- getDashFormOfOption
- getEnvValForOption
- getOptValuesFromConfig
- getOptionFormat
- getPositionalSyntaxString
- mergeArguments
- readPrompt
- setOptionValue
- showMsgWhenDeprecated
- sleep

## Properties

### Static CENSORED_OPTIONS

CENSORED_OPTIONS: string[] = ["auth", "p", "pass", "password", "passphrase", "credentials","authentication", "basic-auth", "basicAuth"]

- Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:45

A list of cli options/keywords that should normally be censored

static
memberof

  CliUtils

deprecated

  Use Censor.CENSORED_OPTIONS

### Static Readonly CENSOR_RESPONSE

CENSOR_RESPONSE: "****" = "****"

- Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:37

Used as the place holder when censoring arguments in messages/command output

static
memberof

  CliUtils

deprecated

  Use Censor.CENSOR_RESPONSE

## Methods

### Static buildBaseArgs

- buildBaseArgs(args: Arguments): ICommandArguments

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:542

  Accepts the yargs argument object and constructs the base imperative argument object. The objects are identical to maintain compatibility with existing CLIs and plugins, but the intent is to eventually phase out having CLIs import anything from Yargs (types, etc).

  #### Parameters

  - ##### args: Arguments

    Yargs argument object

  #### Returns ICommandArguments

  - Imperative argument object

### Static censorCLIArgs

- censorCLIArgs(args: string[]): string[]

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:71

  Copy and censor any sensitive CLI arguments before logging/printing

  deprecated

    Use Censor.censorCLIArgs

  #### Parameters

  - ##### args: string[]

    The args list to censor

  #### Returns string[]

### Static censorYargsArguments

- censorYargsArguments(args: Arguments): Arguments

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:93

  Copy and censor a yargs argument object before logging

  deprecated

    Use Censor.censorYargsArguments

  #### Parameters

  - ##### args: Arguments

    the args to censor

  #### Returns Arguments

  a censored copy of the arguments

### Static extractArrayFromEnvValue

- extractArrayFromEnvValue(envValue: string): string[]

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:282

  Convert an array of strings provided as an environment variable

  #### Parameters

  - ##### envValue: string

    String form of the array

  #### Returns string[]

  String[] based on environment variable

### Static extractEnvForOptions

- extractEnvForOptions(envPrefix: string, options: Array<ICommandOptionDefinition | ICommandPositionalDefinition>): ICommandArguments["args"]

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:224

  Accepts the full set of command options and extracts their values from environment variables that are set.

  #### Parameters

  - ##### envPrefix: string

  - ##### options: Array<ICommandOptionDefinition | ICommandPositionalDefinition>

    the full set of options specified on the command definition. Includes both the option definitions and the positional definitions.

  #### Returns ICommandArguments["args"]

  - the argument style object with both camel and kebab case keys for each option specified in environment variables.

### Static formatHelpHeader

- formatHelpHeader(header: string, indent?: string, color: string): string

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:367

  Format the help header - normally used in help generation etc.

  static
  memberof

    CliUtils

  #### Parameters

  - ##### header: string

  - ##### Default value indent: string = " "

  - ##### color: string

  #### Returns string

### Static generateDeprecatedMessage

- generateDeprecatedMessage(cmdDefinition: ICommandDefinition, showWarning?: boolean): string

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:379

  #### Parameters

  - ##### cmdDefinition: ICommandDefinition

  - ##### Optional showWarning: boolean

  #### Returns string

### Static getDashFormOfOption

- getDashFormOfOption(optionName: string): string

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:54

  Get the 'dash form' of an option as it would appear in a user's command, appending the proper number of dashes depending on the length of the option name

  #### Parameters

  - ##### optionName: string

    e.g. my-option

  #### Returns string

  - e.g. --my-option

### Static getEnvValForOption

- getEnvValForOption(envPrefix: string, cmdOption: string): string | null

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:328

  Get the value of an environment variable associated with the specified option name. The environment variable name will be formed by concatenating an environment name prefix, and the cmdOption using underscore as the delimiter.

  The cmdOption name can be specified in camelCase or in kabab-style. Regardless of the style, it will be converted to upper case. We replace dashes in Kabab-style values with underscores. We replace each uppercase character in a camelCase value with underscore and that character.

  The envPrefix will be used exactly as specified.

  Example: The values myEnv-Prefix and someOptionName would retrieve the value of an environment variable named myEnv-Prefix_SOME_OPTION_NAME

  memberof

    CliUtils

  #### Parameters

  - ##### envPrefix: string

    The prefix for environment variables for this CLI. Our caller can use the value obtained by ImperativeConfig.instance.envVariablePrefix, which will use the envVariablePrefix from the Imperative config object, and will use the rootCommandName as a fallback value.

  - ##### cmdOption: string

    The name of the option in either camelCase or kabab-style.

  #### Returns string | null

  - The value of the environment variable which corresponds to the supplied option for the supplied command. If no such environment variable exists we return null.

### Static getOptValuesFromConfig

- getOptValuesFromConfig(config: Config, profileDef: ICommandProfile, args: ICommandArguments, options: Array<ICommandOptionDefinition | ICommandPositionalDefinition>): any

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:125

  Searches properties in team configuration and attempts to match the option names supplied with profile keys.

  memberof

    CliUtils

  #### Parameters

  - ##### config: Config

    Team config API

  - ##### profileDef: ICommandProfile

    Profile definition of invoked command

  - ##### args: ICommandArguments

    Arguments from command line and environment

  - ##### options: Array<ICommandOptionDefinition | ICommandPositionalDefinition>

    the full set of command options for the command being processed

  #### Returns any

### Static getOptionFormat

- getOptionFormat(key: string): IOptionFormat

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:603

  Takes a key and converts it to both camelCase and kebab-case.

  example
    Conversion of keys

    CliUtils.getOptionFormat("helloWorld");

    // returns const return1 = { key: "helloWorld", camelCase: "helloWorld", kebabCase: "hello-world" }

    /////////////////////////////////////////////////////

    CliUtils.getOptionFormat("hello-world");

    // returns const return2 = { key: "hello-world", camelCase: "helloWorld", kebabCase: "hello-world" }

    /////////////////////////////////////////////////////

    CliUtils.getOptionFormat("hello--------world");

    // returns const return3 = { key: "hello--------world", camelCase: "helloWorld", kebabCase: "hello-world" }

    /////////////////////////////////////////////////////

    CliUtils.getOptionFormat("hello-World-");

    // returns const return4 = { key: "hello-World-", camelCase: "helloWorld", kebabCase: "hello-world" }

  #### Parameters

  - ##### key: string

    The key to transform

  #### Returns IOptionFormat

  An object that contains the new format.

### Static getPositionalSyntaxString

- getPositionalSyntaxString(positionalRequired: boolean, positionalName: string): string

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:352

  Constructs the yargs style positional argument string.

  static
  memberof

    CliUtils

  #### Parameters

  - ##### positionalRequired: boolean

    Indicates that this positional is required

  - ##### positionalName: string

    The name of the positional

  #### Returns string

  - The yargs style positional argument string (e.g. );

### Static mergeArguments

- mergeArguments(...args: any[]): any

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:206

  Using Object.assign(), merges objects in the order they appear in call. Object.assign() copies and overwrites existing properties in the target object, meaning property precedence is least to most (left to right).

  See details on Object.assign() for nuance.

  #### Parameters

  - ##### Rest ...args: any[]

    variadic set of objects to be merged

  #### Returns any

  - the merged object

### Static readPrompt

- readPrompt(message: string, opts?: IPromptOptions): Promise<string | null>

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:497

  Prompt the user with a question and wait for an answer, but only up to the specified timeout.

  example

         const answer = await CliUtils.readPrompt("Type your answer here: ");
         if (answer === null) {
             // abort the operation that you wanted to perform
         } else {
             // use answer in some operation
         }

  #### Parameters

  - ##### message: string

    The text with which we will prompt the user.

  - ##### Optional opts: IPromptOptions

  #### Returns Promise<string | null>

  A string containing the user's answer, or null if we timeout.

### Static setOptionValue

- setOptionValue(optName: string, optAliases: string[], value: any): ICommandArguments["args"]

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:438

  Accepts an option name, and array of option aliases, and their value and returns the arguments style object.

  example
    Create Argument Object

    CliUtils.setOptionValue("my-option", ["mo", "o"], "value");

    // returns { "myOption": "value", "my-option": "value", "mo": "value", "o": "value" }

  #### Parameters

  - ##### optName: string

    The command option name, usually in kebab case (or a single word)

  - ##### optAliases: string[]

    An array of alias names for this option

  - ##### value: any

    The value to assign to the argument

  #### Returns ICommandArguments["args"]

  - The argument style object

### Static showMsgWhenDeprecated

- showMsgWhenDeprecated(handlerParms: IHandlerParameters): void

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:401

  Display a message when the command is deprecated.

  static
  memberof

    CliUtils

  #### Parameters

  - ##### handlerParms: IHandlerParameters

    the IHandlerParameters supplied to a command handler's process() function.

  #### Returns void

### Static sleep

- sleep(timeInMs: number): Promise<unknown>

- - Defined in @zowe/imperative/src/utilities/src/CliUtils.ts:464

  Sleep for the specified number of miliseconds.

  example

         // create a synchronous delay as follows:
         await CliUtils.sleep(3000);

  #### Parameters

  - ##### timeInMs: number

    Number of miliseconds to sleep

  #### Returns Promise<unknown>

Generated using TypeDoc