✨ a command line builder ✨
- What is this?
- Install
- Use
- API
Argument(info)
Command(info)
Command#action([action])
Command#addArgument(argument)
Command#addCommand(subcommand)
Command#addOption(option)
Command#alias([alias])
Command#aliases([aliases])
Command#ancestors()
Command#args
Command#argument(info[, data])
Command#arguments([infos])
Command#argv
Command#command(info[, data])
Command#commands([infos])
Command#copyInheritedSettings(parent)
Command#createArgument(info[, data])
Command#createCommand(info[, data])
Command#createOption(info[, data])
Command#default
Command#defaultCommand
Command#description([description])
Command#done([done])
Command#emit(event)
Command#emitOption(option, value, source[, flags])
Command#error(info)
Command#exit([e])
Command#exiter([exit])
Command#findCommand(x)
Command#findOption(flag[, direction])
Command#hidden
Command#hide([hidden])
Command#id([name])
Command#logger
Command#on<T>(event, listener[, options])
Command#option(info[, data])
Command#optionValue(key[, value][, source])
Command#optionValueSource(key[, source])
Command#options([infos])
Command#opts<T>()
Command#optsWithGlobals<T>()
Command#parent
Command#parse([argv][, options])
Command#parseAsync([argv][, options])
Command#process
Command#snapshot()
Command#summary([summary])
Command#toString()
Command#unknown
Command#unknowns(strategy)
Command#usage([usage])
Command#version([version])
CommandError(info)
KronkError(info)
KronkEvent(id)
Option(info)
Option#boolean
Option#choices([choices])
Option#default([info])
Option#description([description])
Option#env([env])
Option#event
Option#flags
Option#hidden
Option#hide([hidden])
Option#id
Option#key
Option#long
Option#mandatory
Option#optional
Option#parser([parser])
Option#preset([preset])
Option#required
Option#short
Option#toString()
Option#variadic
OptionEvent<T>(option, value, source[, flag])
VersionOption(info)
- Types
Action
ArgumentData
ArgumentInfo
ArgumentMetadata
ArgumentSyntaxMap
ArgumentSyntax
ArgumentsData
ArgvSourceMap
ArgvSource
Awaitable
CommandData
CommandErrorInfo
CommandErrorSnapshot
CommandInfo
CommandMetadata
CommandName
CommandSnapshot
DefaultInfo
EmptyString
ExitCode
ExitProcess
Exit
Flags
KronkErrorCause
KronkErrorId
KronkErrorInfo
KronkErrorJson
KronkErrorMap
KronkEventListener
KronkEventNameMap
List
OptionData
OptionEventListener
OptionEventNameMap
OptionEventName
OptionInfo
OptionMetadata
OptionPriority
OptionValueSourceMap
OptionValueSource
OptionValueSources
OptionsData
ParseArg
ParseOptions
ProcessEnv
Process
RawOptionValue
SubcommandInfo
SubcommandsData
SubcommandsInfo
UnknownStrategy
UsageData
UsageInfo
VersionData
VersionOptionInfo
Version
- Contribute
kronk
is a utility for building command-line applications in node.js and bun.
This package is ESM only.
With yarn:
yarn add @flex-development/kronk
See Git - Protocols | Yarn for info regarding installing from Git.
With bun:
bun add @flex-development/kronk
See bun add
for more details.
TODO: use
kronk exports a global program
object convenient for quick programs.
This is used in the examples throughout this README
for brevity.
import { program } from '@flex-development/kronk'
For larger programs using kronk in multiple ways, including unit testing, a Command
should be created.
import { Command } from '@flex-development/kronk'
const program: Command = new Command()
Options are defined with the .option()
and .options()
methods,
which also serve as documentation for the options. Each option can have at most 2 flags, typically one long flag and one
short or shortish (e.g. --ws
) flag. Flags can be separated by commas (,
), pipes (|
), or spaces (
).
An option and its option-argument can be separated by an equal sign (=
) or spaces (
).
A short option (i.e. -p
) and its option-argument can also be combined.
serve --port 80
serve --port=80
serve -p 80
serve -p80
serve -p=80
Options on the command line are not positional, and can be specified before or after command-arguments.
serve --port=80 ./server.mts
serve ./src/main.mts -p8080
If a non-option (i.e. -13
) looks like an option because it starts with a hyphen (-
), a delimiter (--
) can be used
to demarcate the command-argument from an option.
clamp -M3 -m-1 -- -13
Parsed options can be accessed by calling .opts<T>()
on a Command
object, and are
passed to the command's action
handler.
Multi-word options such as --template-engine
are camelCased, becoming program.opts().templateEngine
, or can be
configured to be converted using snake_case, becoming program.opts().template_engine
.
There are additional, related routines for when .opts<T>()
is not enough:
A command argument (class).
constructor(info: ArgumentInfo | string)
constructor(info: string, data?: ArgumentData | null | undefined)
info
(ArgumentInfo
|string
) — argument info or syntaxdata?
(ArgumentData
, optional) — additional argument info
string
The argument syntax id.
boolean
Whether the argument must have a value after parsing.
The normalized argument syntax string.
Get or set argument choices.
choices(): Set<string>
choices(choices: List<string> | null | undefined): this
choices
(List<string>
, optional) — list of argument choices
(Set<string>
| this
) List of argument choices or this
argument
Get or set the default value configuration.
default<T>(): DefaultInfo<T>
default(info: DefaultInfo | null | undefined): this
T
(any
) — default value type
info
(DefaultInfo
, optional) — default value info
(DefaultInfo<T>
| this
) Default value info or this
argument
Get or set the argument description.
Pass null
, undefined
, or an empty string to remove the argument from the auto-generated help text.
description(): string
description(description: URL | string | null | undefined): this
description
(URL | string
, optional) — the argument description
(string
| this
) Description of this
argument or this
argument
Get or set the handler used to parse command-arguments.
parser<T, V extends string | string[] = string | string[]>(): ParseArg<T, V>
parser(parser: ParseArg<any, any> | null | undefined): this
T
(any
) — parse resultV
(string | string[]
, optional) — the argument or arguments to parse
parser
(ParseArg<any, any>
|null
|undefined
) — the command-argument parser
(ParseArg<T, V>
| this
) The command-argument parser or this
argument
Get the human readable equivalent of the argument.
(string
) String representation of this
argument
boolean
Whether the argument can be specified multiple times.
A command (class).
constructor(info: CommandInfo | string)
constructor(info: string, data?: CommandData | null | undefined)
info
(CommandInfo
|string
) — command info or namedata?
(CommandData
, optional) — additional command info
TODO: Command#action([action])
TODO: Command#addArgument(argument)
TODO: Command#addCommand(subcommand)
TODO: Command#addOption(option)
TODO: Command#alias([alias])
TODO: Command#aliases([aliases])
TODO: Command#ancestors()
any[]
Parsed command-line arguments.
TODO: Command#argument(info[, data])
TODO: Command#arguments([infos])
string[]
Raw command-line arguments.
TODO: Command#command(info[, data])
TODO: Command#commands([infos])
TODO: Command#copyInheritedSettings(parent)
TODO: Command#createArgument(info[, data])
TODO: Command#createCommand(info[, data])
TODO: Command#createOption(info[, data])
boolean
Whether the command is the default subcommand of its parent
.
Command
| null
| undefined
The default command.
TODO: Command#description([description])
TODO: Command#done([done])
TODO: Command#emit(event)
TODO: Command#emitOption(option, value, source[, flags])
TODO: Command#error(info)
TODO: Command#exit([e])
TODO: Command#exiter([exit])
TODO: Command#findCommand(x)
TODO: Command#findOption(flag[, direction])
Command#hidden
boolean
Whether the command should not be displayed in help text.
Command#hide([hidden])
TODO: Command#hide([hidden])
TODO: Command#id([name])
Logger instance.
TODO: Command#on<T>(event, listener[, options])
TODO: Command#option(info[, data])
TODO: Command#optionValue(key[, value][, source])
TODO: Command#optionValueSource(key[, source])
TODO: Command#options([infos])
TODO: Command#opts<T>()
TODO: Command#optsWithGlobals<T>()
Command
| null
| undefined
The parent command.
TODO: Command#parse([argv][, options])
TODO: Command#parseAsync([argv][, options])
Information about the current process.
TODO: Command#snapshot()
TODO: Command#summary([summary])
TODO: Command#toString()
The strategy for handling unknown command-line arguments.
TODO: Command#unknowns(strategy)
TODO: Command#usage([usage])
TODO: Command#version([version])
A command error (class).
info
(CommandErrorInfo
) — info about the error
Command
| null
The command where the error originated.
Get a snapshot of the error.
(CommandErrorSnapshot
) Error snapshot object
A command-line error (class).
Error
constructor(info: KronkErrorInfo)
constructor(info: string, id?: EmptyString | KronkErrorId | null | undefined, code?: ExitCode | null | undefined)
info
(KronkErrorInfo
|string
) — error info or human-readable description of the errorid
(EmptyString
|KronkErrorId
, optional) — unique id representing the errorcode
(ExitCode
, optional) — suggested exit code to use withprocess.exit
string[]
Additional lines to be logged with the error.
KronkErrorCause
| null
| undefined
Info about the cause of the error.
number
The suggested exit code to use with process.exit
.
Unique id representing the error.
Get the error as a JSON object.
(KronkErrorJson
) JSON representation of this
error
Get the error as a human-readable string.
(string
) String representation of this
error
An event (class).
id
(KronkEventName
) — the unique id representing the event
The unique id representing the event.
Get the event as a human-readable string.
(string
) String representation of this
event
A command option (class).
constructor(info: Flags | OptionInfo)
constructor(info: Flags, data?: OptionData | null | undefined)
info
(Flags
|OptionInfo
) — option flags or infodata?
(OptionData
, optional) — additional option info
boolean
Whether the option is a boolean option. Boolean options are options that do not take any option-arguments.
Get or set option choices.
choices(): Set<string>
choices(choices: List<string> | null | undefined): this
choices
(List<string>
, optional) — list of option choices
(Set<string>
| this
) List of option choices or this
option
Get or set the default value configuration.
default<T>(): DefaultInfo<T>
default(info: DefaultInfo | null | undefined): this
T
(any
) — default value type
info
(DefaultInfo
, optional) — default value info
(DefaultInfo<T>
| this
) Default value info or this
option
Get or set the option description.
description(): string
description(description: URL | string | null | undefined): this
description
(URL | string
) — the option description
(string
| this
) Description of this
option or this
option
Get or set the environment variables to check for the value of the option.
env(): Set<string>
env(env: List<string> | string | null | undefined): this
env
(List<string>
|string
|null
|undefined
) — the name of the environment variable to check, or a list of names, in order of priority, to check
(string
| this
) Environment variable names or this
option
The event name for the option.
The normalized option flags string.
Option#hidden
boolean
Whether the option should not be displayed in help text.
Option#hide([hidden])
Remove the option from help text.
hidden
(boolean
|null
|undefined
, optional) — whether the option should be hidden- default:
true
- default:
(this
) this
option
string
The option id.
string
The option id
in a format that can be used an object property key.
string
| null
The long flag for the option.
If null
, the short
flag will be a non-empty string.
boolean
Whether the option must have a value after parsing.
boolean
Whether a value is optional when the option is specified.
Get or set the handler used to parse option-arguments.
parser<T, V extends string | string[] = string | string[]>(): ParseArg<T, V>
parser(parser: ParseArg<any, any> | null | undefined): this
T
(any
) — parse resultV
(string | string[]
, optional) — the argument or arguments to parse
parser
(ParseArg<any, any>
|null
|undefined
) — the option-argument parser
(ParseArg<T, V>
| this
) The option-argument parser or this
option
Get or set the preset to use when the option is specified without an argument.
The option-argument parser
will be called.
preset(): string | null
preset(preset: string | null | undefined): this
preset
(string
|null
|undefined
) — the option-argument preset
(string
| this
| null
) The option-argument preset or this
option
boolean
Whether a value must be supplied when the option is specified.
string
| null
The short flag for the option.
If null
, the long
flag will be a non-empty string.
Get the option as a human-readable string.
(string
) String representation of this
option
boolean
Whether the option can be specified multiple times.
A parsed option event (class).
T
(Option
, optional) — Parsed command option
option
(T
) — the command option instancevalue
(RawOptionValue
) — the rawoption
valuesource
(OptionValueSource
) — the source of the raw optionvalue
flag
(Flags
, optional) — the parsedoption
flag
Flags
| null
| undefined
The parsed command option
flag.
The option event name.
T
The command option
instance.
The source of the raw option value
.
The raw option
value.
A command version option (class).
info
(Version
|VersionOptionInfo
) — command version or option info
string
The version of the command.
This package is fully typed with TypeScript.
The callback to fire when a command is executed (TypeScript type).
type Action<
Opts extends OptionValues = OptionValues,
Args extends any[] = any[]
> = (
this: Command,
opts: Opts,
...args: Args
) => Awaitable<null | undefined | void>
Opts
(OptionValues
, optional) — command optionsArgs
(any[]
, optional) — command arguments
this
(Command
) — the current command or subcommand being executedoptions
(Opts
) — parsed command options...args
(Args
) — parsed command arguments
(Awaitable<null | undefined | void>
) Nothing
Data transfer object for command-arguments (TypeScript interface).
choices?
(List<string>
, optional) — list of argument choicesdefault?
(DefaultInfo
, optional) — default value configurationdescription?
(URL | string
, optional) — description of the argumentparser?
(ParseArg<any, any>
, optional) — handler used to parse command-arguments.
the handler receives two parameters, the raw, unparsed command-argument (or command-arguments for variadic options), and the previous (default) value for the argument. it should return the new value for the argument
Data used to create command-arguments (TypeScript interface).
syntax
(ArgumentSyntax
|string
) — argument syntax
Command-argument metadata (TypeScript interface).
id
(string
) — argument syntax idrequired
(boolean
) — whether required syntax was used when defining the argumentvariadic
(boolean
) — whether variadic syntax was used when defining the argument
Registry of strings used to define command and option arguments (TypeScript interface).
interface ArgumentSyntaxMap {/* see code */}
When developing extensions that use additional syntaxes, augment ArgumentSyntaxMap
to register custom syntaxes:
declare module '@flex-development/kronk' {
interface ArgumentSyntaxMap {
requiredMaybe: `<${string}?>`
}
}
Union of registered syntaxes used to define command and option arguments (TypeScript type).
To register custom syntaxes, augment ArgumentSyntaxMap
.
They will be added to this union automatically.
type ArgumentSyntax = ArgumentSyntaxMap[keyof ArgumentSyntaxMap]
Union of types used to create command arguments (TypeScript type).
type ArgumentsData =
| ArgumentInfo
| List<ArgumentInfo | ArgumentSyntax>
| string
Registry of command-line argument sources (TypeScript interface).
interface ArgvSourceMap {/* see code */}
When developing extensions that use additional sources, augment ArgvSourceMap
to register custom sources:
declare module '@flex-development/kronk' {
interface ArgvSourceMap {
electron: 'electron'
}
}
Union of registered command-line argument sources (TypeScript type).
To register custom sources, augment ArgvSourceMap
.
They will be added to this union automatically.
type ArgvSource = ArgvSourceMap[keyof ArgvSourceMap]
Create a union of T
and T
as a promise (TypeScript type).
T
(any
, optional)- the value
type Awaitable<T = unknown> = Promise<T> | T
Data transfer object for commands (TypeScript interface).
action?
(Action<any>
, optional) — callback to fire when the command is executedaliases?
(List<string>
|string
, optional) — aliases for the commandarguments?
(List<string>
, optional) — arguments for the commanddefault?
(boolean
, optional) — whether this is the default commanddescription?
(URL | string
, optional) — description of the commanddone?
(Action<any>
, optional) — callback to fire after the commandaction
is executedexit?
(Exit
, optional) — callback to fire when the process is exitedhidden?
(boolean
, optional) — whether the command should be not displayed in help textoptionPriority?
(OptionPriority
, optional) — the strategy to use when merging global and local options- default:
'local'
- default:
options?
(OptionsData
, optional) — options for the commandparent?
(Command
, optional) — the parent commandsubcommands?
(SubcommandsData
, optional) — subcommands for the commandsummary?
(string
, optional) — a summary of the commandunknown?
(UnknownStrategy
, optional) — the strategy to use for handling unknown command-line arguments- default:
false
- default:
usage?
(UsageData
, optional) — an object describing how the command is used- default:
{ arguments: null, options: '[options]', subcommand: '[command]' }
- default:
version?
(VersionData
, optional) — command version configuration
Data used to create command errors (TypeScript interface).
command?
(Command
, optional) — the command where the error originatedid
(KronkErrorId
) — unique id representing the error
Command error overview (TypeScript interface).
command
(CommandSnapshot
|null
) — an overview of the failed command
Data used to create commands (TypeScript interface).
name?
(CommandName
, optional) — the name of the command
Command metadata (TypeScript interface).
arguments
(Argument[]
) — list of command argumentsoptions
(Map<string, Option>
) — map, where each key is a long or short flag and each value is the command option instance registered for that flagparent?
(null
|undefined
) — the parent commandsubcommands
(Map<string, Command>
) — map, where each key is the name of a subcommand each value is a subcommandversion
(VersionOption
|null
|undefined
) — command version option
The name of a command (TypeScript type).
Parent commands do not need to have a name, but all subcommands must have a name. Valid command names are non-empty strings.
type CommandName = string | null
Object representing a command overview (TypeScript interface).
ancestors
(CommandName[]
) — list of ancestor command namesargs
(string[]
) — list of parsed command argumentsargv
(string[]
) — list of raw command argumentsname
(CommandName
) — the name of the commandoptionValueSources
(OptionValueSources
) — record, where each key is an option key and each value is the source of the parsed option valueopts
(OptionValues
) — parsed command optionsoptsWithGlobals
(OptionValues
) — parsed command options (with globals)
Data used to configure the default value of a command argument or option (TypeScript interface).
T
(any
, optional) — default value type
description?
(URL | string
, optional) — description of the default valuevalue?
(T
, optional) — the default value- default:
undefined
- default:
An empty string (TypeScript type).
type EmptyString = ''
Union of exit status code types (TypeScript type).
type ExitCode = number | string
Terminate the process synchronously with an exit status of code
(TypeScript type).
If code
is omitted, exit
uses either the 'success' code 0
or the value of process.exitCode
if it has been set.
type ExitProcess = (code?: ExitCode | null | undefined) => undefined
code?
(ExitCode
, optional) — exit status code
(undefined
) Nothing
The callback to fire when the process is exited (TypeScript type).
type Exit = (
this: Command,
e?: CommandError | KronkError | null | undefined
) => undefined
this
(Command
) — the current command or subcommand being executede?
(CommandError
|KronkError
, optional) — the error to handle (if any)
(undefined
) Nothing
A string comprised of option flags (TypeScript type).
The flags string can contain at most 2 flags, typically one long flag and one short or shortish (e.g. --ws
) flag.
Flags are separated by commas (,
), pipes (|
), or spaces.
A short flag is a hyphen — specifically HYPHEN-MINUS U+002D
— followed by one case-insensitive alphanumeric
character.
The letters themselves have conventional meanings and are worth following, if possible.
A long flag starts with two hyphens followed by one or more case-insensitive alphanumeric characters. Using two hyphens
prevents long flags from being confused for grouped short options.
Hyphens and full stops (FULL STOP U+002E
) can be used to separate words, as well as camelCase format.
Option-arguments are marked as required using empty angle brackets (<>
) or by wrapping an argument id in angle
brackets: <id>
.
Optional arguments use empty square brackets ([]
) or have their id wrapped in square brackets: [id]
.
Variadic arguments are specified with an ellipsis wrapped in brackets (e.g. <...>
, [...]
) or by appending the
ellipsis to the end of the argument id (<value...>
, [value...]
). Option-arguments can also be marked as mandatory by
appending an exclamation mark to the end of the argument id: (<!>
, <id!>
, <value!...>
).
type Flags = string
Info about the cause of an error (TypeScript interface).
👉 Note:
Symbol.hasInstance
andSymbol.unscopables
are used to identify arrays and functions.
interface KronkErrorCause {
[Symbol.hasInstance]?: never
[Symbol.unscopables]?: never
[key: string]: any
}
Union of registered error ids (TypeScript type).
To register custom error ids, augment KronkErrorMap
.
They will be added to this union automatically.
type KronkErrorId = `kronk/${keyof KronkErrorMap}`
Data used to create errors (TypeScript interface).
additional?
(string | string[]
, optional) — additional lines to be logged with the errorcause?
(KronkErrorCause
, optional) — info about the cause of the errorcode?
(ExitCode
, optional) — the suggested exit code to use withprocess.exit
- default:
1
- default:
id?
(EmptyString
|KronkErrorId
, optional) — the unique id representing the error- default:
'kronk/error'
- default:
reason
(string
) — a human-readable description of the error
JSON representation of an error (TypeScript interface).
additional
(string[]
) — additional lines to be logged with the errorcause?
(KronkErrorCause
, optional) — info about the cause of the errorcode
(number
) — the suggested exit code to use withprocess.exit
id
(KronkErrorId
) — the unique id representing the errormessage
(string
) — the human-readable description of the errorstack?
(string
, optional) — stack trace
Registry of errors (TypeScript interface).
Each key is the suffix of an error id and each value is a KronkError
.
interface KronkErrorMap {/* see code */}
When developing extensions that use additional errors, augment KronkErrorMap
to register custom errors:
declare module '@flex-development/kronk' {
interface KronkErrorMap {
'action-error': CustomCommandError
'parse-error': CustomKronkError
}
}
Handle an event
(TypeScript type).
type KronkEventListener<T extends KronkEvent = KronkEvent> = (
event: T
) => undefined
T
(KronkEvent
, optional) — the emitted event
event
(T
) — the emitted event
(undefined
) Nothing
Registry of event names (TypeScript interface).
interface KronkEventNameMap extends OptionEventNameMap {/* see code */}
When developing extensions that use additional events, augment KronkEventNameMap
to register custom event names:
declare module '@flex-development/kronk' {
interface KronkEventNameMap {
custom: 'command:custom'
}
}
Union of registered event names (TypeScript type).
To register custom event names, augment KronkEventNameMap
.
They will be added to this union automatically.
type KronkEventName = KronkEventNameMap[keyof KronkEventNameMap]
A list (TypeScript type).
T
(any
, optional) — list item type
type List<T = unknown> = ReadonlySet<T> | readonly T[]
Data transfer object for command options (TypeScript interface).
choices?
(List<string>
, optional) — list of option choicesdefault?
(DefaultInfo
, optional) — default value configuration👉 note: the option-argument
parser
will not be called.description?
(URL | string
, optional) — description of the option- default:
''
- default:
env?
(List<string>
|string
, optional) — the name of the environment variable to check for option value, or a list of names, in order of priority, to checkhidden?
(boolean
, optional) — whether the option should be not displayed in help text- default:
false
- default:
mandatory?
(boolean
, optional) — whether the option is mandatory. mandatory options must have a value after parsing, which usually means the option must be specified on the command line- default:
false
- default:
parser?
(ParseArg<any, string> | ParseArg<any, string[]>
, optional) — handler used to parse option-arguments. the handler receives two parameters, the raw, unparsed option-argument (or option-arguments for variadic options), and the previous (default) value for the argument. it should return the new value for the argumentpreset?
(string
, optional) — for boolean and optional options, the preset to use when the option is specified without an option-argument.👉 note: the option-argument
parser
will be called.snakecase?
(boolean
, optional) — whether to usesnake_case
format when converting the option id to an object property key
Handle a parsed command option event
(TypeScript type).
type OptionEventListener<T extends Option = Option> = (
event: OptionEvent<T>
) => undefined
T
(Option
, optional) — the parsed command option
event
(OptionEvent<T>
) — the emitted parsed option event
(undefined
) Nothing
Registry of option event names (TypeScript interface).
interface OptionEventNameMap {/* see code */}
When developing extensions that use additional events, augment OptionEventNameMap
to register custom event names:
declare module '@flex-development/kronk' {
interface OptionEventNameMap {
custom: `option.${string}`
}
}
Union of registered option event names (TypeScript type).
To register custom event names, augment OptionEventNameMap
.
They will be added to this union automatically.
type OptionEventName = OptionEventNameMap[keyof OptionEventNameMap]
Data used to create command options (TypeScript interface).
flags
(Flags
) — option flags
Command option metadata (TypeScript interface).
long
(string
|null
|undefined
) — long flagoptional
(boolean
) — whether a value is optional when the option is specifiedrequired
(boolean
) — whether a value must be supplied when the option is specifiedshort
(string
|null
|undefined
) — short (or shortish, e.g.--ws
) flag👉 note: if
null
orundefined
, thelong
flag will be a non-empty stringvariadic
(boolean
) — whether the option can be specified multiple times
Union of strategies used when merging global and local options (TypeScript type).
global
: global options overwrite local optionslocal
: local options overwrite global options
type OptionPriority = 'global' | 'local'
Registry of option value sources (TypeScript interface).
interface OptionValueSourceMap {/* see code */}
When developing extensions that use additional sources, augment OptionValueSourceMap
to register custom sources:
declare module '@flex-development/kronk' {
interface OptionValueSourceMap {
builder: 'builder'
}
}
Union of registered option value sources (TypeScript type).
To register custom sources, augment OptionValueSourceMap
.
They will be added to this union automatically.
type OptionValueSource = OptionValueSourceMap[keyof OptionValueSourceMap]
Record, where each key is an option key (Option.key
)
and each value is an OptionValueSource
(TypeScript type).
type OptionValueSources = {
[x: Option['key']]: OptionValueSource | null | undefined
}
Record, where each key is an option key (Option.key
)
and each value is a parsed option value (TypeScript type).
T
(any
, optional) — parsed option value type
type OptionValues<T = any> = { [x: Option['key']]: T }
Union of types used to create command options (TypeScript type).
type OptionsData =
| Flags
| List<Flags | OptionInfo>
| OptionInfo
Parse a command or option argument value
(TypeScript type).
type ParseArg<T = any, Value extends string | string[] = string | string[]> = (
this: void,
value: Value,
previous: T | undefined
) => T
T
(any
, optional) — parse resultValue
(string | string[]
, optional) — the argument or arguments to parse
this
(Command
) — the current command or subcommand being executedvalue
(Value
) — the raw argument or arguments to parseprevious
(T
|undefined
) — the default argument value
(T
) Parse result
Options for parsing command-line arguments (TypeScript interface).
from?
(ArgvSource
, optional) — the source of the command line arguments
Information about the current user environment (TypeScript interface).
interface ProcessEnv {
[key: string]: string | undefined
}
Information about the current process (TypeScript interface).
argv
(string[]
) — list of command-line arguments passed when the process was launchedenv
(ProcessEnv
) — object containing information about the user environmentexit
(ExitProcess
) — terminate the process synchronously with an exit status ofcode
exitCode?
(ExitCode
, optional) — the exit code to use when the process exits gracefully, or is exited viaexit
without specifying a codestderr
(WriteStream
) — the writeable stream for standard error outputstdout
(WriteStream
) — the writeable stream for standard output
Union of raw option value types (TypeScript type).
type RawOptionValue = boolean | string | string[] | null
Data used to create subcommands (TypeScript interface).
name
(string
) — the name of the subcommand
Union of types used to create subcommands (TypeScript type).
type SubcommandsData = SubcommandInfo | SubcommandsInfo
Record, where each key is the name of a subcommand and each value is an info object.
type SubcommandsInfo = { [subcommand: string]: CommandInfo }
Union of values used to alter handling of unknown command-line arguments (TypeScript type).
'arguments'
: allow unknown command-arguments only'options'
: allow unknown options onlyfalse
: disallow unknown command-arguments and optionstrue
: allow unknown command-arguments and options
type UnknownStrategy = 'arguments' | 'options' | boolean
An object describing command usage (TypeScript interface).
arguments?
(string
, optional) — command arguments descriptor👉 note: displayed in auto-generated help text only when a command has at least one visible argument
- default: generated using visible command arguments
options?
(string
, optional) — command options descriptor👉 note: displayed in auto-generated help text only when a command has at least one visible option
- default:
'[options]'
- default:
subcommand?
(string
, optional) — subcommands descriptor👉 note: displayed in auto-generated help text only when a command has at least one visible subcommand
- default:
'[command]'
- default:
Command usage info (TypeScript interface).
options
(string
) — command options descriptor👉 note: displayed in auto-generated help text only when a command has at least one visible option
subcommand
(string
) — subcommands descriptor👉 note: displayed in auto-generated help text only when a command has at least one visible subcommand
Union of types used to configure the version of a Command
(TypeScript type).
type VersionData = Version | VersionOption | VersionOptionInfo
Data used to create command version options (i.e. -v | --version
) (TypeScript interface).
flags?
(Flags
, optional) — option flags- default:
'-v | --version'
- default:
version
(Version
) — the command version
Union of command version types (TypeScript type).
type Version = import('semver').SemVer | string
See CONTRIBUTING.md
.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.