Module

x/cliffy/packages/command/mod.ts>Command

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Go to Latest
class Command
import { Command } from "https://dotland.deno.dev/x/cliffy@v0.12.0/packages/command/mod.ts";

Base command implementation without pre configured command's and option's.

Type Parameters

optional
O = any
optional
A extends Array<any> = any

Properties

private
_allowEmpty: boolean
private
optional
_globalParent: Command
private
optional
_helpOption: IDefaultOption<O, A> | false
private
_name: string
private
optional
_parent: Command
private
_stopEarly: boolean
private
_useRawArgs: boolean
private
optional
_versionOption: IDefaultOption<O, A> | false
private
aliases: string[]
private
args: IArgumentDetails[]
private
optional
argsDefinition: string
private
cmd: Command
private
commands: Map<string, Command>
private
completions: Map<string, ICompleteSettings>
private
optional
defaultCommand: string
private
desc: IDescription
private
envVars: IEnvVariable[]
private
examples: IExample[]
private
optional
fn: IAction<O, A>
private
hasDefaults: Boolean
private
isExecutable: boolean
private
isGlobal: boolean
private
isHidden: boolean
private
literalArgs: string[]
private
options: IOption<O, A>[]
private
rawArgs: string[]
private
throwOnError: boolean
private
types: ITypeMap
private
ver: string

Methods

private
registerDefaults(): this
protected
execute(options: O, ...args: A): Promise<IParseResult<O, A>>

Execute command.

protected
executeExecutable(args: string[])

Execute external sub-command.

protected
findActionFlag(flags: O): IOption | undefined

Execute help command if help flag is set.

protected
getBaseType(name: string): ITypeSettings | undefined
protected
getGlobalType(name: string): ITypeSettings | undefined
protected
getType(name: string): ITypeSettings | undefined
protected
parseArguments(args: string[], flags: O): A

Match commands and arguments from command line arguments.

protected
parseFlags(args: string[]): IFlagsResult<O>

Parse command line args.

protected
parseType(
name: string,
option: IFlagOptions,
nextValue: string,
): any
protected
shouldThrowErrors(): boolean
protected
validateEnvVars()

Validate environment variables.

action(fn: IAction<O, A>): this

Set command handler.

alias(alias: string): this

Add new command alias.

allowEmpty(allowEmpty?: boolean): this

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

arguments(args: string): this

Set command arguments.

command(
nameAndArguments: string,
cmd?: Command | string,
override?: boolean,
): this

Add new sub-command.

complete(
name: string,
complete: ICompleteHandler,
options?: ICompleteOptions,
): this

Register command specific custom type.

default(name: string): this

Set default command. The default command will be called if no action handler is registered.

description(description: IDescription): this

Set command description.

env(
name: string,
description: string,
options?: IEnvVarOption,
): this

Add new environment variable.

error(error: Error, showHelp?: boolean): Error

Handle error. If .throwErrors() was called all error's will be thrown, otherwise Deno.exit(1) will be called.

example(name: string, description: string): this

Add new command example.

getAliases(): string[]

Get command name aliases.

getArgsDefinition(): string | undefined

Get arguments definition.

getArgument(name: string): IArgumentDetails | undefined

Get argument.

Get arguments.

getBaseCommand<O = any>(name: string, hidden?: boolean): Command<O> | undefined
getBaseCommands(hidden?: boolean): Command[]
getBaseCompletion(name: string): ICompleteSettings | undefined
getBaseEnvVar(name: string, hidden?: boolean): IEnvVariable | undefined
getBaseEnvVars(hidden?: boolean): IEnvVariable[]
getBaseOption(name: string, hidden?: boolean): IOption | undefined

Get base option by name.

getBaseOptions(hidden?: boolean): IOption[]
getCommand<O = any>(name: string, hidden?: boolean): Command<O> | undefined

Get sub-command with given name.

getCommands(hidden?: boolean): Command[]

Get sub-commands.

getCompletion(name: string)
getDescription(): string

Get command description.

getEnvVar(name: string, hidden?: boolean): IEnvVariable | undefined

Get environment variable with given name.

getEnvVars(hidden?: boolean): IEnvVariable[]

Get environment variables.

getExample(name: string): IExample | undefined

Get example with given name.

Get examples.

getGlobalCommand<O = any>(name: string, hidden?: boolean): Command<O> | undefined
getGlobalCommands(hidden?: boolean): Command[]
getGlobalCompletion(name: string): ICompleteSettings | undefined
getGlobalEnvVar(name: string, hidden?: boolean): IEnvVariable | undefined
getGlobalEnvVars(hidden?: boolean): IEnvVariable[]
getGlobalOption(name: string, hidden?: boolean): IOption | undefined

Get global option from parent command's by name.

getGlobalOptions(hidden?: boolean): IOption[]
getGlobalParent(): Command | undefined

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.

getHelp(): string

Get generated help.

getLiteralArgs(): string[]

Get main command.

getName(): string

Get command name.

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

Get option by name.

getOptions(hidden?: boolean): IOption[]
getParent(): Command | undefined

Get parent command.

getPath(): string

Get full command path of all parent command names's and current command name.

getRawArgs(): string[]
getVersion(): string

Get command version.

global(): this

Make command globally available.

Check if command has arguments.

hasCommand(name: string, hidden?: boolean): boolean

Checks whether the command has a sub-command with given name or not.

hasCommands(hidden?: boolean): boolean

Checks whether the command has sub-commands or not.

hasEnvVar(name: string, hidden?: boolean): boolean

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

hasEnvVars(hidden?: boolean): boolean

Checks whether the command has environment variables or not.

hasExample(name: string): boolean

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

hasExamples(): boolean

Checks whether the command has examples or not.

hasOption(name: string, hidden?: boolean): boolean

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

hasOptions(hidden?: boolean): boolean

Checks whether the command has options or not.

Output generated help without exiting.

helpOption(
flags: string | false,
desc?: string,
opts?: IAction<O, A> | ICommandOption<O, A>,
): this
hidden(): this

Hide command from help, completions, etc.

log(...args: any[])

Write line to stdout.

logError(...args: any[])

Write line to stderr.

name(name: string): this

Get or set command name.

option(
flags: string,
desc: string,
): this

Add new option (flag).

parse(args?: string[], dry?: boolean): Promise<IParseResult<O, A>>

Parse command line arguments and execute matched command.

removeCommand<O = any>(name: string): Command<O> | undefined

Remove sub-command with given name.

removeOption(name: string): IOption | undefined

Remove option by name.

reset(): this

Reset internal command reference to main command.

select(name: string): this

Reset internal command reference to child command with given name.

stopEarly(stopEarly?: boolean): this

If enabled, all arguments starting from the first non option argument will be interpreted as raw argument.

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

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

throwErrors(): this

Throw error's instead of calling Deno.exit() to handle error's manually. This has no effect for parent commands. Only for the command on which this method was called and all child commands.

type(
name: string,
handler: Type<any> | ITypeHandler<any>,
options?: ITypeOption,
): this

Register command specific custom type.

useRawArgs(useRawArgs?: boolean): this

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): this

Set command version.

versionOption(
flags: string | false,
desc?: string,
opts?: IAction<O, A> | ICommandOption<O, A>,
): this
write(...args: any[])

Write line to stdout without line break.

writeError(...args: any[])

Write line to stderr without line break.

import Command
import { Command } from "https://dotland.deno.dev/x/cliffy@v0.12.0/packages/command/mod.ts";