Home Manual Reference Source
import CLISubCommand from 'projext/src/abstracts/cliSubCommand.js'
public class | version 1.0 | source

CLISubCommand

A helper class for creating sub commands for the CLI. A sub command works like a CLICommand inside a regular CLICommand.

Constructor Summary

Public Constructor
public abstract

Class constructor.

Member Summary

Public Members
public

A short description for what the generator does.

public

The name of the sub command for the help interface.

public

A list with the name of the options the generator supports.

public

A dictionary of options settings by their option name.

Method Summary

Public Methods
public

addOption(name: string, instruction: string, description: string, defaultValue: string)

Add a new option for the command.

public

Generates a complete description of the sub command and its options in order to be used on the help interface of the CLICommand that implements it.

public abstract

handle()

The method called by the CLICommand that implements the sub command.

Public Constructors

public abstract constructor() source

Class constructor.

Throw:

TypeError

If instantiated directly.

Public Members

public description: string source

A short description for what the generator does.

public name: string source

The name of the sub command for the help interface.

public options: Array source

A list with the name of the options the generator supports. New options can be added using the addOption method.

public optionsByName: Object source

A dictionary of options settings by their option name. New options can be added using the addOption method.

Public Methods

public addOption(name: string, instruction: string, description: string, defaultValue: string) source

Add a new option for the command.

Params:

NameTypeAttributeDescription
name string

The option name.

instruction string

The option instruction, for example: -t, --type [type].

description string
  • optional
  • default: ''

The option description.

defaultValue string
  • optional
  • default: ''

The option default value, in case is not used on execution.

Example:

// To capture an option
this.addOption(
  'type',
  '-t, --type [type]',
  'The type of thingy you want to use?',
);

// As a simple flag
this.addOption(
  'ready',
  '-r, --ready',
  'Is it read?',
  false
);

public getHelpInformation(): string source

Generates a complete description of the sub command and its options in order to be used on the help interface of the CLICommand that implements it.

Return:

string

public abstract handle() source

The method called by the CLICommand that implements the sub command. It receives a dicitionary with the parsed options the command received.

Throw:

Error

if not overwritten.