Module

x/cliffy/packages/command/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.6.0/packages/command/mod.ts";

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

Properties

protected
_allowEmpty: boolean
protected
_useRawArgs: boolean
protected
args: IArgumentDetails[]
protected
argsDefinition: string | undefined
protected
cmd: BaseCommand
protected
cmdName: string | undefined
protected
commands: Map<string, CommandMap>
protected
completions: ICompleteHandlerMap
protected
defaultCommand: string | undefined
protected
desc: string
protected
envVars: IEnvVariable[]
protected
examples: IExample[]
protected
fn: IAction | undefined
protected
isExecutable: boolean
protected
name: string
protected
options: IOption[]
protected
path: string
protected
rawArgs: string[]
protected
throwOnError: boolean
protected
types: ITypeMap
protected
ver: string

Methods

protected
execute(options?: IFlags, ...args: IFlagValue[]): Promise<IFlagsParseResult>

Execute command.

protected
executeExecutable(args: string[])

Execute external sub-command.

protected
findActionFlag(flags: IFlags, args: IFlagValue[]): IOption | undefined

Execute help command if help flag is set.

protected
parseArgsDefinition(argsDefinition: string): IArgumentDetails[]

Parse command line args definition.

protected
parseArguments(args: string[], flags: IFlags): IFlagValue[]

Match commands and arguments from command line arguments.

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

Parse command line args.

protected
splitArguments(args: string)

Split arguments string into args and types: -v, --verbose [arg:boolean]

protected
validateEnvVars()

Validate environment variables.

action(fn: IAction): 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(action: string, completeHandler: ICompleteHandler): 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): this

Add new environment variable.

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

Handle error. If throwOnError is enabled all error's will be thrown, if not Deno.exit(1) will be called.

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

Add new command example.

getActionNames(): string[]
getArgsDefinition(): string | undefined

Get arguments definition.

getArgument(name: string): IArgumentDetails | undefined

Get argument.

Get arguments.

getCommand(name: string): BaseCommand

Get sub-command with given name.

getCommandMap(name: string): CommandMap

Get sub-command map with given name.

Get sub-command maps.

Get sub-commands.

getCompletion(action: string): Promise<string[] | undefined>
getDescription(): string

Get command description.

getEnvVar(name: string): string | undefined

Get environment variable with given name.

Get environment variables.

getExample(name: string): IExample | undefined

Get example with given name.

Get examples.

getName(): string

Get command name.

getOption(name: string): IOption | undefined

Get option by name.

getPath(): string

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

getVersion(): string

Get command arguments.

Check if command has arguments.

hasCommand(name: string): boolean

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

hasCommands(): boolean

Checks whether the command has sub-commands or not.

hasEnvVar(name: string): boolean

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

hasEnvVars(): 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): boolean

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

hasOptions(): boolean

Checks whether the command has options or not.

Execute help command.

log(...args: any[])

Write line to stdout.

logError(...args: any[])

Write line to stderr.

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<IFlagsParseResult>

Parse command line arguments and execute matched command.

removeCommand(name: string): BaseCommand

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.

setPath(path: string): this

Set command path.

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(
type: string,
typeHandler: Type<any> | ITypeHandler<any>,
override?: boolean,
): 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.6.0/packages/command/mod.ts";