Home Reference Source Test Repository
import Commando from 'console-commando/src/commando.js'
public class | source

Commando

Represents a command or subcommand.

Test:

Static Method Summary

Static Public Methods
public static

setDebugLevel(level: int)

Sets the debug level for which messages will be printed.

Constructor Summary

Public Constructor
public

Create a Commando from a string, object or Commando.

Method Summary

Public Methods
public

Returns a commando with a new action added to it.

public

args(args: array, rootArgs: Immutable.Map): Commando

Returns a Command with arguments applied to it.

public

Returns a commando with a before callback set to 'before'.

public

Returns a commando with a new subcommand added to it.

public

debug()

Prints out debugging information.

public

description(description: string): Commando

Returns a new Commando with the same config and a given description.

public

get(key: string): *

Gets a property of the Commando instance.

public

Gets a sub command by name.

public

Returns the value for an applied option.

public

Returns an object with option names as keys and option values as values.

public

help()

Prints user facing command help.

public

name(name: string): Commando

Returns a new Commando with the same config and a given name.

public

option(optstring: string, description: string, defaultValue: *): Commando

Returns a commando with a new option added to it.

public

run(rootCommand: Command): boolean

Runs the command based on previously set arguments.

public

version(version: string): Commando

Returns a new Commando with the same config and a given version number.

Static Public Methods

public static setDebugLevel(level: int) source

Sets the debug level for which messages will be printed.

Params:

NameTypeAttributeDescription
level int

the debug level

See:

  • option.js

Public Constructors

public constructor(config: string | object | Commando): Commando source

Create a Commando from a string, object or Commando.

Params:

NameTypeAttributeDescription
config string | object | Commando

A name, config object or Commando.

Return:

Commando

A Commando with the fiven config.

Test:

Public Methods

public action(action: function): Commando source

Returns a commando with a new action added to it.

Params:

NameTypeAttributeDescription
action function

An action callback for this command.

Return:

Commando

A Commando with the given action.

Test:

public args(args: array, rootArgs: Immutable.Map): Commando source

Returns a Command with arguments applied to it.

Params:

NameTypeAttributeDescription
args array

Arguments array. Usually they will be process.argv.slice([2]).

rootArgs Immutable.Map
  • optional

Arguments of the root command.

Return:

Commando

The new Commando.

Test:

public before(before: Commando): Commando source

Returns a commando with a before callback set to 'before'.

Params:

NameTypeAttributeDescription
before Commando

A sub command to add to the current instance.

Return:

Commando

A Commando with the given command.

public command(command: Commando): Commando source

Returns a commando with a new subcommand added to it.

Params:

NameTypeAttributeDescription
command Commando

A sub command to add to the current instance.

Return:

Commando

A Commando with the given command.

Test:

public debug() source

Prints out debugging information.

public description(description: string): Commando source

Returns a new Commando with the same config and a given description.

Params:

NameTypeAttributeDescription
description string

A description string.

Return:

Commando

A Commando with the given description apllied to it.

public get(key: string): * source

Gets a property of the Commando instance.

Params:

NameTypeAttributeDescription
key string

The name of the property to get.

Return:

*

The value of the property.

public getCommand(name: string): Commando | undefined source

Gets a sub command by name.

Params:

NameTypeAttributeDescription
name string

The name of the desired sub command.

Return:

Commando | undefined

The requested command or undefined if not found.

Test:

public getOption(key: string): string source

Returns the value for an applied option.

Params:

NameTypeAttributeDescription
key string

the option key (short, long, or key)

Return:

string

the value for the specified option.

public getOptionsHash(): object source

Returns an object with option names as keys and option values as values.

Return:

object

the option hash.

public help() source

Prints user facing command help.

public name(name: string): Commando source

Returns a new Commando with the same config and a given name.

Params:

NameTypeAttributeDescription
name string

A name string.

Return:

Commando

A Commando with the given name apllied to it.

public option(optstring: string, description: string, defaultValue: *): Commando source

Returns a commando with a new option added to it.

Params:

NameTypeAttributeDescription
optstring string

An opstring for the new Option.

description string

A description for the new Option.

defaultValue *

A default value for the Option.

Return:

Commando

A Commando with the given option.

See:

public run(rootCommand: Command): boolean source

Runs the command based on previously set arguments.

Params:

NameTypeAttributeDescription
rootCommand Command
  • optional

The root command, if different from this.

Return:

boolean

The return value from the run.

See:

public version(version: string): Commando source

Returns a new Commando with the same config and a given version number.

Params:

NameTypeAttributeDescription
version string

A version number.

Return:

Commando

A Commando with the given version number.