# Commander.js
[![Build Status](https://github.com/tj/commander.js/workflows/build/badge.svg)](https://github.com/tj/commander.js/actions?query=workflow%3A%22build%22)
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://npmcharts.com/compare/commander?minimal=true)
[![Install Size](https://packagephobia.now.sh/badge?p=commander)](https://packagephobia.now.sh/result?p=commander)
The complete solution for [node.js](http://nodejs.org) command-line interfaces.
Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
- [Commander.js](#commanderjs)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Declaring _program_ variable](#declaring-program-variable)
- [Options](#options)
- [Common option types, boolean and value](#common-option-types-boolean-and-value)
- [Default option value](#default-option-value)
- [Other option types, negatable boolean and boolean|value](#other-option-types-negatable-boolean-and-booleanvalue)
- [Required option](#required-option)
- [Variadic option](#variadic-option)
- [Version option](#version-option)
- [More configuration](#more-configuration)
- [Custom option processing](#custom-option-processing)
- [Commands](#commands)
- [Command-arguments](#command-arguments)
- [More configuration](#more-configuration-1)
- [Custom argument processing](#custom-argument-processing)
- [Action handler](#action-handler)
- [Stand-alone executable (sub)commands](#stand-alone-executable-subcommands)
- [Life cycle hooks](#life-cycle-hooks)
- [Automated help](#automated-help)
- [Custom help](#custom-help)
- [Display help after errors](#display-help-after-errors)
- [Display help from code](#display-help-from-code)
- [.name](#name)
- [.usage](#usage)
- [.description and .summary](#description-and-summary)
- [.helpOption(flags, description)](#helpoptionflags-description)
- [.helpCommand()](#helpcommand)
- [More configuration](#more-configuration-2)
- [Custom event listeners](#custom-event-listeners)
- [Bits and pieces](#bits-and-pieces)
- [.parse() and .parseAsync()](#parse-and-parseasync)
- [Parsing Configuration](#parsing-configuration)
- [Legacy options as properties](#legacy-options-as-properties)
- [TypeScript](#typescript)
- [createCommand()](#createcommand)
- [Node options such as `--harmony`](#node-options-such-as---harmony)
- [Debugging stand-alone executable subcommands](#debugging-stand-alone-executable-subcommands)
- [npm run-script](#npm-run-script)
- [Display error](#display-error)
- [Override exit and output handling](#override-exit-and-output-handling)
- [Additional documentation](#additional-documentation)
- [Support](#support)
- [Commander for enterprise](#commander-for-enterprise)
For information about terms used in this document see: [terminology](./docs/terminology.md)
## Installation
```sh
npm install commander
```
## Quick Start
You write code to describe your command line interface.
Commander looks after parsing the arguments into options and command-arguments,
displays usage errors for problems, and implements a help system.
Commander is strict and displays an error for unrecognised options.
The two most used option types are a boolean option, and an option which takes its value from the following argument.
Example file: [split.js](./examples/split.js)
```js
const { program } = require('commander');
program
.option('--first')
.option('-s, --separator <char>');
program.parse();
const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
```
```console
$ node split.js -s / --fits a/b/c
error: unknown option '--fits'
(Did you mean --first?)
$ node split.js -s / --first a/b/c
[ 'a' ]
```
Here is a more complete program using a subcommand and with descriptions for the help. In a multi-command program, you have an action handler for each command (or stand-alone executables for the commands).
Example file: [string-util.js](./examples/string-util.js)
```js
const { Command } = require('commander');
const program = new Command();
program
.name('string-util')
.description('CLI to some JavaScript string utilities')
.version('0.8.0');
program.command('split')
.description('Split a string into substrings and display as an array')
.argument('<string>', 'string to split')
.option('--first', 'display just the first substring')
.option('-s, --separator <char>', 'separator character', ',')
.action((str, options) => {
const limit = options.first ? 1 : undefined;
console.log(str.split(options.separator, limit));
});
program.parse();
```
```console
$ node string-util.js help split
Usage: string-util split [options] <string>
Split a string into substrings and display as an array.
Arguments:
string string to split
Options:
--first display just the first substring
-s, --separator <char> separator character (default: ",")
-h, --help display help for command
$ node string-util.js split --separator=/ a/b/c
[ 'a', 'b', 'c' ]
```
More samples can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
## Declaring _program_ variable
Commander exports a global object which is convenient for quick programs.
This is used in the examples in this README for brevity.
```js
// CommonJS (.cjs)
const { program } = require('commander');
```
For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use.
```js
// CommonJS (.cjs)
const { Command } = require('commander');
const program = new Command();
```
```js
// ECMAScript (.mjs)
import { Command } from 'commander';
const program = new Command();
```
```ts
// TypeScript (.ts)
import { Command } from 'commander';
const program = new Command();
```
## Options
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('|').
The parsed options can be accessed by calling `.opts()` on a `Command` object, and are passed to the action handler.
Multi-word options such as "--template-engine" are camel-cased, becoming `program.opts().templateEngine` etc.
An option and its option-argument can be separated by a space, or combined into the same argument. The option-argument can follow the short option directly or follow an `=` for a long option.
```sh
serve -p 80
serve -p80
serve --port 80
serve --port=80
```
You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.
By default, options on the command line are not positional, and can be specified before or after other arguments.
There are additional related routines for when `.opts()` is not enough:
- `.optsWithGlobals()` returns merged local and global option values
- `.getOptionValue()` and `.setOptionValue()` work with a single option value
- `.getOptionValueSource()` and `.setOptionValueWithSource()` include where the option value came from
### Common option types, boolean and value
The two most used option types are a boolean option, and an option which takes its value
from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line.
Example file: [options-common.js](./examples/options-common.js)
```js
program
.option('-d, --debug', 'output extra debugging')
.option('-s, --small', 'small pizza size')
.option('-p, --pizza-type <type>', 'flavour of pizza');
program.parse(process.argv);
const options = program.opts();
if (options.debug
没有合适的资源?快使用搜索试试~ 我知道了~
java毕业设计 基于SpringCloud+Vue服务架构的宠物短视频社区小程序源码+详细文档+全部资料(优秀项目)
共2000个文件
js:1148个
java:354个
json:274个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 59 浏览量
2024-04-16
14:09:03
上传
评论
收藏 5.73MB ZIP 举报
温馨提示
【资源说明】 java毕业设计 基于SpringCloud Alibaba(gatewaynacos)、MyBatis-Plus、Redis、Druid、Knife4j、Vue、ElementUI、Ant Design mini微服务架构的宠物短视频社区小程序【本科毕设】源码+详细文档+全部资料(优秀项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为毕设项目、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 3、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
java毕业设计 基于SpringCloud+Vue服务架构的宠物短视频社区小程序源码+详细文档+全部资料(优秀项目) (2000个子文件)
ie.html 23KB
index.html 5KB
test.mock.html 2KB
noop.html 77B
tslib.es6.html 36B
tslib.html 32B
ExcelUtil.java 50KB
Convert.java 25KB
UserBanExample.java 22KB
HTMLFilter.java 19KB
UserBlockExample.java 18KB
GenTableServiceImpl.java 17KB
SysUserServiceImpl.java 15KB
UUID.java 15KB
SysMenuServiceImpl.java 15KB
ReflectUtils.java 14KB
VelocityUtils.java 14KB
StringUtils.java 14KB
SysUserController.java 12KB
SysRoleServiceImpl.java 11KB
IpUtils.java 11KB
WxHomeServiceImpl.java 10KB
SysDeptServiceImpl.java 9KB
AuthLogic.java 9KB
Base64.java 9KB
ServletUtils.java 9KB
LogAspect.java 9KB
GenUtils.java 8KB
SysRoleController.java 8KB
GenTableColumn.java 8KB
GenTable.java 8KB
WxHomeMapper.java 8KB
WxUserServiceImpl.java 7KB
SysJobServiceImpl.java 7KB
SysUser.java 7KB
SysJobController.java 7KB
WxHomeController.java 7KB
FileUtils.java 7KB
GenController.java 6KB
RedisService.java 6KB
SwaggerProperties.java 6KB
FileUploadUtils.java 6KB
UserRoleVo.java 6KB
OSSServiceImpl.java 6KB
DataScopeAspect.java 6KB
SysDictTypeServiceImpl.java 6KB
GlobalExceptionHandler.java 6KB
SysRole.java 6KB
SysConfigServiceImpl.java 6KB
SysLoginService.java 6KB
UserInfoController.java 6KB
JobInvokeUtil.java 6KB
SysProfileController.java 5KB
SysMenuController.java 5KB
SysMenu.java 5KB
WxGoodsServiceImpl.java 5KB
SwaggerAutoConfiguration.java 5KB
SysOperLog.java 5KB
ScheduleUtils.java 5KB
XssFilter.java 5KB
TokenService.java 5KB
WxGoodsController.java 5KB
SysDeptController.java 5KB
UserPet.java 5KB
DateUtils.java 5KB
AuthFilter.java 5KB
SysJob.java 5KB
SysConfigController.java 4KB
ISysUserService.java 4KB
HttpClientUtil.java 4KB
EscapeUtil.java 4KB
SysDictTypeController.java 4KB
AjaxResult.java 4KB
SysDictData.java 4KB
SysPostController.java 4KB
SysDept.java 4KB
SysPostServiceImpl.java 4KB
CaptchaConfig.java 4KB
WxGoodsMapper.java 4KB
SysDictDataController.java 4KB
Excel.java 4KB
AuthUtil.java 4KB
UserContentController.java 4KB
UserCommentController.java 4KB
ValidateCodeServiceImpl.java 4KB
GenConstants.java 4KB
ISysRoleService.java 4KB
UserLiveController.java 3KB
StrFormatter.java 3KB
SysLogininforController.java 3KB
AbstractQuartzJob.java 3KB
SysJobLog.java 3KB
SpringUtils.java 3KB
ISysMenuService.java 3KB
WechatUtil.java 3KB
UserComment.java 3KB
BaseController.java 3KB
SysUserOnlineController.java 3KB
SysPost.java 3KB
SysNoticeController.java 3KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
不走小道
- 粉丝: 3206
- 资源: 5122
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 937712277954201实习5.word
- 2程序语言基础知识pdf1_1716337722703.jpeg
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功