为什么终端不显示其他yargs命令?

时间:2020-04-18 19:48:43

标签: node.js yargs

当我运行命令FirebaseOptions时,终端仅显示add命令,而我定义了三个命令,所有这些命令均有效。当我使用node app.js --help方法而不是parse()时,为什么我会打印2次“删除便笺”?

argv

1 个答案:

答案 0 :(得分:0)

您正在调用.argv,这将在调用help之前定义其他进程之前停止该过程。

从您创建的最后一个命令定义中删除.argv是最简单的解决方法。

const yargs = require('yargs');


yargs.command({
    command:'add',
    describe:'Adds new note',
    handler:function(){
    console.log('Adding a note')
    }
});

yargs.command({
    command:'remove',
    describe:'Removes a note',
    handler:function(){
    console.log('Removing a note')
    }
 });

yargs.command({
    command:'list',
    describe:'Fetches a list of notes',
    handler:function(){
    console.log('Fetching a list')
    }
 }).argv;