Module

x/cliffy/mod.ts>BaseCommand

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Go to Latest
class BaseCommand
import { BaseCommand } from "https://dotland.deno.dev/x/cliffy@v0.8.0/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

protected
_allowEmpty: boolean
protected
_name: string
protected
optional
_parent: BaseCommand
protected
_useRawArgs: boolean
protected
aliases: string[]
protected
args: IArgumentDetails[]
protected
argsDefinition: string | undefined
protected
cmd: BaseCommand
protected
commands: Map<string, BaseCommand>
protected
completions: Map<string, ICompleteSettings>
protected
defaultCommand: string | undefined
protected
desc: string
protected
envVars: IEnvVariable[]
protected
examples: IExample[]
protected
fn: IAction<O, A> | undefined
protected
isExecutable: boolean
protected
isGlobal: boolean
protected
isHidden: boolean
protected
options: IOption<O, A>[]
protected
rawArgs: string[]
protected
throwOnError: boolean
protected
types: ITypeMap
protected
ver: string

Methods

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
parseArgsDefinition(argsDefinition: string): IArgumentDetails[]

Parse command line args definition.

protected
parseArguments(args: string[], flags: O): A

Match commands and arguments from command line arguments.

protected
parseFlags(
args: string[],
stopEarly?: boolean,
knownFlaks?: IFlags,
): IFlagsResult<O>

Parse command line args.

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

Split arguments string into args and types: -v, --verbose [arg: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?: BaseCommand | 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: string): 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): BaseCommand<O> | undefined
getBaseCommands(hidden?: boolean): BaseCommand[]
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): BaseCommand<O> | undefined

Get sub-command with given name.

getCommands(hidden?: boolean): BaseCommand[]

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): BaseCommand<O> | undefined
getGlobalCommands(hidden?: boolean): BaseCommand[]
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[]
getName(): string

Get or set command name.

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

Get option by name.

getOptions(hidden?: boolean): IOption[]
getPath(): string

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

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.

Execute help command.

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).

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): BaseCommand<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.

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.

write(...args: any[])

Write line to stdout without line break.

writeError(...args: any[])

Write line to stderr without line break.

import BaseCommand
import { BaseCommand } from "https://dotland.deno.dev/x/cliffy@v0.8.0/mod.ts";