x/velociraptor/deps.ts

The npm-style script runner for Deno
Latest
class Command
import { Command } from "https://deno.land/x/velociraptor@1.5.0/deps.ts?s=Command";

Type Parameters

optional
CO extends Record<string, any> | void = any
[src]
optional
CA extends Array<unknown> = CO extends number ? any : []
[src]
optional
CG extends Record<string, any> | void = CO extends number ? any : void
[src]
optional
PG extends Record<string, any> | void = CO extends number ? any : void
[src]
optional
P extends Command | undefined = CO extends number ? any : undefined
[src]

Properties

private
_allowEmpty: boolean
[src]
private
optional
_globalParent: Command
[src]
private
optional
_help: IHelpHandler
[src]
private
optional
_helpOption: IDefaultOption | false
[src]
private
_name: string
[src]
private
optional
_parent: P
[src]
private
_stopEarly: boolean
[src]
private
_useRawArgs: boolean
[src]
private
optional
_versionOption: IDefaultOption | false
[src]
private
aliases: string[]
[src]
private
args: IArgument[]
[src]
private
optional
argsDefinition: string
[src]
private
cmd: Command
[src]
private
commands: Map<string, Command>
[src]
private
completions: Map<string, ICompletion>
[src]
private
optional
defaultCommand: string
[src]
private
desc: IDescription
[src]
private
envVars: IEnvVar[]
[src]
private
examples: IExample[]
[src]
private
optional
fn: IAction
[src]
private
hasDefaults: boolean
[src]
private
isExecutable: boolean
[src]
private
isGlobal: boolean
[src]
private
isHidden: boolean
[src]
private
literalArgs: string[]
[src]
private
options: IOption[]
[src]
private
rawArgs: string[]
[src]
private
throwOnError: boolean
[src]
private
types: Map<string, IType>
[src]
private
optional
ver: IVersionHandler
[src]

Methods

private
getHelpHandler(): IHelpHandler
[src]

Get help handler method.

private
getVersionHandler(): IVersionHandler | undefined
[src]

Get help handler method.

private
registerDefaults(): this
[src]

Register default options like --version and --help.

protected
error(error: Error): Error
[src]

Handle error. If throwErrors is enabled the error will be returned, otherwise a formatted error message will be printed and Deno.exit(1) will be called.

protected
execute(options: PG & CG & CO, ...args: CA): Promise<IParseResult<CO, CA, CG, PG, P>>
[src]

Execute command.

protected
executeExecutable(args: string[])
[src]

Execute external sub-command.

protected
parseArguments(args: string[], flags: Record<string, unknown>): CA
[src]

Parse command-line arguments.

protected
parseFlags(args: string[]): IFlagsResult & { action?: IAction; }
[src]

Parse raw command line arguments.

protected
parseType(type: ITypeInfo): unknown
[src]

Parse argument type.

protected
shouldThrowErrors(): boolean
[src]

Check whether the command should throw errors or exit.

protected
validateEnvVars(): Promise<void>
[src]

Validate environment variables.

action(fn: IAction<CO, CA, CG, PG, P>): this[src]

Set command callback method.

alias(alias: string): this[src]

Add new command alias.

allowEmpty(allowEmpty?): this[src]

Don't throw an error if the command was called without arguments.

arguments<A extends Array<unknown> = CA>(args: string): Command<CO, MapArgumentTypes<A>, CG, PG, P>[src]

Set command arguments:

requiredArg:string [optionalArg: number] [...restArgs:string]

arguments(args: string): Command[src]
command<C extends (CO extends number ? Command : Command<Record<string, any> | void, Array<unknown>, Record<string, any> | void, Merge<PG, CG> | void | undefined, OneOf<P, this> | undefined>)>(
name: string,
cmd: C,
override?: boolean,
): C extends Command<infer O, infer A, infer G, any, any> ? Command<O, A, G, Merge<PG, CG>, OneOf<P, this>> : never
[src]

Add new sub-command.

command<A extends Array<unknown> = Array<any>>(
name: string,
desc?: string,
override?: boolean,
): Command<CO extends number ? any : void, MapArgumentTypes<A>, CO extends number ? any : void, Merge<PG, CG>, OneOf<P, this>>
[src]

Add new sub-command.

command(
nameAndArguments: string,
cmdOrDescription?: Command | string,
override?: boolean,
): Command
[src]

Add new sub-command.

complete(
name: string,
complete: ICompleteHandler<Partial<CO>, Partial<CA>, CG, PG, any>,
options: ICompleteOptions & { global: boolean; },
): this
[src]

Register command specific custom type.

complete(
name: string,
complete: ICompleteHandler<CO, CA, CG, PG, P>,
options?: ICompleteOptions,
): this
[src]
complete(
name: string,
complete: ICompleteHandler<CO, CA, CG, PG, P>,
options?: ICompleteOptions,
): this
[src]
default(name: string): this[src]

Set default command. The default command is executed when the program was called without any argument and if no action handler is registered.

description(description: IDescription<CO, CA, CG, PG, P>): this[src]

Set the long command description.

