# 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)
- [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)
- [.usage and .name](#usage-and-name)
- [.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)
- [Override exit and output handling](#override-exit-and-output-handling)
- [Additional documentation](#additional-documentation)
- [Examples](#examples)
- [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
```
## 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
const { program } = require('commander');
program.version('0.0.1');
```
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
const { Command } = require('commander');
const program = new Command();
program.version('0.0.1');
```
For named imports in ECMAScript modules, import from `commander/esm.mjs`.
```js
// index.mjs
import { Command } from 'commander/esm.mjs';
const program = new Command();
```
And in TypeScript:
```ts
// index.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.
(You can also use `.getOptionValue()` and `.setOptionValue()` to work with a single option value,
and `.getOptionValueSource()` and `.setOptionValueWithSource()` when it matters where the option value came from.)
Multi-word options such as "--template-engine" are camel-cased, becoming `program.opts().templateEngine` etc.
Multiple short flags may optionally be combined in a single argument following the dash: boolean flags, followed by a single option taking a value (possibly followed by the value).
For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.
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.
### 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 size');
if (options.pizzaType) console.log(`- ${options.pizzaType}`);
```
```bash
$ pizza-options -p
error: option '-p, --pizza-type <type>' argument missing
$ pizza-options -d -s -p vegetarian
{ debug: true, small: true, pizzaType: 'vegetarian' }
pizza details:
- small pizza size
- vegetarian
$ pizza-options --pizza-type=cheese
pizza details:
- cheese
```
`program.parse(arguments)` processes the arguments, leaving any args not consumed by the program options in the `program.args` array. The parameter is optional and defaults to `process.argv`.
### Default option value
You can specify a default value for an option which takes a value.
Example file: [options-defaults.js](./examples/options-defaults.js)
```js
program
.option('-c, --cheese <type>', 'add the specified type of cheese', 'blue');
program.parse();
console.log(`cheese: ${program.opts().cheese}`);
```
```bash
$ pizza-options
cheese: blue
$ pizza-options --cheese stilton
cheese: stilton
```
### Other option types, negatable boolean and boolean|value
You can define a boolean option long name with a leading `no-` to set the option value to false when used.
Defined alone this also makes the option true by default.
If you define `--foo` first, adding `--no-foo` does not change the default value from what it would
otherwise be. You can specify a default boolean value for a boolean option and it can be overridden on command line.
Example file: [options-negatable.js](./examples/options-negatable.js)
```js
program
.option('--no-sauce', 'Remove sauce')
.option('--cheese <flavour>', 'cheese flavour', 'mozzarella')
.option('--no-cheese', 'plain with no cheese')
.parse();
const options = program.opts();
const sauceStr = options.sauce ? 'sauce' : 'no sauce';
const cheeseStr = (options.cheese === false) ? 'no cheese' : `${options.cheese} cheese`;
console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
```
```bash
$ pizza-options
You ordered a pizza with sauce and mozzarella cheese
$ pizza-options --sauce
error: unknown option '--sauce'
$ pizza-options --cheese=blue
You ordered a pizza with sauce and blue cheese
$ pizza-options --no-sauce --no-cheese
You ordered a pizza with no sauce and no cheese
```
You can specify an option which may be used as a boolean option but may optionally take an option-argument
(declared with square brackets like `--optional
没有合适的资源?快使用搜索试试~ 我知道了~
2020软件数据库与信息系统课程设计.zip
共567个文件
js:165个
md:69个
json:59个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 37 浏览量
2024-04-23
09:37:15
上传
评论
收藏 5.39MB ZIP 举报
温馨提示
数据库课程设计 在信息方面,需要对学生的信息能够了解,能够方便以后的课程教学中可以对自己进行改进。 在处理方面,当学生的信息出错时,老师能对信息进行修改。比如学生团支部更改、学生有转校、转系、转专业等,老师可以根据实际情况进行更新。需要的操作是修改、删除、增加。老师能够更改课程名、课程时长以及课程对应的学分的修改、删除、增加等等。 在安全性与完整性要求方面,系统需要设置访问用户的表示以鉴别是否为合法用户,并按照要求设置用户密码,以防止用户账号被盗用,系统也应该应对不同用户设置不同的访问权限及等级,区分教职工和学生。为了保证信息的完整性,在录入信息时,系统的各项内容不能为空,各项信息数据应保证准确正确,相同数据在不同记录中应一致。 2.1.2对于学生来说 在信息方面,学生能够查询自己的个人信息,确保学生信息的正确性。还可以查询学生的课程信息及学生培养信息,以便于学生能够了解学习目标及目的。还可以修改学生信息。 在处理方面,学生除了能够查询自己成整体信息外,还能够修改学生信息。当学生查询信息发现学生个人信息比如姓名、年龄等出错时学生可以根据个人情况进行修改、删除等。 2.2数据需求
资源推荐
资源详情
资源评论
收起资源包目录
2020软件数据库与信息系统课程设计.zip (567个子文件)
he.1 3KB
acorn 60B
AUTHORS 169B
index.cjs 41KB
html-minifier-terser.cmd 384B
terser.cmd 361B
he.cmd 348B
sample-cli-config-file.conf 1KB
global.css 380B
tree.css 198B
5.23日志.docx 1.57MB
5.23日志.docx 1.57MB
validateTableData.js.flow 993B
validateConfig.js.flow 900B
calculateMaximumColumnWidthIndex.js.flow 649B
alignTableData.js.flow 503B
drawRow.js.flow 356B
stringifyTableData.js.flow 201B
gredis.go 28KB
memberDao.go 2KB
ginselete.go 2KB
adminDao.go 1KB
ceshi.go 1KB
ceshi.go 1KB
familyDao.go 1KB
member.go 1KB
cors.go 1KB
update.go 1021B
update.go 1021B
setting.go 1017B
response.go 943B
admin.go 932B
test6.go 901B
helper.go 816B
dao.go 778B
member.go 717B
model.go 680B
ginupdate.go 560B
test5.go 548B
test5.go 548B
gindelete.go 543B
menuDao.go 522B
family.go 514B
code.go 487B
connect.go 460B
connect.go 460B
test11.go 452B
memberRouters.go 448B
admin.go 433B
routers_init.go 431B
test1.go 429B
test1.go 429B
main.go 423B
main.go 407B
family.go 395B
test`.go 351B
test3.go 339B
test8.go 311B
statusRouters.go 306B
test10.go 304B
staffRouters.go 297B
da.go 266B
test2.go 264B
test9.go 259B
test4.go 246B
setup.go 244B
msg.go 235B
menu.go 231B
menu.go 194B
test7.go 184B
loginRouter.go 168B
menuRouter.go 167B
get_msg.go 131B
cache.go 101B
he 4KB
he 336B
goodjob.html 118KB
denglu.html 2KB
denglu.html 2KB
test3.html 1KB
test3.html 1KB
布局.html 843B
布局.html 843B
index.html 628B
test5.html 521B
test5.html 521B
test1.html 507B
test2.html 472B
test2.html 472B
test4.html 472B
test.html 296B
testr.html 273B
html-minifier-terser 408B
favicon.ico 5KB
favicon.ico 5KB
favicon1.ico 4KB
app.ini 276B
login5.jpg 426KB
pre.jpg 320KB
login4.jpg 47KB
共 567 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
野生的狒狒
- 粉丝: 2722
- 资源: 2219
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功