Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yargs help not displaying all the help options

I am using yargs to add command line options for the arguments passed to the script. When i issue the help command along with the script name, It does not display the help for add parameter.

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' }
like image 865
ryan Avatar asked Nov 07 '22 01:11

ryan


1 Answers

const yargs = require("yargs");

yargs.command({
  command: "add",
  describe: "Add new note",
  builder: {
    title: {
      // describe: 'note title',
      demandOption: true,
      type: "string"
    }
  },
  handler: function(argv) {
    console.log("My title: " + argv.title);
  }
});

yargs.parse();

Then run in the command line:

node filename.js add --title="title name"
like image 181
Harsh Agrahari Avatar answered Nov 14 '22 22:11

Harsh Agrahari