Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KawkahCore

Hierarchy

  • EventEmitter
    • KawkahCore

Index

Constructors

constructor

Properties

$0

$0: string

Private _aborting

_aborting: boolean

Private _catchHandler

_catchHandler: KawkahAction

Private _completionsHandler

_completionsHandler: KawkahCompletionsHandler

Private _completionsName

_completionsName: string = "completions"

Private _events

_events: object

Type declaration

  • max: number
  • names: string[]

Private _footer

_footer: [string, "left" | "center" | "right"]

Private _header

_header: [string, "left" | "center" | "right"]

Private _helpHandler

_helpHandler: KawkahHelpHandler

Private _logHandler

_logHandler: KawkahLogHandler

Private _traceName

_traceName: string

aliases

aliases: IKawkahMap<string>

commands

examples

examples: IKawkahMap<string>

groups

middleware

middleware: KawkahMiddleware

options

package

package: object

Type declaration

result

table

table: Tablur

utils

Static defaultMaxListeners

defaultMaxListeners: number

Accessors

Private assert

  • get assert(): assert

Methods

abort

  • abort(): boolean
  • abort(abort?: boolean): void
  • Gets abort status

    Returns boolean

  • Sets abort status.

    Parameters

    • Optional abort: boolean

      bool indicating aborting/exiting.

    Returns void

Protected actionKeys

  • Gets actionable options for a command. Currently only supports default command.

    Parameters

    • Optional command: string | IKawkahCommand

      the command name or command.

    Returns any[]

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Protected argKeys

  • argKeys(command: string): string[]
  • Gets array of argument option keys.

    Parameters

    • command: string

      the command name.

    Returns string[]

buildHelp

  • buildHelp(groups: string[]): string[]
  • Builds help menu by groups, when no groups specified builds default.

    Parameters

    • groups: string[]

      the groups to build help for.

    Returns string[]

commandAliasToKey

  • commandAliasToKey(alias: string, def?: string): any
  • Command to key finds a corresponding pirmary key from alias.

    example

    .commandToKey('in') returns >> 'install'.

    Parameters

    • alias: string

      the alias to be mapped to primary command name.

    • Optional def: string

      a default value if alias is not defined.

    Returns any

Private dispatch

  • dispatch(err: Error | KawkahError): any
  • dispatch(message: string, ...args: any[]): any
  • dispatch(event: KawkahEvent, message: string, ...args: any[]): any
  • Dispatches an error.

    Parameters

    Returns any

  • Dispatches a notify event using formatted message.

    Parameters

    • message: string

      a message to be dispatch.

    • Rest ...args: any[]

      array of args for formatting the message.

    Returns any

  • Dispatches an event using formatted message.

    Parameters

    • event: KawkahEvent

      the event type to dispatch.

    • message: string

      the message or error to be dispatched.

    • Rest ...args: any[]

      an array of arguments to use in formatting.

    Returns any

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

error

  • error(message: any, ...args: any[]): void
  • Dispatches an error message.

    Parameters

    • message: any

      the message to be logged.

    • Rest ...args: any[]

      optional array of arguments for formatting.

    Returns void

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

exit

  • exit(code?: number): void
  • Exits the process.

    Parameters

    • Default value code: number = 0

      the exit code if any.

    Returns void

Protected flagKeys

  • flagKeys(command: string): string[]
  • Gets array of flag option keys.

    Parameters

    • command: string

      the command name.

    Returns string[]

getCommand

  • Gets a command using it's name or alias.

    Parameters

    • name: string

      the name of the command or command alias to get.

    • Optional def: string

      a default command if fails to find primary.

    Returns IKawkahCommandInternal

getCompletions

  • Resolves completions returning matches.

    Parameters

    Returns any

getCompletionsQuery

  • Gets a completions query from env vars or generated from line.

    Parameters

    • Optional line: string | string[]

      the optional line to build query from.

    Returns IKawkahCompletionQuery

getExample

  • getExample(name: string): string
  • Gets example for default command.

    Parameters

    • name: string

      the example name to lookup.

    Returns string

getFooter

  • getFooter(): [string, "left" | "center" | "right"]
  • Gets the footer.

    Returns [string, "left" | "center" | "right"]

getGroup

