5

yargsを使用して、スクリプトに渡される引数のコマンド ライン オプションを追加しています。スクリプト名とともに help コマンドを発行すると、パラメーターの追加に関するヘルプが表示されません。

const yargs=require('yargs');
 const argv= yargs.command('add', 'ADD A NOTE TO A FILE', {
    title : {
        describe : 'title of the file',
        demand: 'true'
    }
})
.help()
.argv;




root# node mainFile_node.js --help
Options:
  --help     Show help                                                 [boolean]
  --version  Show version number

     node mainFile_node.js add
YARGS ARGV:-{ _: [ 'add' ], '$0': 'mainFile_node.js' }
4

6 に答える 6

0
yargs.command({
command: 'add',

showInHelp: true, //add this line here!!!

describe: 'add a note',
builder: {
    title: {
        describe: 'title of my note',
        demandOption: true,
        type: 'string',
        
        
    },
    body: {
        describe: 'body note',
        demandOption: true,
        type: 'string',
        

        
    }
},

handler: function (argv) {
    console.log(argv.title,'\n', argv.body, '\n creating the note', argv)
}
})
于 2021-11-14T17:51:20.140 に答える