Skip to main content

QCommand

@quik/cli


@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

Constructors

Constructor

protected new 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?

protected optional _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

IQCommand.builder


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

IQCommand.handler

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

IQCommand.aliases


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

IQCommand.command


commandName

Get Signature

get commandName(): string

Defined in: cli/src/QCommand.ts:103

Command name without arguments.

Returns

string

Implementation of

IQCommand.commandName


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

IQCommand.deprecated


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

IQCommand.describe


logger

Get Signature

get protected logger(): 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()

abstract protected _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()

protected endSpan(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()

protected hide(): void

Defined in: cli/src/QCommand.ts:136

Hide this command from help output.

Returns

void


pushArgument()

protected pushArgument(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()

protected pushOptions(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()

protected recordSpanError(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()

protected setAliases(...newAliases): void

Defined in: cli/src/QCommand.ts:145

Add aliases for this command.

Parameters

newAliases

...string[]

Alias strings.

Returns

void


setSpanAttribute()

protected setSpanAttribute(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()

protected startSpan(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