getGroupNamespace

  • getGroupNamespace(name: string): object
  • Normalizes namespaces for groups.

    description

    A bit convoluted but makes it much easier for users to create groups.

    Parameters

    • name: string

      the name to lookup and normalize.

    Returns object

    • item: any
    • name: string
    • ns: string

getHeader

  • getHeader(): [string, "left" | "center" | "right"]
  • Gets the header.

    Returns [string, "left" | "center" | "right"]

getHelp

  • getHelp(groups?: string | string[]): string[]
  • Gets help if enabled.

    Parameters

    • Optional groups: string | string[]

      a group or array of group strings.

    Returns string[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getOption

  • Gets options by dot notation or lookup.

    Parameters

    • name: string

      the name, alias or command.option key.

    Returns IKawkahOptionInternal

  • Gets an option from a command options.

    Parameters

    • command: string

      the command the option belongs to if known.

    • name: string

      the name or alias of the option to get.

    Returns IKawkahOptionInternal

getTheme

getUsage

Protected groupifyChildren

Protected groupifyCommand

  • Adds command and options to help groups by scheme.

    Parameters

    Returns void

Protected groupifyCommands

  • Adds collection of commands and options to help groups by scheme.

    Parameters

    Returns void

Protected groupifyExamples

  • groupifyExamples(command: string, name: string): void
  • Groupify example.

    Parameters

    • command: string
    • name: string

      the name of the example.

    Returns void

Private handleHelp

  • handleHelp(groups?: string[]): void
  • Handles displaying help.

    Parameters

    • Optional groups: string[]

      groups to display help for.

    Returns void

Private handleLog

  • handleLog(type: any, message: any, err?: Error): void
  • Default log handler.

    Parameters

    • type: any

      the type of message to log.

    • message: any

      the message to be logged.

    • Optional err: Error

    Returns void

hasCommand

  • hasCommand(command: string): boolean
  • Checks if command exists in collection.

    Parameters

    • command: string

      the command name to check.

    Returns boolean

Protected isDuplicateFlag

  • isDuplicateFlag(command: string, name: string): boolean
  • Checks if flag name conflicts with global flag.

    Parameters

    • command: string
    • name: string

      the name of the flag option.

    Returns boolean

listGroup

  • listGroup(...names: string[]): void
  • Lists groups and their contents.

    Parameters

    • Rest ...names: string[]

      the group names to be listed.

    Returns void

listen

  • Listens for commands, parses specified args or uses process.argv.

    Parameters

    • Optional argv: string | string[]

      string or array of args.

    Returns IKawkahResult

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

log

  • Logs an empty line.

    Returns KawkahCore

  • Logs an error.

    Parameters

    • err: Error

      the error to be logged.

    Returns KawkahCore

  • Logs a message with optional formatting.

    Parameters

    • message: any

      a message to be logged.

    • Rest ...args: any[]

      rest param of arguments used in formatting.

    Returns KawkahCore

  • Logs a message by type.

    Parameters

    • type: string | KawkahEvent

      a log event type.

    • message: any

      a message to be logged.

    • Rest ...args: any[]

      rest param of arguments used in formatting.

    Returns KawkahCore

Protected mergeCommand

Protected mergeOption

name

  • name(name?: string): string
  • Gets or sets the application name overwriting generated value.

    Parameters

    • Optional name: string

      the name of the application.

    Returns string

Protected normalizeStyles

notify

  • notify(message: any, ...args: any[]): void
  • Dispatches a notification message.

    Parameters

    • message: any

      the message to be logged.

    • Rest ...args: any[]

      optional array of arguments for formatting.

    Returns void

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

ok

  • ok(message: any, ...args: any[]): void
  • Dispatches an ok message.

    Parameters

    • message: any

      the message to be logged.

    • Rest ...args: any[]

      optional array of arguments for formatting.

    Returns void

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

optionAliasToKey

  • Iterates a collection of options mapping an alias to the primary key.

    Parameters

    Returns string

parse

  • Parses arguments using specified args or uses process.argv.

    Parameters

    • Optional argv: string | string[]

      string or arguments to parse.

    Returns IKawkahResult

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

reindexArgs

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeCommand

  • removeCommand(command: string): void
  • Removes a command from the collection.

    Parameters

    • command: string

      the command to be removed.

    Returns void

removeExample

  • removeExample(name: string): void
  • Removes an example from the collection.

    Parameters

    • name: string

      the name of the example to be removed.

    Returns void

removeGroup

  • removeGroup(name: string): void
  • Removes a group from the collection.

    Parameters

    • name: string

      the name of the group to be removed.

    Returns void

removeGroupItem

  • removeGroupItem(name: string, group?: string): void
  • Removes key from a group's items or all instances of key in any group.

    Parameters

    • name: string
    • Optional group: string

      the optional group to remove key from.

    Returns void

removeGroupPurge

  • removeGroupPurge(name: string): void
  • Purges any groups by name and cleans any groups which contain key in items.

    Parameters

    • name: string

      the name of the group to be removed.

    Returns void

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

removeOption

  • removeOption(command: string, name: string): void
  • Remove an option from a command.

    Parameters

    • command: string

      the command name.

    • name: string

      the name of the option to remove.

    Returns void

resultExcludeKeys

  • resultExcludeKeys(): string[]
  • Gets array of keys used to exclude result keys leaving only option keys.

    Returns string[]

setAbout

  • setAbout(): any
  • setAbout(enabled: boolean): any
  • setAbout(name: string | string[], describe?: string): any
  • Enables about option/feature with defaults.

    Returns any

  • Enables or disables about option/feature.

    Parameters

    • enabled: boolean

      boolean enable/disables about.

    Returns any

  • Enables about feature optionally sets the option and description to be used.

    Parameters

    • name: string | string[]

      the option name for displaying command about.

    • Optional describe: string

      the option description to display in help.

    Returns any

setCatchHandler

  • setCatchHandler(fn?: string | boolean | KawkahAction, isCommand?: boolean): void
  • Sets the catch handler when no command is found.

    Parameters

    • Default value fn: string | boolean | KawkahAction = true

      the function to use for handling catch.

    • Default value isCommand: boolean = false

    Returns void

setCommand

  • Sets command using only usage tokens.

    Parameters

    • usage: string

      the usage tokens for the command.

    Returns any

  • Sets a command by configuration.

    Parameters

    • command: string

      the name of the command to be updated.

    • Optional config: IKawkahCommand

      a command configuration object.

    Returns IKawkahCommandInternal

  • Sets command by command name and usage string.

    Parameters

    • command: string

      the name of the command.

    • Optional usage: string

      the usage string.

    Returns IKawkahCommandInternal

  • Sets a value by key in command.

    Parameters

    • command: string

      the name of the command setting to be updated.

    • Optional key: KawkahCommandInternalKeys

      the key in the command object to be updated.

    • Optional val: any

      the value to be updated.

    Returns IKawkahCommandInternal

setCompletions

  • Adds tab completions to your app using all defaults.

    Returns IKawkahCommandInternal

  • Adds tab completions with defaults or disables.

    example

    .completions(false);

    Parameters

    • enabled: boolean

      enables with defaults or disables completions.

    Returns IKawkahCommandInternal

  • Adds tab completions to app with custom name.

    example

    .completions('completions');

    Parameters

    • name: string

      the name of the completions command.

    Returns IKawkahCommandInternal

  • Adds tab completions to app with name and custom handler function for generating completions.

    example

    .completions('completions', HandlerFunction);

    Parameters

    • name: string

      the name of the completions command.

    • fn: KawkahCompletionsHandler

      optional custom handler for building completions.

    Returns IKawkahCommandInternal

  • Adds tab completions to your app with named completions command, custom description, custom handler and bash script template.

    example

    Function: a custom completions handler function. Template: a custom template for generating completions script. .completions('completions', 'Some description', HandlerFunction, 'Template')

    Parameters

    • name: string

      the name of the completions command.

    • describe: string

      the help description for completions.

    • Optional fn: KawkahCompletionsHandler

      optional custom handler for building completions.

    • Optional template: string

      a custom template for generating completions script.

    Returns IKawkahCommandInternal

setExample

  • setExample(name: string, text: string): void
  • Stores example text.

    Parameters

    • name: string

      the name of the example.

    • text: string

      the example text.

    Returns void

setFooter

  • setFooter(footer: string, align?: "left" | "center" | "right"): void
  • Sets the footer.

    Parameters

    • footer: string

      the footer text.

    • Optional align: "left" | "center" | "right"

    Returns void

setGroup

  • Sets a group's visibility.

    Parameters

    • name: string

      the name of the group to be set.

    • enabled: boolean

      toggles visibility for the group.

    Returns IKawkahGroup

  • Sets a group using configuration file.

    Parameters

    • name: string

      the name of the group to be set.

    • config: IKawkahGroup

      the group's configuration.

    Returns IKawkahGroup

  • Sets a group's items.

    Parameters

    • name: string

      the name of the group to be set.

    • Rest ...items: string[]

      array of items to bind to the group.

    Returns IKawkahGroup

  • Sets group by command binding options or filtered options.

    Parameters

    • name: string

      the name of the group to be set.

    • command: string
    • include: true | string[]

      true or array of option keys to include.

    Returns IKawkahGroup

setHeader

  • setHeader(header: string, align?: "left" | "center" | "right"): void
  • Sets the header.

    Parameters

    • header: string

      the header text.

    • Optional align: "left" | "center" | "right"

    Returns void

setHelp

setLogHandler

  • Sets the log handler or uses default.

    Parameters

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

setOption

  • Sets an option by usage.

    Parameters

    • command: string

      the command which contains the option.

    • usage: string

    Returns IKawkahMap<IKawkahOptionInternal>

  • Sets an option by config object..

    Parameters

    • command: string

      the command which contains the option.

    • name: string

      the name of the option to update.

    • config: IKawkahOptionInternal

      the configuration object to extend with.

    Returns IKawkahOptionInternal

  • Sets an option by using name and simple transform type.

    Parameters

    • command: string

      the command which contains the option.

    • name: string

      the name of the option to update.

    • type: string

      the transform type to create the option with.

    Returns IKawkahOptionInternal

  • Sets an option value by key.

    Parameters

    • command: string

      the command which contains the option.

    • name: string

      the name of the option to update.

    • key: KawkahOptionInternalKeys

      the key within the option to be updated.

    • val: any

      the key's value to be updated.

    Returns IKawkahOptionInternal

setTheme

setTrace

  • setTrace(option?: string | boolean): void
  • When true and --trace is present in args enabled/disable stack tracing for errors.

    Parameters

    • Optional option: string | boolean

    Returns void

setVersion

  • Sets version option with all defaults.

    Returns IKawkahOptionInternal

  • Sets version with custom version value.

    example

    .setVersion('1.2.6-alpha');

    Parameters

    • version: string

      the value to set version to.

    Returns IKawkahOptionInternal

  • Enables or disables version.

    example

    .setVersion(false);

    Parameters

    • enabled: boolean

      bool value to enable/disable version.

    Returns IKawkahOptionInternal

  • Sets version with custom option keys with description and custom version.

    Parameters

    • name: string[]

      the option keys to use for version.

    • Optional describe: string

      the description for help.

    • Optional version: string

      a custom value to set version to.

    Returns IKawkahOptionInternal

showCatch

  • showCatch(): void
  • Calls the catch handler which shows help.

    Returns void

showHelp

  • showHelp(...groups: string[]): void
  • Calls help handler if enabled.

    Parameters

    • Rest ...groups: string[]

      optional group or groups to show help for.

    Returns void

spawn

  • spawn(command: string, args?: any[], options?: SpawnOptions): ChildProcess
  • Spawns a child process.

    Parameters

    • command: string

      the command to spawn.

    • Optional args: any[]

      the arguments to apply to command.

    • Optional options: SpawnOptions

      the spawn options for the child process.

    Returns ChildProcess

spawnCommand

  • Takes a parsed result containing a command and then calls spawn.

    Parameters

    Returns ChildProcess

Protected toCommand

Protected toOption

Protected toOptionNormalize

validate

Private validateMiddleware

Protected verifyOption

warning

  • warning(message: any, ...args: any[]): void
  • Dispatches a warning message.

    Parameters

    • message: any

      the message to be logged.

    • Rest ...args: any[]

      optional array of arguments for formatting.

    Returns void

write

  • write(message?: string, wrap?: boolean): this
  • Writes message to output stream with optional wrap.

    Parameters

    • Optional message: string

      the message to be output.

    • Optional wrap: boolean

      when true message is wrapped in new lines.

    Returns this

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Object literals

symbols

symbols: object

error

error: null = null

notify

notify: null = null

ok

ok: null = null

warning

warning: null = null

Generated using TypeDoc