Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positional parameter and then command? #1720

Closed
BigBlueHat opened this issue Aug 21, 2020 · 2 comments
Closed

Positional parameter and then command? #1720

BigBlueHat opened this issue Aug 21, 2020 · 2 comments
Labels

Comments

@BigBlueHat
Copy link
Contributor

I've loved working with yargs! However, I've just hit a snag which I can't seem to get around.

I'd like to have a command line tool that works this way:

$ script-name example.com command
$ script-name example.com other-command

I can have a single default command (i.e. .command('$0') which can parse all that, but then I miss out on the power of yargs.

I did explore subcommands, but I can't seem to get them to handle everything past a first positional argument. Pseudo code of what I tried below:

require('yargs)
  .command('$0 [domain]', 'do awesomeness',
    (yargs) => {
      yargs
        .command('command', 'do specific stuff', () => {}, (argv) => { // take actions })
        .command('other-command', 'do other stuff', () => {}, (argv) => { // take other actions })
    },
    (argv) => {
      // do default stuff--i.e. no additional command
    });

Any ideas?

Thanks!
🎩

@bcoe bcoe added the question label Sep 10, 2020
@bcoe
Copy link
Member

bcoe commented Sep 10, 2020

@BigBlueHat the way commands are implemented is that they resolve to single command.

As a user of command line applications, I think this tends to be the expectation too, if you were going to do something compositional like this you'd tend to use | or > to combine multiple commands.

One option you might try would be a second full instance of yargs which parses the result of the first parse?

@shadowspawn
Copy link
Member

There is not support for a positional followed by a command. (And this is not a typical command-line pattern, although perfectly reasonable to ask!)

This issue has not had any activity in over six months. It isn't likely to get acted on due to this report.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants