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

Filter option for actions.prompt #198

Closed
wants to merge 1 commit into from
Closed

Conversation

passy
Copy link
Member

@passy passy commented Mar 27, 2013

I would like to propose a feature I found while digging around in grunt-init that did not have an equivalent in Yeoman.

The prompt should accept a filter option that allows to sanitize, validate or manipulate the value provided by the user.

Example Usage

var prompts = [{
  name: 'title',
  message: 'Project Title:',
  filter: function (value, cb) {
    // Callback expects (err, newValue)
    cb(null, value.replace(/jquery/i, 'jQuery'));
  }
}];

Benefit

While sanitizing data is already possible after the prompt is finished in the callback, this way makes it clearer to see where the manipulation is happening. Also, this allows to abort early if a value fails to validate.

@passy
Copy link
Member Author

passy commented Apr 5, 2013

/ping @sindresorhus

@sindresorhus
Copy link
Member

Should also have a pattern to quickly validate a prompt with regex.

But when thinking about this some more, why are we reinventing the wheel instead of using an existing prompt module? Like https://github.com/flatiron/prompt

@passy
Copy link
Member Author

passy commented Apr 6, 2013

Yes by all means. I'm on my phone and not sure where I mentioned this, but
Addy and I were wondering if reusing an existing prompt library in our
kickoff anyway. The API for that one looks pretty good.
On Apr 6, 2013 2:42 PM, "Sindre Sorhus" [email protected] wrote:

Should also have a pattern to quickly validate a prompt with regex.

But when thinking about this some more, why are we reinventing the wheel
instead of using an existing prompt module? Like
https://github.com/flatiron/prompt


Reply to this email directly or view it on GitHubhttps://github.com//pull/198#issuecomment-15995568
.

/ref yeoman#199

This changes the prompt API slightly and adds the following features:

    - `grunt-init` style coloring
    - `default` can be a function (in preperation of "magic defaults")
    - if `default` is a boolean, it will display a 'y/n' prompt with proper
      validation
    - validations occurs after a value is entered and not after the whole wizard
      completed
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.

2 participants