I'm testing out some yargs commands, but I am a bit confused on its usages. My code is:
const argv1 = require('yargs')
.command('testFunc', 'testing yargs stuff', (yargs) => {
yargs.option('age', {
description: 'number for age',
type: 'number'
})
console.log(` yargs section: ${yargs.name} | ${yargs.age}`);
}, (argv) => {
console.log(` argv section: ${argv.name} | ${argv.age}`);
}).argv;
Right now, if I run the command: node reporting-job-influx.js testFunc --name=Bob --age=1a
, I get the following output:
yargs section: undefined | undefined
argv section: Bob | NaN
So other than the yargs section unable to get the parameter data, what are the different purposes of having both a (yargs) => {}
and an (args) => {}
? And why can I still use a --name=Bob
value despite not declaring it in the options?
Also, what would be the difference with having the (yargs) => {...}
from above and moving the option up one level like this:
.command('testFunc2', 'testing yargs stuff', (yargs) => {}, (argv) => {
console.log(` argv section: ${argv.name} | ${argv.age}`);
})
.option('age', {
description: 'number for age',
type: 'number'
})
The output still verifies if --age
is a number so it looks to function the same way.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…