Skip to content

default ​

gunshi cli entry point.

This entry point exports the bellow APIs and types:

  • cli: The main CLI function to run the command, included global options and usage renderer built-in plugins.
  • define: A function to define a command.
  • defineWithTypes: A function to define a command with specific type parameters.
  • lazy: A function to lazily load a command.
  • lazyWithTypes: A function to lazily load a command with specific type parameters.
  • plugin: A function to create a plugin.
  • createCommandContext: A function to create a command context, mainly for testing purposes.
  • args-tokens utilities: parseArgs, resolveArgs, ArgsValidationError, ArgsValidationErrorKeys, and ArgsValidationErrorCode for parsing and validating command line arguments.
  • Structured error utilities: CommandNotFoundError, CommandNotFoundErrorKeys, CommandNotFoundErrorCode, CommandNotFoundErrorOptions, CommandResolutionError, CommandResolutionErrorKeys, CommandResolutionErrorCode, CommandResolutionErrorOptions, isCommandNotFoundError, isCommandResolutionError, isArgsValidationError, and hasPriorityValidationError.
  • Some basic type definitions, such as CommandContext, Plugin, PluginContext, etc.

Example ​

js
import { cli } from 'gunshi'

Variables ​

VariableDescription
ANONYMOUS_COMMAND_NAME
CommandNotFoundErrorKeysCommand not found error resource keys.
CommandResolutionErrorKeysCommand resolution error resource keys.

Functions ​

FunctionDescription
cliRun the command.
hasPriorityValidationErrorCheck whether validation errors should be handled before version, help, or command execution.
isArgsValidationErrorCheck whether an error is an ArgsValidationError.
isCommandNotFoundErrorCheck whether an error is a CommandNotFoundError.
isCommandResolutionErrorCheck whether an error is a CommandResolutionError.
parseArgsParse command line arguments.
pluginDefine a plugin with extension compatibility and typed dependency extensions
resolveArgsResolve command line arguments.

Classes ​

ClassDescription
ArgsValidationErrorAn error that contains structured metadata for argument validation failures.
CommandNotFoundErrorError raised when a command cannot be resolved.
CommandResolutionErrorError raised when command routing cannot produce one consistent command.
DefaultTranslationDefault implementation of TranslationAdapter.

Interfaces ​

InterfaceDescription
ArgsAn object that contains argument schema.
ArgSchemaAn argument schema definition for command-line argument parsing.
ArgTokenArgument token.
CliOptionsCLI options of cli function.
CommandCommand interface.
CommandContextCommand context.
CommandContextExtensionCommand context extension
CommandEnvironmentCommand environment.
GunshiParamsGunshi unified parameter type.
PluginContextGunshi plugin context interface.
PluginDependencyPlugin dependency definition
PluginOptionsPlugin definition options
PluginWithExtensionPlugin return type with extension, which includes the plugin ID, name, dependencies, and extension.
PluginWithoutExtensionPlugin return type without extension, which includes the plugin ID, name, and dependencies, but no extension.
RenderingOptionsRendering control options
SubCommandableSub-command entry type for use in subCommands.

References ​

CommandContextParams ​

Re-exports CommandContextParams


createCommandContext ​

Re-exports createCommandContext


define ​

Re-exports define


defineWithTypes ​

Re-exports defineWithTypes


lazy ​

Re-exports lazy


lazyWithTypes ​

Re-exports lazyWithTypes

Type Aliases ​

Type AliasDescription
ArgsValidationErrorCodeA machine-readable argument validation error code.
ArgValuesAn object that contains the values of the arguments.
AwaitableAwaitable type.
CommandableDefine a command type.
CommandCallModeCommand call mode.
CommandContextCoreReadonly command context available to a command context extension factory.
CommandDecoratorCommand decorator.
CommandExamplesFetcherCommand examples fetcher.
CommandLoaderCommand loader.
CommandNotFoundErrorCodeCommand not found error code.
CommandNotFoundErrorOptionsOptions for CommandNotFoundError.
CommandResolutionErrorCodeCommand resolution error code.
CommandResolutionErrorOptionsOptions for CommandResolutionError.
CommandRunnerCommand runner.
DefaultGunshiParamsDefault Gunshi parameters.
ExtendContextExtend command context type. This type is used to extend the command context with additional properties at CommandContext.extensions.
GunshiParamsConstraintGeneric constraint for command-related types.
LazyCommandLazy command interface.
OnPluginExtensionPlugin extension callback, which is called when the plugin is extended with extension option.
PluginGunshi plugin, which is a function that receives a PluginContext.
PluginExtensionPlugin extension
PluginFunctionPlugin function type
PrettifyPrettify a type by flattening its structure.
RendererDecoratorRenderer decorator type.
ValidationErrorsDecoratorValidation errors renderer decorator type. A function that wraps a validation errors renderer to add or modify its behavior.

Released under the MIT License.