QCommand
@quik/cli / QCommand
Abstract Class: QCommand<TArguments>
Defined in: cli/src/QCommand.ts:12
Base class for creating CLI commands.
Subclasses should implement the _run method which is executed when the command is invoked.
Extends
QObject
Type Parameters
TArguments
TArguments = any
Implements
IQCommand<TArguments>
Constructors
Constructor
protectednew QCommand<TArguments>(name,description?):QCommand<TArguments>
Defined in: cli/src/QCommand.ts:28
Create a new command.
Parameters
name
string
Command name used in the CLI.
description?
string
Optional description shown in help output.
Returns
QCommand<TArguments>
Overrides
QObject.constructor
Properties
_aliases
protected_aliases:string[] =[]
Defined in: cli/src/QCommand.ts:53
Alternate names for this command.
_arguments
protected_arguments:Record<string,PositionalOptions> ={}
Defined in: cli/src/QCommand.ts:18
Registered positional arguments keyed by argument name.
_command
protected_command:string
Defined in: cli/src/QCommand.ts:85
Full command string as accepted by yargs.
_deprecated
protected_deprecated:string|boolean
Defined in: cli/src/QCommand.ts:37
Deprecation flag or message for this command.
_describe?
protectedoptional_describe?:string|false
Defined in: cli/src/QCommand.ts:69
Description shown in CLI help output.
_options
protected_options:Record<string,Options> ={}
Defined in: cli/src/QCommand.ts:20
Registered options keyed by option name.
builder
builder: (
args) =>Argv<TArguments>
Defined in: cli/src/QCommand.ts:14
Function used by yargs to build the command options.
Parameters
args
Argv<TArguments>
Returns
Argv<TArguments>
Implementation of
handler
handler: (
args) =>void|Promise<void>
Defined in: cli/src/QCommand.ts:16
Handler called by yargs when the command is executed.
Parameters
args
ArgumentsCamelCase<TArguments>
Returns
void | Promise<void>
Implementation of
Accessors
aliases
Get Signature
get aliases():
string[]
Defined in: cli/src/QCommand.ts:55
array of strings (or a single string) representing aliases of exports.command, positional args defined in an alias are ignored
Returns
string[]
Set Signature
set aliases(
newValue):void
Defined in: cli/src/QCommand.ts:64
Replace existing command aliases.
Parameters
newValue
string[]
List of aliases.
Returns
void
array of strings (or a single string) representing aliases of exports.command, positional args defined in an alias are ignored
Implementation of
command
Get Signature
get command():
string
Defined in: cli/src/QCommand.ts:87
string (or array of strings) that executes this command when given on the command line, first string may contain positional args
Returns
string
Set Signature
set command(
newValue):void
Defined in: cli/src/QCommand.ts:96
Set the full command definition as accepted by yargs.
Parameters
newValue
string
Command string.
Returns
void
string (or array of strings) that executes this command when given on the command line, first string may contain positional args
Implementation of
commandName
Get Signature
get commandName():
string
Defined in: cli/src/QCommand.ts:103
Command name without arguments.
Returns
string
Implementation of
deprecated
Get Signature
get deprecated():
string|boolean
Defined in: cli/src/QCommand.ts:39
boolean (or string) to show deprecation notice
Returns
string | boolean
Set Signature
set deprecated(
newValue):void
Defined in: cli/src/QCommand.ts:48
Mark the command as deprecated.
Parameters
newValue
string | boolean
Deprecation message or boolean flag.
Returns
void
boolean (or string) to show deprecation notice
Implementation of
describe
Get Signature
get describe():
string|false
Defined in: cli/src/QCommand.ts:71
string used as the description for the command in help text, use false for a hidden command
Returns
string | false
Set Signature
set describe(
newValue):void
Defined in: cli/src/QCommand.ts:80
Change the command description.
Parameters
newValue
string
New description text.
Returns
void
string used as the description for the command in help text, use false for a hidden command
Implementation of
logger
Get Signature
get
protectedlogger():IQLogger
Defined in: core/src/QObject.ts:15
The logger getter for the object.
Returns
IQLogger
Inherited from
QObject.logger
name
Get Signature
get name():
string
Defined in: core/src/QObject.ts:8
Returns
string
Inherited from
QObject.name
Methods
_builder()
protected_builder(argv):Argv<TArguments>
Defined in: cli/src/QCommand.ts:119
Configure yargs with the command's arguments and options.
Parameters
argv
Argv<TArguments>
Yargs instance.
Returns
Argv<TArguments>
_run()
abstractprotected_run(args):void|Promise<void>
Defined in: cli/src/QCommand.ts:112
Execute the command logic.
Parameters
args
ArgumentsCamelCase<TArguments>
Parsed command arguments.
Returns
void | Promise<void>
endSpan()
protectedendSpan(span):void
Defined in: core/src/QObject.ts:35
End a span returned by startSpan.
Parameters
span
TelemetrySpan
The span to end.
Returns
void
Inherited from
QObject.endSpan
hide()
protectedhide():void
Defined in: cli/src/QCommand.ts:136
Hide this command from help output.
Returns
void
pushArgument()
protectedpushArgument(argument,options?):void
Defined in: cli/src/QCommand.ts:155
Register a positional argument for the command.
Parameters
argument
string
Name of the argument.
options?
PositionalOptions
Optional argument configuration.
Returns
void
pushOptions()
protectedpushOptions(option,options?):void
Defined in: cli/src/QCommand.ts:165
Register an option for the command.
Parameters
option
string
Option name.
options?
Options
Optional option configuration.
Returns
void
recordSpanError()
protectedrecordSpanError(span,err):void
Defined in: core/src/QObject.ts:45
Record an exception on an active span.
Parameters
span
TelemetrySpan
The span to record the error on.
err
unknown
The error to record.
Returns
void
Inherited from
QObject.recordSpanError
setAliases()
protectedsetAliases(...newAliases):void
Defined in: cli/src/QCommand.ts:145
Add aliases for this command.
Parameters
newAliases
...string[]
Alias strings.
Returns
void
setSpanAttribute()
protectedsetSpanAttribute(span,key,value):void
Defined in: core/src/QObject.ts:64
Set a single attribute on an active span.
Parameters
span
TelemetrySpan
The span to update.
key
string
Attribute key.
value
string | number | boolean
Attribute value.
Returns
void
Inherited from
QObject.setSpanAttribute
startSpan()
protectedstartSpan(spanName,options?):TelemetrySpan
Defined in: core/src/QObject.ts:26
Start a telemetry span for the given operation name. Returns undefined when no telemetry provider is active.
Parameters
spanName
string
Name of the span.
options?
TelemetrySpanOptions
Optional span attributes and kind.
Returns
TelemetrySpan
Inherited from
QObject.startSpan