2

I am working on a CLI Project, where the user has to login before using any of its other commands. Below are the commands that the user will interact with.

  1. oms login -u username -p -a auth_url
  2. oms get -u url

When I'm trying to see the help for oms login , it is showing help for the oms get command.

const argv = require('yargs/yargs')(process.argv.slice(2))
    .usage('Usage: $0 <command> [options]')
    .command({
        command: "oms login",
        desc: "Login the User to OMS",
        builder: {
            username: {
                alias: 'u',
                demandOption: true

            },
            password: {
                alias: 'p',
                demandOption: true
            },
            auth_url: {
                alias: 'a',
                demandOption: true
            }
        },
        handler: (argv) => console.log(argv),
    })
    .command({
        command: "oms get",
        desc: "Get the Status",
        builder: {
            url: {
                alias: 'u',
                demandOption: true
            }
        },
        handler: (argv) => console.log(argv),
    })
    .help('h')
    .alias('h', 'help')
    .wrap(null)
    .argv;

Help from oms login

PS F:\node\REST-CLI\cli> node .\index.js oms login --help
index.js oms get

Get the Status

Options:
      --version  Show version number  [boolean]
  -h, --help     Show help  [boolean]
  -u, --url  [required]

Help from oms get

PS F:\node\REST-CLI\cli> node .\index.js oms get --help
index.js oms get

Get the Status

Options:
      --version  Show version number  [boolean]
  -h, --help     Show help  [boolean]
  -u, --url  [required]

I'm using above code, Kindly let me know me where I'm doing the mistake. Thanks

Aditya
  • 21
  • 3
  • I'm guessing it's because command names can't have spaces in them. If you want sub-commands you have to make a oms command, and then in the handler for that you want to define the commands `get` and `login`. – karizma Aug 20 '21 at 20:14

0 Answers0