cac: 构建 CLI 应用程序的 JavaScript 库。
https://www.npmjs.com/package/cac
Command And C onquer 是一个用于构建 CLI 应用程序的 JavaScript 库。
Option
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
|
const cli = require('cac')('MyCli');
cli.option('--type <type>', 'Choose a project type', {
default: 'node',
});
cli.option('--name <name>', 'Provide your name');
cli.help();
cli.version('0.0.1');
const { options, args } = cli.parse();
console.log('name:', options.name);
console.log('type:', options.type);
console.log('args:', args);
|
Command
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
|
const cli = require('cac')('MyCli');
cli
.command('rm <dir>', 'Remove a dir')
.option('--name <name>', 'Provide your name')
.action((dir, options) => {
console.log('remove ', dir);
console.log('options ', options);
});
cli.help();
cli.version('0.0.1');
cli.parse();
|
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 33 34 35 36 37 38 39 40 41 42 43 44 45
|
const cli = require('cac')('MyCli');
cli
.command('rm <dir>', 'Remove a dir')
.option('--name <name>', 'Provide your name')
.action((dir, options) => {
console.log('remove ', dir);
console.log('options ', options);
});
cli
.command('build <entry1> <entry2> [...otherFiles]', 'Remove a dir')
.option('--name <name>', 'Provide your name')
.action((entry1, entry2, otherFiles, options) => {
console.log('entry1 ', entry1);
console.log('entry2 ', entry2);
console.log('otherFiles ', otherFiles);
console.log('options ', options);
});
cli.help();
cli.version('0.0.1');
cli.parse();
|