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

Use sade for sub-commands and inquirer for prompting. #32

Merged
merged 6 commits into from
Jun 12, 2019
Merged

Conversation

treshugart
Copy link
Contributor

@treshugart treshugart commented Jun 11, 2019

This should retain pretty much 100% compatibility. I'll do a final check before merging.

Why remove meow?

  • Doesn't support sub-commands.
  • Help doesn't print command description or option documentation.

Why not commander (i.e. "it's popular")?

I'm compiling this from recent experience and memory:

  • No clear way of having global options and apply to sub-commands. They seemed to be undefined as part of the action() arguments and you'd have to somehow refer to the global parsed options, but there wasn't any validation on them.
  • Sub-commands cannot alias a default command (i.e. cmd being equivalent to cmd default). Maybe it does do this, but its docs weren't clear to me. Having this not only retains backward compatibility, it also enables simpler use-cases where you only need one command.

Why sade?

  • Luke Edwards writes some really awesome, small, focused and robust stuff.
  • It's basically commander but supports what we want.
  • In comparison to meow, it's very simple to write an option-based API over it without creating a maintenance burden. commander also makes this pretty simple, sade just supports stuff we want out of the box.

Why inquirer?

  • It's popular (~12m dls / month).
  • Seems to have everything we need, so no reason to choose another.

What does it look like?

See the README for bin but gist:

  • It supports options like before, but now allows an option.question config that it passes to inquirer.
  • It supports a new commands option for defining sub-commands which can contain a description and an options object for command-specific options and questions.
  • A default sub-command is specified allowing it to be invoked without specifying a command (existing and simple behaviour).
  • If you do not specify an option, and it has a corresponding question, you will be prompted to fill it in by inquirer.
bin({
  options: {
    global: {
      question: {
        message: 'Yay?',
        type: 'confirm'
      }
    }
  },
  commands: {
    default: {
      options: {
        question: {
          message: 'Yay?',
          type: 'confirm'
        }
      }
    }
  }
})

@treshugart treshugart merged commit ea0ebed into master Jun 12, 2019
@treshugart treshugart deleted the prompting branch June 12, 2019 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant