Reputation: 19810
I'm playing with yargs as would like to configure the following command line options:
Usage: myapp <source file> [destination file]
No options, no commamnds, etc. Just takes a file path to read from and an optional one to write to. What's the yarg config that gets me that and gives me all the nice documentation?
Seems like I either need to use an option or a command. Can't I just pass in the file argument on its own?
Couldn't see how to do this with commander either. Trying to trade up from process.argv
, but stuck at the first hurdle.
Upvotes: 2
Views: 2949
Reputation: 24600
Here is an example how to get the first and second parameters:
var argv=require('yargs').argv
var source=argv._[0]
var dest=argv._[1]
Or even a better way:
const argv = require("yargs").command(
"$0 <source file> [destination file]",
"the default command",
() => {},
function({ sourcefile, destinationfile }) {
console.log({ sourcefile, destinationfile })
},
).argv
$0
is the default command.
The output should be:
myapp.js <source file> [destination file]
the default command
Options:
--help Show help [boolean]
--version Show version number [boolean]
Not enough non-option arguments: got 0, need at least 1
Upvotes: 1