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

feature-request: built-in prompts #26

Closed
jonschlinkert opened this issue Mar 6, 2017 · 2 comments
Closed

feature-request: built-in prompts #26

jonschlinkert opened this issue Mar 6, 2017 · 2 comments

Comments

@jonschlinkert
Copy link
Collaborator

jonschlinkert commented Mar 6, 2017

This is more of an idea for discussion. If any argument to .task after the first argument is a string that ends with ?, register it as a confirmation prompt, and conditionally run any arguments that follow if the prompt returns true.

Example:

composer.task('install', 'Want to install dependencies?', function(cb) {
  // this will only run if prompt is confirmed by user
  cb();
});

// or
composer.task('prompt-install', 'Want to install dependencies?', ['install', 'something', 'else']);

// or
composer.task('install', 'Want to install dependencies?', function(cb) {
  // run this if "true"
  cb();
}, function() {
  // run this if "false"
  cb();
});

The conventions for how "prompt tasks" work could differ from normal tasks.

Normally I would recommend this be done in a plugin or implementation, but after trying to create a plugin to do it, I'm thinking it would be really easy to do here. (Fwiw, I already have a working plugin that I can publish to npm if we decide to go that route. It just occurred to me that it would be awesome to have here as a built-in feature).

edit: the more I think about it, I think we should consider having Composer inherit from Enquirer, and have built-in support for all of the prompt types, or at least a handful of them. We just need to document how those prompt types work and expected behavior. This would make composer totally different than any other flow control library, and I think assemble, generate, verb and update users would really like this feature. It would also make composer more awesome for general CLI usage.

Ideas:

  • task and/or build can return the answers in the callback.
  • we can limit prompt functionality to specific conventions, like having the first and second args be strings
  • if composer inherits enquirer, we could allow prompts to be composed as tasks. Meaning that when task foo is run by build, composer would look for a prompt named foo and, if found, will run the prompt, otherwise, continue with the deps (how this is handled doesn't matter. composer might splice the prompt into the deps or something, but to the user it would be transparent)
@jonschlinkert jonschlinkert changed the title feature-request: confirm feature-request: built-in prompts Mar 6, 2017
@jonschlinkert
Copy link
Collaborator Author

jonschlinkert commented Mar 6, 2017

this would resolve some of the items in this checklist

@doowb
Copy link
Owner

doowb commented Mar 6, 2017

I like the idea of starting off with the confirmation prompt and going from there. I can already see how the code will work for based on the ideas above and the plugin you mentioned.

We could add additional prompts using the same convention (if second argument is a string ending with ?), and allowing the options to be passed into enquirer to specify the prompt type. Then instead of using y/n to determine which task function to run, the task function will just be run and this.answers will be populated with the answers. I think we can also return the answers in the .build callback when used directly.

@doowb doowb mentioned this issue Mar 7, 2017
@doowb doowb closed this as completed in #27 Mar 8, 2017
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

No branches or pull requests

2 participants