cac
- Version 6.7.14
- Published
- 81.8 kB
- No dependencies
- MIT license
Install
npm i cac
yarn add cac
pnpm add cac
Overview
Simple yet powerful framework for building command-line apps.
Index
Functions
Classes
Command
- action()
- alias()
- aliasNames
- allowUnknownOptions()
- args
- checkOptionValue()
- checkRequiredArgs()
- checkUnknownOptions()
- cli
- commandAction
- config
- description
- example()
- examples
- globalCommand
- hasOption()
- helpCallback
- ignoreOptionDefaultValue()
- isDefaultCommand
- isGlobalCommand
- isMatched()
- name
- option()
- options
- outputHelp()
- outputVersion()
- rawName
- usage()
- usageText
- version()
- versionNumber
Functions
function cac
cac: (name?: string) => CAC;
Parameter name
The program name to display in help and version message
Classes
class CAC
class CAC extends EventEmitter {}
constructor
constructor(name?: string);
Parameter name
The program name to display in help and version message
property args
args: readonly string[];
Parsed CLI arguments
property commands
commands: Command[];
property globalCommand
globalCommand: GlobalCommand;
property matchedCommand
matchedCommand?: Command;
property matchedCommandName
matchedCommandName?: string;
property name
name: string;
The program name to display in help and version message
property options
options: { [k: string]: any };
Parsed CLI options, camelCased
property rawArgs
rawArgs: string[];
Raw CLI arguments
property showHelpOnExit
showHelpOnExit?: boolean;
property showVersionOnExit
showVersionOnExit?: boolean;
method command
command: ( rawName: string, description?: string, config?: CommandConfig) => Command;
Add a sub-command
method example
example: (example: CommandExample) => this;
Add a global example.
This example added here will not be used by sub-commands.
method help
help: (callback?: HelpCallback) => this;
Show help message when
-h, --help
flags appear.
method option
option: (rawName: string, description: string, config?: OptionConfig) => this;
Add a global CLI option.
Which is also applied to sub-commands.
method outputHelp
outputHelp: () => void;
Output the corresponding help message When a sub-command is matched, output the help message for the command Otherwise output the global one.
method outputVersion
outputVersion: () => void;
Output the version number.
method parse
parse: (argv?: string[], { run }?: { run?: boolean | undefined }) => ParsedArgv;
Parse argv
method runMatchedCommand
runMatchedCommand: () => any;
method unsetMatchedCommand
unsetMatchedCommand: () => void;
method usage
usage: (text: string) => this;
Add a global usage text.
This is not used by sub-commands.
method version
version: (version: string, customFlags?: string) => this;
Show version number when
-v, --version
flags appear.
class Command
class Command {}
constructor
constructor( rawName: string, description: string, config: CommandConfig, cli: CAC);
property aliasNames
aliasNames: string[];
property args
args: CommandArg[];
property cli
cli: CAC;
property commandAction
commandAction?: (...args: any[]) => any;
property config
config: CommandConfig;
property description
description: string;
property examples
examples: CommandExample[];
property globalCommand
globalCommand?: GlobalCommand;
property helpCallback
helpCallback?: HelpCallback;
property isDefaultCommand
readonly isDefaultCommand: boolean;
property isGlobalCommand
readonly isGlobalCommand: boolean;
property name
name: string;
property options
options: Option[];
property rawName
rawName: string;
property usageText
usageText?: string;
property versionNumber
versionNumber?: string;
method action
action: (callback: (...args: any[]) => any) => this;
method alias
alias: (name: string) => this;
method allowUnknownOptions
allowUnknownOptions: () => this;
method checkOptionValue
checkOptionValue: () => void;
Check if the required string-type options exist
method checkRequiredArgs
checkRequiredArgs: () => void;
method checkUnknownOptions
checkUnknownOptions: () => void;
Check if the parsed options contain any unknown options
Exit and output error when true
method example
example: (example: CommandExample) => this;
method hasOption
hasOption: (name: string) => Option | undefined;
Check if an option is registered in this command
Parameter name
Option name
method ignoreOptionDefaultValue
ignoreOptionDefaultValue: () => this;
method isMatched
isMatched: (name: string) => boolean;
Check if a command name is matched by this command
Parameter name
Command name
method option
option: (rawName: string, description: string, config?: OptionConfig) => this;
Add a option for this command
Parameter rawName
Raw option name(s)
Parameter description
Option description
Parameter config
Option config
method outputHelp
outputHelp: () => void;
method outputVersion
outputVersion: () => void;
method usage
usage: (text: string) => this;
method version
version: (version: string, customFlags?: string) => this;
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (28)
- @babel/core
- @babel/plugin-syntax-typescript
- @rollup/plugin-commonjs
- @rollup/plugin-node-resolve
- @types/fs-extra
- @types/jest
- @types/mri
- cz-conventional-changelog
- esbuild
- eslint-config-rem
- execa
- fs-extra
- globby
- husky
- jest
- lint-staged
- markdown-toc
- mri
- prettier
- rollup
- rollup-plugin-dts
- rollup-plugin-esbuild
- semantic-release
- sucrase
- ts-jest
- ts-node
- typedoc
- typescript
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/cac
.
- Markdown[](https://www.jsdocs.io/package/cac)
- HTML<a href="https://www.jsdocs.io/package/cac"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4313 ms. - Missing or incorrect documentation? Open an issue for this package.