env(
name: string,
description: string,
options?: IEnvVarOptions,
): this
[src]

Add new environment variable.

example(name: string, description: string): this[src]

Add new command example.

executable(): this[src]

Make command executable.

getAliases(): string[][src]

Get command name aliases.

getArgsDefinition(): string | undefined[src]

Get arguments definition. E.g: input-file:string output-file:string

getArgument(name: string): IArgument | undefined[src]

Get argument by name.

getArguments(): IArgument[][src]

Get arguments.

getBaseCommand(name: string, hidden?: boolean): Command | undefined[src]

Get base command by name or alias.

getBaseCommands(hidden?: boolean): Array<Command>[src]

Get base commands.

getBaseCompletion(name: string): ICompletion | undefined[src]

Get base completion by name.

getBaseCompletions(): ICompletion[][src]

Get base completions.

getBaseEnvVar(name: string, hidden?: boolean): IEnvVar | undefined[src]

Get base environment variable by name.

getBaseEnvVars(hidden?: boolean): IEnvVar[][src]

Get base environment variables.

getBaseOption(name: string, hidden?: boolean): IOption | undefined[src]

Get base option by name.

getBaseOptions(hidden?: boolean): IOption[][src]

Get base options.

getBaseType(name: string): IType | undefined[src]

Get base type by name.

getBaseTypes(): IType[][src]

Get base types.

getCommand(name: string, hidden?: boolean): Command | undefined[src]

Get command by name or alias.

getCommands(hidden?: boolean): Array<Command>[src]

Get commands.

getCompletion(name: string): ICompletion | undefined[src]

Get completion by name.

getCompletions()[src]

Get completions.

getDescription(): string[src]

Get command description.

getEnvVar(name: string, hidden?: boolean): IEnvVar | undefined[src]

Get environment variable by name.

getEnvVars(hidden?: boolean): IEnvVar[][src]

Get environment variables.

getExample(name: string): IExample | undefined[src]

Get example with given name.

getExamples(): IExample[][src]

Get all examples.

getGlobalCommand(name: string, hidden?: boolean): Command | undefined[src]

Get global command by name or alias.

getGlobalCommands(hidden?: boolean): Array<Command>[src]

Get global commands.

getGlobalCompletion(name: string): ICompletion | undefined[src]

Get global completions by name.

getGlobalCompletions(): ICompletion[][src]

Get global completions.

getGlobalEnvVar(name: string, hidden?: boolean): IEnvVar | undefined[src]

Get global environment variable by name.

getGlobalEnvVars(hidden?: boolean): IEnvVar[][src]

Get global environment variables.

getGlobalOption(name: string, hidden?: boolean): IOption | undefined[src]

Get global option from parent command's by name.

getGlobalOptions(hidden?: boolean): IOption[][src]

Get global options.

getGlobalParent(): Command | undefined[src]

Get parent command from global executed command. Be sure, to call this method only inside an action handler. Unless this or any child command was executed, this method returns always undefined.

getGlobalType(name: string): IType | undefined[src]

Get global type by name.

getGlobalTypes(): IType[][src]

Get global types.

getHelp(): string[src]

Get generated help.

getLiteralArgs(): string[][src]

Get all arguments defined after the double dash.

getMainCommand(): Command[src]

Get main command.

getName(): string[src]

Get command name.

getOption(name: string, hidden?: boolean): IOption | undefined[src]

Get option by name.

getOptions(hidden?: boolean): IOption[][src]

Get options.

getParent(): P[src]

Get parent command.

getPath(): string[src]

Get full command path.

getRawArgs(): string[][src]

Get original command-line arguments.

getShortDescription(): string[src]

Get short command description. This is the first line of the description.

getType(name: string): IType | undefined[src]

Get type by name.

getTypes(): IType[][src]

Get types.

getVersion(): string | undefined[src]

Get command version.

global(): this[src]

Make command globally available.

globalComplete(
name: string,
complete: ICompleteHandler,
options?: Omit<ICompleteOptions, "global">,
): this
[src]
globalEnv(
name: string,
description: string,
options?: Omit<IEnvVarOptions, "global">,
): this
[src]
globalOption<G extends Record<string, unknown> | void = CG>(
flags: string,
desc: string,
opts?: Omit<ICommandOption<Partial<CO>, CA, Merge<CG, MapOptionTypes<G>>, PG, P>, "global"> | IFlagValueHandler,
): Command<CO, CA, Merge<CG, MapOptionTypes<G>>, PG, P>
[src]
globalType(
name: string,
type: Type<unknown> | ITypeHandler<unknown>,
options?: Omit<ITypeOptions, "global">,
): this
[src]
hasArguments()[src]

Check if command has arguments.

hasCommand(name: string, hidden?: boolean): boolean[src]

Checks whether a child command exists by given name or alias.

hasCommands(hidden?: boolean): boolean[src]

Checks whether the command has sub-commands or not.

hasEnvVar(name: string, hidden?: boolean): boolean[src]

Checks whether the command has an environment variable with given name or not.

hasEnvVars(hidden?: boolean): boolean[src]

Checks whether the command has environment variables or not.

