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

Option

Defines options with short and long names.

Options can also have optional or required arguments.

See:

Test:

Constructor Summary

Public Constructor
public

constructor(config: string | object, description: string, defaultValue: *): Option

Creates a new Option.

Method Summary

Public Methods
public

debug()

Prints out debugging information.

public

get(key: string): *

Gets a property of the Option instance.

public

getArgValue(args: Immutable.List): mixed

Returns the argument value for this option, according to a list of args.

Public Constructors

public constructor(config: string | object, description: string, defaultValue: *): Option source

Creates a new Option.

Option strings can have a short and long name, as well as a named argument, which can be optional or required. It's defined as a string:

-o --long-option [argumentName]

where:

  • -o represents the short name (o),
  • --long-option is the long name (long-option)
  • and [argumentName] represents an optional argument.
  • use <argumentName> for required arguments.

Params:

NameTypeAttributeDescription
config string | object

An optString or configuration object.

description string
  • optional

A description, shown in help.

defaultValue *
  • optional
  • nullable: true

A default value for this option.

Return:

Option

A new Option object.

Test:

Public Methods

public debug() source

Prints out debugging information.

public get(key: string): * source

Gets a property of the Option instance.

Params:

NameTypeAttributeDescription
key string

The name of the property to get.

Return:

*

The value of the property.

public getArgValue(args: Immutable.List): mixed source

Returns the argument value for this option, according to a list of args.

Params:

NameTypeAttributeDescription
args Immutable.List

List of arguments.

Return:

mixed (nullable: true)

The value of the argument.