当我运行命令node app.js --help
时,终端只显示添加命令,同时我已经定义了三个命令并且它们都有效。当我使用parse()
方法而不是argv
为什么我打印了 2 次“删除笔记”时?
const yargs = require('yargs');
yargs.command({
command:'add',
describe:'Adds new note',
handler:function(){
console.log('Adding a note')
}
}).argv;
yargs.command({
command:'remove',
describe:'Removes a note',
handler:function(){
console.log('Removing a note')
}
}).argv;
yargs.command({
command:'list',
describe:'Fetches a list of notes',
handler:function(){
console.log('Fetching a list')
}
}).argv;
Commands:
app.js add Adds new note
Options:
--help Show help [boolean]
--version Show version number [boolean]
PS C:\Users\Sanket\Documents\node js\notes-app>
PS C:\Users\Sanket\Documents\node js\notes-app> node app.js add
Adding a note
PS C:\Users\Sanket\Documents\node js\notes-app> node app.js remove
Removing a note
Removing a note
PS C:\Users\Sanket\Documents\node js\notes-app> node app.js list
Fetching a list
PS C:\Users\Sanket\Documents\node js\notes-app>