Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KawkahCommandBase<T>

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

Properties

Protected _name

_name: string

core

Accessors

Protected _command

Protected assert

  • get assert(): assert

Protected utils

Methods

Protected _option

  • Creates option flag or option arg.

    NOTE: if tokens are passed the name is parsed in this case --user.name will be seen as user with alias name when not using tokens e.g. user.name it is seen as a named config for a nested property.

    Parameters

    • name: string

      the flag/arg name or tokens.

    • describe: string | IKawkahOption

      the description or config object.

    • type: KawkahOptionType

      the option's type.

    • def: any

      the option's default value.

    • Optional argOrAction: boolean | KawkahResultAction

    Returns T & KawkahCommandBase<T>

abort

  • When true injects -- abort arg resulting in all arguments being added to result.__

    Parameters

    • Default value enabled: boolean = true

      enables/disables abort for command.

    Returns T & KawkahCommandBase<T>

about

  • Creates long description about the command.

    Parameters

    • text: string

      the text to be displayed about the command.

    Returns T & KawkahCommandBase<T>

action

  • Binds an action to be called when parsed command or alias is matched.

    example

    .action((result, context) => { do something });

    example

    .action((arg1..., result, context) => { do something }); (spread enabled)

    Parameters

    Returns T & KawkahCommandBase<T>

alias

  • Adds alias to command.

    Parameters

    • Rest ...alias: string[]

      string or array of string aliases.

    Returns T & KawkahCommandBase<T>

aliasFor

  • Adds alias(s) option by key.

    Parameters

    • name: string

      the option key name.

    • Rest ...alias: string[]

      the aliases to be added.

    Returns T & KawkahCommandBase<T>

arg

  • Adds an argument by parsable tokens.

    Parameters

    • tokens: string

      the token to be parsed as an argument.

    Returns T & KawkahCommandBase<T>

  • Adds an argument to command using config object.

    Parameters

    • name: string

      the name of the argument to create.

    • config: IKawkahOption

      the option configuration object.

    Returns T & KawkahCommandBase<T>

  • Adds an argument to the command.

    Parameters

    • name: string

      the argument name.

    • describe: string

      the description for the argument.

    • Optional type: KawkahOptionType

      the argument's type.

    • Optional def: any

      a default value.

    Returns T & KawkahCommandBase<T>

args

  • Adds multiple args to command from a string of arguments.

    @ .args(' [directory] [other]');

    Parameters

    • arg: string

    Returns T & KawkahCommandBase<T>

  • Adds multiple args to command from an array.

    @ .args('', '[directory]', ...);

    Parameters

    • Rest ...args: string[]

      array of args to add for command.

    Returns T & KawkahCommandBase<T>

arrayFor

  • Assigns option keys as type of array.

    Parameters

    • Rest ...names: string[]

      the option keys to assign.

    Returns T & KawkahCommandBase<T>

booleanFor

  • Assigns option keys as type of boolean.

    Parameters

    • Rest ...names: string[]

      the option keys to assign.

    Returns T & KawkahCommandBase<T>

coerceFor

completionsFor

  • Sets custom completions for the specified option.

    example

    .completions('theme', 'light', 'dark', 'contrast');

    Parameters

    • name: string

      the option key name.

    • Rest ...completions: string[]

      array of completion values.

    Returns T & KawkahCommandBase<T>

context

contextFor

  • Gets a configuration for a flag or arg option on this command.

    Parameters

    • name: string

      the name of the flag or arg option.

    Returns IKawkahOptionInternal

defaultFor

  • Sets a default value for the specified option.

    example

    .default('theme', 'dark');

    Parameters

    • name: string

      the option key name.

    • def: any

      a default value.

    Returns T & KawkahCommandBase<T>

demandFor

  • Sets demands for the specified option.

    example

    .demand('username', 'password', ...);

    Parameters

    • name: string

      the option key name.

    • Rest ...demand: string[]

      rest array of keys to demand.

    Returns T & KawkahCommandBase<T>

  • Sets demands when matches handler criteria

    example

    .demand('username', ['password', 'email'], function validator(v) { return true });

    Parameters

    • name: string

      the option key name.

    • demand: string[]

      array of keys to demand.

    • handler: RegExp | KawkahValidateHandler

      handler that returns if should demand keys.

    Returns T & KawkahCommandBase<T>

  • Sets demands when matches handler criteria

    example

    .demand('username', ['password', 'email'], 1, function validator(v) { return true });

    Parameters

    • name: string

      the option key name.

    • demand: string[]

      array of keys to demand.

    • match: number

      indicates how many keys should be demanded, 0 for all.

    • handler: RegExp | KawkahValidateHandler

      handler that returns if should demand keys.

    Returns T & KawkahCommandBase<T>