hasExample(name: string): boolean[src]

Checks whether the command has an example with given name or not.

hasExamples(): boolean[src]

Checks whether the command has examples or not.

hasOption(name: string, hidden?: boolean): boolean[src]

Checks whether the command has an option with given name or not.

hasOptions(hidden?: boolean): boolean[src]

Checks whether the command has options or not.

help(help: string | IHelpHandler<Partial<CO>, Partial<CA>, CG, PG> | HelpOptions): this[src]

Set command help.

helpOption(enable: false): this[src]

Disable help option.

helpOption(
flags: string,
desc?: string,
opts?: ICommandOption<Partial<CO>, CA, CG, PG, P> & { global: true; },
): this
[src]

Set global help option.

helpOption(
flags: string,
desc?: string,
opts?: ICommandOption<CO, CA, CG, PG, P>,
): this
[src]

Set help option.

helpOption(
flags: string,
desc?: string,
opts?: IAction<CO, CA, CG, PG, P>,
): this
[src]

Set help option.

helpOption(
flags: string | false,
desc?: string,
opts?: IAction<CO, CA, CG, PG, P> | ICommandOption<CO, CA, CG, PG, P> | ICommandOption<Partial<CO>, CA, CG, PG, P> & { global: true; },
): this
[src]
hidden(): this[src]

Hide command from help, completions, etc.

name(name: string): this[src]

Set command name.

option<G extends Record<string, unknown> | void = CG>(
flags: string,
desc: string,
opts: ICommandOption<Partial<CO>, CA, Merge<CG, MapOptionTypes<G>>, PG, P> & { global: true; } | IFlagValueHandler,
): Command<CO, CA, Merge<CG, MapOptionTypes<G>>, PG, P>
[src]

Add a new option.

option<O extends Record<string, unknown> | void = CO>(
flags: string,
desc: string,
opts?: ICommandOption<Merge<CO, MapOptionTypes<O>>, CA, CG, PG, P> | IFlagValueHandler,
): Command<Merge<CO, MapOptionTypes<O>>, CA, CG, PG, P>
[src]
option(
flags: string,
desc: string,
opts?: ICommandOption | IFlagValueHandler,
): Command
[src]
parse(args?: string[], dry?: boolean): Promise<IParseResult<CO, CA, CG, PG, P>>[src]

Parse command line arguments and execute matched command.

removeCommand(name: string): Command | undefined[src]

Remove sub-command by name or alias.

removeOption(name: string): IOption | undefined[src]

Remove option by name.

reset(): OneOf<P, this>[src]

Reset internal command reference to main command.

select<O extends Record<string, unknown> | void = any, A extends Array<unknown> = any, G extends Record<string, unknown> | void = any>(name: string): Command<O, A, G, PG, P>[src]

Set internal command pointer to child command with given name.

showHelp(): void[src]

Output generated help without exiting.

showVersion(): void[src]

Output generated help without exiting.

stopEarly(stopEarly?): this[src]

Enable stop early. If enabled, all arguments starting from the first non option argument will be passed as arguments with type string to the command action handler.

For example: command --debug-level warning server --port 80

Will result in: - options: {debugLevel: 'warning'} - args: ['server', '--port', '80']

throwErrors(): this[src]

Throw validation error's instead of calling Deno.exit() to handle validation error's manually.

A validation error is thrown when the command is wrongly used by the user. For example: If the user passes some invalid options or arguments to the command.

This has no effect for parent commands. Only for the command on which this method was called and all child commands.

Example:

try {
  cmd.parse();
} catch(error) {
  if (error instanceof ValidationError) {
    cmd.showHelp();
    Deno.exit(1);
  }
  throw error;
}
type(
name: string,
handler: Type<unknown> | ITypeHandler<unknown>,
options?: ITypeOptions,
): this
[src]

Register custom type.

useRawArgs(useRawArgs?): Command<CO, Array<string>, CG, PG, P>[src]

Disable parsing arguments. If enabled the raw arguments will be passed to the action handler. This has no effect for parent or child commands. Only for the command on which this method was called.

version(version: string | IVersionHandler<Partial<CO>, Partial<CA>, CG, PG>): this[src]

Set command version.

versionOption(enable: false): this[src]

Disable version option.

versionOption(
flags: string,
desc?: string,
opts?: ICommandOption<Partial<CO>, CA, CG, PG, P> & { global: true; },
): this
[src]

Set global version option.

versionOption(
flags: string,
desc?: string,
opts?: ICommandOption<CO, CA, CG, PG, P>,
): this
[src]

Set version option.

versionOption(
flags: string,
desc?: string,
opts?: IAction<CO, CA, CG, PG, P>,
): this
[src]

Set version option.

versionOption(
flags: string | false,
desc?: string,
opts?: IAction<CO, CA, CG, PG, P> | ICommandOption<CO, CA, CG, PG, P> | ICommandOption<Partial<CO>, CA, CG, PG, P> & { global: true; },
): this
[src]
import Command
import { Command } from "https://deno.land/x/velociraptor@1.5.0/deps.ts?s=Command";