# 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)
- [.helpOption(flags, description)](#helpoptionflags-description)
- [.addHelpCommand()](#addhelpcommand)
- [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)
- [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
```bash
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));
```
```sh
$ 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();
```
```sh
$ 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.
```bash
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) console.log(options);
console.log('pizza details:');
if (options.small) console.log('- small pizza
没有合适的资源?快使用搜索试试~ 我知道了~
eclipse-committers-2022-06-R-win32-x86_64.zip
共2000个文件
js:3304个
ts:1037个
jar:787个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 70 浏览量
2022-06-18
16:26:17
上传
评论
收藏 482.15MB ZIP 举报
温馨提示
Eclipse IDE for Eclipse Committers(eclipse-committers-2022-06-R-win32-x86_64.zip) 适用于Windows x86_64: Package suited for development of Eclipse itself at Eclipse.org; based on the Eclipse Platform adding PDE, Git, Marketplace Client, source code and developer documentation.
资源推荐
资源详情
资源评论
收起资源包目录
eclipse-committers-2022-06-R-win32-x86_64.zip (2000个子文件)
e4-dark_globalstyle.css 9KB
e4-dark_ide_colorextensions.css 9KB
e4-light_ide_colorextensions.css 5KB
e4-light_ide_colorextensions.css 5KB
urls.css 5KB
e4-dark_win.css 5KB
sample.css 5KB
e4-dark_tabstyle.css 4KB
narrow_book.css 4KB
narrow_book.css 4KB
book.css 4KB
book.css 4KB
e4_system.css 3KB
e4-dark_partstyle.css 3KB
e4-dark_preferencestyle.css 3KB
e4-light_tabstyle.css 3KB
e4_default_mac.css 3KB
e4-dark_mac1013.css 3KB
e4-light_tabstyle.css 3KB
e4_default_gtk.css 3KB
e4-light_globalstyle.css 2KB
e4_default_win.css 2KB
e4-light_globalstyle.css 2KB
e4-dark_mac.css 2KB
e4_classic.css 2KB
e4-dark_linux.css 2KB
urls.css 2KB
urls.css 2KB
urls.css 1KB
urls.css 1KB
whatsnew.css 1KB
urls.css 1KB
e4_basestyle.css 1KB
high-contrast.css 875B
e4-light_partstyle.css 860B
e4-light_partstyle.css 860B
e4-light-drag-styling.css 831B
e4-light-drag-styling.css 831B
e4-dark-drag-styling.css 769B
e4_globalstyle.css 761B
disabled_book.css 356B
disabled_book.css 356B
macosx_narrow_book.css 269B
macosx_narrow_book.css 269B
migrate.css 188B
overview.css 177B
simple.css 99B
plugin.css 77B
postProcessor.css 44B
simple.css 24B
jvmti.h 82KB
AccessBridgePackages.h 76KB
jni.h 74KB
AccessBridgeCalls.h 35KB
classfile_constants.h 22KB
jawt.h 12KB
jdwpTransport.h 8KB
AccessBridgeCallbacks.h 5KB
jvmticmlr.h 5KB
jawt_md.h 2KB
jni_md.h 2KB
readme_eclipse.html 76KB
about.html 29KB
epl-v20.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-v20.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
epl-2.0.html 17KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
YunFeiDong
- 粉丝: 173
- 资源: 4045
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 35 财务汇报部门历年薪酬统计图表.xlsx
- 39 财务工资发放表.xlsx
- 37 财务工资支出上半年年中总结报告.xlsx
- 38 财务分析工资年度开支表.xlsx
- 41 财务公司部门工资开支分析表.xlsx
- 40 财务分析部门工资支出图表.xlsx
- 42 部门员工工资统计表.xlsx
- 45 年度薪酬费用统计表.xlsx
- 44 人事薪酬管理台账.xlsx
- 48 工资对比分析报表模板.xls
- 47 可视化工资表自动统计1.xlsx
- 46 企业员工工资支出预算表.xlsx
- 43 工资收入对比分析表.xlsx
- 50 薪资分析图表.xlsx
- 49 薪酬数据统计分析报表excel模板.xlsx
- 年度公司薪酬调查分析方案(完整版).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功