You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try learn how to work this tool and requiresArg , and I've tried this example requires_arg.js but this is the result
$ node requires_arg.js
YError: Invalid second argument. Expected string or boolean but received object.
at c (/home/pi/Desktop/test/node_modules/yargs/build/index.cjs:1:2244)
at /home/pi/Desktop/test/node_modules/yargs/build/index.cjs:1:2096
at Array.forEach (<anonymous>)
at h (/home/pi/Desktop/test/node_modules/yargs/build/index.cjs:1:1993)
at Bt.usage (/home/pi/Desktop/test/node_modules/yargs/build/index.cjs:1:39503)
at Object.<anonymous> (/home/pi/Desktop/test/requires_arg.js:3:18)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
.
.
.
e [YError]: .usage() description must start with $0 if being used as alias for .command()
at Bt.usage (/home/pi/Desktop/test/node_modules/yargs/build/index.cjs:1:39703)
at Object.<anonymous> (/home/pi/Desktop/test/requires_arg.js:3:18)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
I wrote my ( based from this solution for other issue )version and run
Seems like it's because usage() changed how it works, Now it asks for the actual usage command as the first parameter like so:
yargs.usage("$0 [port]"), next would be description, builder and handler.
Your example works, but it doesn't provide the actual command or the allowed options, only the description. So I think something like this would be better:
varyargs=require('yargs/yargs')(process.argv.slice(2));varargv=yargs.usage('$0 [port]',"Load up a server").options({input: {description: 'Input file name',requiresArg: true,alias: 'i',},output: {description: 'Output file name',requiresArg: true,alias: 'o',},}).argv;yargs.showHelp();console.log('\n\nInspecting options');console.dir(argv);
And yea looks like yargs changed from short to alias.
I try learn how to work this tool and requiresArg , and I've tried this example requires_arg.js but this is the result
I wrote my ( based from this solution for other issue )version and run
I replace short with alias, because I don't found short on the documentation
The text was updated successfully, but these errors were encountered: