DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • node

    • NODE
    • parseArgs
    • compose
    • date-format
    • dayjs
    • encrypt
    • env-cmd
    • glob
    • Koa 洋葱模型
    • lodash
    • logger
    • log4js
    • mongod
    • nanoid
    • node-red
    • node-stream
    • node:test
    • nodemailer
    • nodemon
    • nodered
    • parse-curl
    • pm2
    • toml
    • ws
    • yargs
    • zx

yargs

Install

npm i yargs
npm i @types/yargs --save-dev
#!/usr/bin/env node
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const argv = yargs(hideBin(process.argv)).argv;
console.log(argv);
if (argv.ships > 3 && argv.distance < 53.5) {
  console.log('Plunder more riffiwobbles!');
} else {
  console.log('Retreat from the xupptumblers!');
}
➜  trader git:(master) ✗ npm run test ships --  --a=1 a 

> trader@1.0.0 test
> node app.js "ships" "--a=1" "a"

{ _: [ 'ships', 'a' ], a: 1, '$0': 'app.js' }
Retreat from the xupptumblers!

Refer

  • yargs.js.org
Last Updated:
Contributors: rosendo
Prev
ws
Next
zx