我在跑步:
node app.js add
Run Code Online (Sandbox Code Playgroud)
我的代码是:
const yargs = require('yargs');
yargs.command({
command:'add',
describe:'Adding command',
handler:function(){
console.log('Adding notes');
},
})
Run Code Online (Sandbox Code Playgroud)
但是控制台上没有打印任何内容。
Iho*_*yuk 13
正如@jonrsharpe 在上面的评论中提到的那样。
尝试:
const yargs = require('yargs');
yargs
.command({
command:'add',
describe:'Adding command',
handler: argv => {
console.log('Adding notes');
}
})
.parse();
Run Code Online (Sandbox Code Playgroud)
或者
const yargs = require('yargs');
const argv = yargs
.command({
command: 'add',
describe: 'Adding command',
handler: argv => {
console.log('Adding notes');
}
})
.argv;
Run Code Online (Sandbox Code Playgroud)
node index.js add
小智 7
你必须提供yargs.parse(); 或 yargs.argv; 定义所有命令后。
const yargs = require('yargs');
yargs.command({
command:'add',
describe:'Adding command',
handler:function(){
console.log('Adding notes');
},
});
yargs.parse();
//or
yargs.argv;
Run Code Online (Sandbox Code Playgroud)
或者
You can .argv or .parse() specify individually
yargs.command({
command:'add',
describe:'Adding command',
handler:function(){
console.log('Adding notes');
},
}).parse() or .argv;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5142 次 |
| 最近记录: |