denyFor

  • Sets deny for the specified option.

    example

    .deny('username', 'password', ...);

    Parameters

    • name: string

      the option key name.

    • Rest ...deny: string[]

      rest array of keys to deny.

    Returns T & KawkahCommandBase<T>

  • Sets deny when matches handler criteria

    example

    .demand('username', ['password', 'email'], function validator(v) { return true });

    Parameters

    • name: string

      the option key name.

    • deny: string[]

      array of keys to deny.

    • handler: RegExp | KawkahValidateHandler

      handler that returns if should deny keys.

    Returns T & KawkahCommandBase<T>

  • Sets deny when matches handler criteria

    example

    .deny('username', ['password', 'email'], 1, function validator(v) { return true });

    Parameters

    • name: string

      the option key name.

    • deny: string[]

      array of keys to deny.

    • match: number

      indicates how many keys should be denied, 0 for all.

    • handler: RegExp | KawkahValidateHandler

      handler that returns if should deny keys.

    Returns T & KawkahCommandBase<T>

describe

  • Adds or updates the command's description.

    Parameters

    • describe: string

      the command description.

    Returns T & KawkahCommandBase<T>

describeFor

  • Sets a description for the specified option.

    Parameters

    • name: string

      the option key name.

    • describe: string

      the option's description

    Returns T & KawkahCommandBase<T>

example

  • Creates example for command.

    example

    kawkah.example('My global example'); kawkah.command('mycommand').example('My command specific example');

    Parameters

    • text: string

      the example text.

    Returns T & KawkahCommandBase<T>

  • Creates example using namespace.

    example

    kawkah.example('commandName.exampleName', 'My example'); kawkah.example('anyName.exampleName', 'My example');

    Parameters

    • name: string

      assign namespace to example.

    • text: string

      the example text.

    Returns T & KawkahCommandBase<T>

exec

  • Executes a command's action handler manually.

    Parameters

    • Optional result: IKawkahResult

      a parsed result to pass to command action.

    Returns any

