-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·32 lines (29 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env node
// ==========================================================
const { Command } = require("commander");
const map = require("./src/map/index.js");
const docs = require("./src/docs/index.js");
const search = require("./src/search/index.js");
const version = require("./package.json").version;
// ==========================================================
// new Command()用于创建一个新的命令对象
const program = new Command();
program
// .argument("[type]", "search content")
.version(version, "-v, --version")
.argument("[content]", "Search something")
.action((content) => {
content && search(content);
});
// option用于添加参数
program
.option("-s, --search <content>", "Search something", search)
.option("-d, --doc", "open docs List", docs)
.option("-m, --map", "open map of Baidu", map);
// parse()方法会解析命令行参数,并将其存储在Command的args属性中
program.parse(process.argv);
// opts()用于获取命令行参数
const options = program.opts();
if (!process.argv.slice(2).length) {
program.help();
}