The base class for all CLI commands.

Property Summary

Public Properties
public final

An array of aliases for the command

public final

An array of anonymous options for the command

public final

An array of available options for the command

public final

The description of what this command does.

public final
public final

The name of the command.

public final

Does this command work everywhere or just inside or outside of projects.

Method Summary

Public Methods
public
assignAlias(option, alias): Boolean
public
assignOption(option, parsedOptions, commandOptions): Boolean

Assigns option

public
beforeRun( ): Promise | Null

Hook for extending a command before it is run in the cli.run command. Most common use case would be to extend availableOptions.

public
getJson(options): Object
public

Reports if the given command has a command line option by a given name

public

Merges any options with duplicate keys in the availableOptions array. Used primarily by registerOptions.

public

Normalizes option, filling in implicit values

public
onInterrupt( ): Promise | Undefined

Called when command is interrupted from outside, e.g. ctrl+C or process kill Can be used to cleanup artifacts produced by command and control process exit code

public
parseAlias(option, alias): Object

Parses alias for an option and adds it to optionsAliases

public
parseArgs(commandArgs): Object | Null

Parses command arguments and processes

public

Prints basic help for the command.

public

Prints detailed help for the command.

public
registerOptions(options)

Registers options with command. This method provides the ability to extend or override command options. Expects an object containing anonymousOptions or availableOptions, which it will then merge with existing availableOptions before building the optionsAliases which are used to define shorthands.

public
run(commandArgs)
public

Validates alias value

public
public

Validates option

Private Methods
private
runTask(name, options): Promise

Looks up for the task and runs It also keeps the reference for the current active task Keeping reference for the current task allows to cleanup task on interruption

Public Properties

lib/models/command.js:100

public final aliases: Array

An array of aliases for the command

Example:

['g'] for the generate command

lib/models/command.js:137

public final anonymousOptions: Array

An array of anonymous options for the command

Example:

anonymousOptions: [
  '<blueprint>'
],
lib/models/command.js:117

public final availableOptions: Array

An array of available options for the command

Example:

availableOptions: [
  { name: 'dry-run',    type: Boolean, default: false, aliases: ['d'] },
  { name: 'verbose',    type: Boolean, default: false, aliases: ['v'] },
  { name: 'blueprint',  type: String,  default: 'app', aliases: ['b'] },
  { name: 'skip-npm',   type: Boolean, default: false, aliases: ['sn'] },
  { name: 'skip-git',   type: Boolean, default: false, aliases: ['sg'] },
  { name: 'directory',  type: String ,                 aliases: ['dir'] }
],
lib/models/command.js:51

public final description: String

The description of what this command does.

lib/models/command.js:81

public final isWithinProject: Boolean

lib/models/command.js:88

public final name: String

The name of the command.

Example:

new or generate

lib/models/command.js:60

public final works: String

Does this command work everywhere or just inside or outside of projects.

Possible values:

  • insideProject
  • outsideProject
  • everywhere

Public Methods

lib/models/command.js:482

public assignAlias(option, alias): Boolean

Parameters:

Name Type Attribute Description
option Object
alias Object

Return:

lib/models/command.js:378

public assignOption(option, parsedOptions, commandOptions): Boolean

Assigns option

Parameters:

Name Type Attribute Description
option Object
parsedOptions Object
commandOptions Object

Return:

lib/models/command.js:247

public beforeRun( ): Promise | Null

Hook for extending a command before it is run in the cli.run command. Most common use case would be to extend availableOptions.

Return:

Promise | Null
lib/models/command.js:636

public getJson(options): Object

Parameters:

Name Type Attribute Description
options Object

Return:

lib/models/command.js:315

public hasOption(name): Boolean

Reports if the given command has a command line option by a given name

Parameters:

Name Type Attribute Description
name String

Return:

lib/models/command.js:331

public mergeDuplicateOption(key): Object

Merges any options with duplicate keys in the availableOptions array. Used primarily by registerOptions.

Parameters:

Name Type Attribute Description
key String

Return:

lib/models/command.js:366

public normalizeOption(option): Object

Normalizes option, filling in implicit values

Parameters:

Name Type Attribute Description
option Object

Return:

lib/models/command.js:179

public onInterrupt( ): Promise | Undefined

Called when command is interrupted from outside, e.g. ctrl+C or process kill Can be used to cleanup artifacts produced by command and control process exit code

Return:

Promise | Undefined

if rejected promise then result of promise will be used as an exit code

lib/models/command.js:437

public parseAlias(option, alias): Object

Parses alias for an option and adds it to optionsAliases

Parameters:

Name Type Attribute Description
option Object
alias Object | String

Return:

lib/models/command.js:529

public parseArgs(commandArgs): Object | Null

Parses command arguments and processes

Parameters:

Name Type Attribute Description
commandArgs Object

Return:

Object | Null
lib/models/command.js:595

public printBasicHelp( )

Prints basic help for the command.

Basic help looks like this:

ember generate <blueprint> <options...>
  Generates new code from blueprints
  aliases: g
  --dry-run (Default: false)
  --verbose (Default: false)

The default implementation is designed to cover all bases but may be overridden if necessary.

lib/models/command.js:626

public printDetailedHelp( )

Prints detailed help for the command.

The default implementation is no-op and should be overridden for each command where further help text is required.

lib/models/command.js:153

public registerOptions(options)

Registers options with command. This method provides the ability to extend or override command options. Expects an object containing anonymousOptions or availableOptions, which it will then merge with existing availableOptions before building the optionsAliases which are used to define shorthands.

Parameters:

Name Type Attribute Description
options Object
lib/models/command.js:585

public run(commandArgs)

Parameters:

Name Type Attribute Description
commandArgs Object
lib/models/command.js:497

public validateAlias(alias): Boolean

Validates alias value

Parameters:

Name Type Attribute Description
alias Object

Return:

lib/models/command.js:255

public validateAndRun( ): Promise

Return:

lib/models/command.js:411

public validateOption(option): Boolean

Validates option

Parameters:

Name Type Attribute Description
option Object

Return:

Private Methods

lib/models/command.js:206

private runTask(name, options): Promise

Looks up for the task and runs It also keeps the reference for the current active task Keeping reference for the current task allows to cleanup task on interruption

Parameters:

Name Type Attribute Description
name String

Task name from the tasks registry. Should be capitalized

options Object

Return:

Promise

Task run

Throws:

Error

on attempt to run concurrent task