extendFor

  • Loads a config at the parsed path specified in arguments.

    Parameters

    • option: string

      the name of the option key.

    Returns T & KawkahCommandBase<T>

  • Gets specific keys from loaded config.

    example

    .extendFor('conf', ['name', 'version', 'author']);

    Parameters

    • option: string

      the name of the option key.

    • Rest ...keys: string[]

      specific keys to get on load.

    Returns T & KawkahCommandBase<T>

  • Extends result with this static object at this option.

    example

    .extendFor('conf', { // some object });

    Parameters

    • option: string

      the name of the option key.

    • obj: object

      a static object to be extended to result.

    Returns T & KawkahCommandBase<T>

external

  • Sets command as an external command using existing command name.

    Returns T & KawkahCommandBase<T>

  • Sets command in path as an external command.

    example

    .external('ls');

    Parameters

    • command: string

      an external command to assign this command to.

    Returns T & KawkahCommandBase<T>

  • Sets command using existing command name as an external command with spawn options.

    Parameters

    • options: SpawnOptions

      spawn options to use when spawning command.

    Returns T & KawkahCommandBase<T>

  • Sets command as an external command using specified command in path with options.

    Parameters

    • command: string

      an external command in path to assign this command to.

    • options: SpawnOptions

      spawn options to use when spawning command.

    Returns T & KawkahCommandBase<T>

flag

  • Adds a flag by parsable tokens.

    Parameters

    • tokens: string

      the token to be parsed as flag option.

    Returns T & KawkahCommandBase<T>

  • Adds a flag to command using config object.

    Parameters

    • name: string

      the name of the option to create.

    • config: IKawkahOption

      the option configuration object.

    Returns T & KawkahCommandBase<T>

  • Adds a flag to the command.

    Parameters

    • name: string

      the name of the option.

    • describe: string

      the description for the option.

    Returns T & KawkahCommandBase<T>

  • Adds a flag to the command.

    Parameters

    • name: string

      the name of the option.

    • describe: string

      the description for the option.

    • action: KawkahResultAction

      an action to call on flag option. (Default Command ONlY)

    Returns T & KawkahCommandBase<T>

  • Adds a flag to the command.

    Parameters

    • name: string

      the name of the option.

    • describe: string

      the description for the option.

    • type: KawkahOptionType

      the option's type.

    • Optional action: KawkahResultAction

      an action to call on flag option. (Default Command ONlY)

    Returns T & KawkahCommandBase<T>

  • Adds a flag to the command.

    Parameters

    • name: string

      the name of the option.

    • describe: string

      the description for the option.

    • type: KawkahOptionType

      the option's type.

    • Optional def: any

      a default value.

    • Optional action: KawkahResultAction

      an action to call on flag option. (Default Command ONlY)

    Returns T & KawkahCommandBase<T>

flags

  • Adds multiple args to command from an array.

    @ .flags('force', 'status', ...); .flags('--tags [string]', '--age [number]');

    Parameters

    • Rest ...flags: string[]

    Returns T & KawkahCommandBase<T>

help

  • Enables help for this command using defaults.

    example

    .commandHelp();

    Returns T & KawkahCommandBase<T>

  • Enables command help by specifying custom help text overrides child help.

    example

    .commandHelp('my custom help text.');

    Parameters

    • text: string

      a custom help string to display for this command.

    Returns T & KawkahCommandBase<T>

  • Enables or disables command help overrides child help.

    example

    .help(false);

    Parameters

    • enabled: boolean

      enables/disables help for this option.

    Returns T & KawkahCommandBase<T>

  • Enables help by specifying custom help text, optionally sets help for option. Passes the current command and instance, overrides child help.

    example

    .help((cmd, instance) => { return 'my custom help text.' }));

    Parameters

    Returns T & KawkahCommandBase<T>

helpFor

  • Enables help by specifying custom help text.

    example

    .help('my_key', my custom help text.');

    Parameters

    • name: string

      the option key to bind to.

    • text: string

      a custom help string to display for this option.

    Returns T & KawkahCommandBase<T>

  • Enables or disables help for the specifed option.

    example

    .help('my_key', false);

    Parameters

    • name: string

      the option key to bind to.

    • enabled: boolean

      enables/disables help for this option.

    Returns T & KawkahCommandBase<T>

  • Enables help by specifying custom help text, optionally sets help for option.

    example

    .help('my_key', () => { return 'my custom help text.' }));

    Parameters

    • name: string

      the option key to bind to.

    • fn: KawkahHandler

      synchronous function for generating help.

    Returns T & KawkahCommandBase<T>

maxArgs

  • maxArgs(count: number): this
  • The maximum args allowed for the command.

    example

    .maxArgs(2);

    Parameters

    • count: number

      the count number.

    Returns this

maxFlags

  • maxFlags(count: number): this
  • The maximum flags allowed for the command.

    example

    .maxFlags(2);

    Parameters

    • count: number

      the count number.

    Returns this

minArgs

  • minArgs(count: number): this
  • The minimum args allowed for the command.

    example

    .minArgs(2);

    Parameters

    • count: number

      the count number.

    Returns this

minFlags

  • minFlags(count: number): this
  • The minimum flags allowed for the command.

    example

    .minFlags(2);

    Parameters

    • count: number

      the count number.

    Returns this

numberFor

  • Assigns option keys as type of number.

    Parameters

    • Rest ...names: string[]

      the option keys to assign.

    Returns T & KawkahCommandBase<T>

options

  • Adds multiple options using map of key and KawkahOption objects. To specify an argument option set "index" to -1.

    @ .options({ name: { type: 'string' } }); .options({ path: { type: 'string', index: true } });

    Parameters

    Returns T & KawkahCommandBase<T>

requiredFor

  • Sets specified option as required.

    example

    .required('password', true);

    Parameters

    • name: string

      the option key name.

    • Default value required: boolean = true

      enable/disable required option.

    Returns T & KawkahCommandBase<T>

skip

skipFor

  • Sets validation skip for the specified option.

    example

    .skip('theme', true);

    Parameters

    • name: string

      the option key name.

    Returns T & KawkahCommandBase<T>

  • Sets validation skip for the specified option.

    example

    .skip('theme', true);

    Parameters

    • name: string

      the option key name.

    • skip: boolean

      enable/disable skip.

    Returns T & KawkahCommandBase<T>

spread

  • Toggles spreading action args in positional order, missing args are null.

    @ { _: ['file', 'dir', null ]} >> .action(file, dir, null, result) {}

    Parameters

    • Default value spread: boolean = true

      bool value indicating if should spread args.

    Returns T & KawkahCommandBase<T>

stringFor

  • Assigns option keys as type of string.

    Parameters

    • Rest ...names: string[]

      the option keys to assign.

    Returns T & KawkahCommandBase<T>

typeFor

validateFor

  • Sets validation for option using RegExp.

    example

    .validate('value', /^value$/);

    Parameters

    • name: string

      the option key name.

    • exp: RegExp

      regular expression to validate with.

    Returns T & KawkahCommandBase<T>

  • Sets validation for option using config object.

    example

    .validate('value', { message: 'error message', handler: RegExp or Function });

    Parameters

    Returns T & KawkahCommandBase<T>

  • Sets validation for option using function.

    example

    .validate('value', (val) => { // return if valid } );

    Parameters

    Returns T & KawkahCommandBase<T>

variadicFor

  • Sets argument as variadic.

    example

    .variadic('tags');

    Parameters

    • name: string

      the option key name.

    Returns T & KawkahCommandBase<T>

  • Sets argument as variadic by boolean or count of args.

    example

    .variadic('tags', 2);

    Parameters

    • name: string

      the option key name.

    • value: boolean | number

      boolean or a count of args.

    Returns T & KawkahCommandBase<T>

Generated using TypeDoc