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

#132 Override questions with prompts.override #144



Copy link

lumio commented Feb 21, 2019

Allows to skip questions if answers are provided and are valid.


This comment has been minimized.

Copy link

terkelg commented Feb 23, 2019

Thank you @lumio – sorry I'm a bit slow because of the relocating.
Can you provide an example of when this is useful?


This comment has been minimized.

Copy link
Collaborator Author

lumio commented Feb 23, 2019

No worries.

So basically what @jkwohlfahrt wanted in #132 was a way to override questions in a programatically way. Similar to inject but on a field-name base.

I needed something similar for a terminal program too where I usually want the user to specify arguments, so they can quickly run a task without getting shown the prompts and quickly get their job done. However, if they missed an argument, the prompt should still be rendered.

It's basically what flatiron/prompt does with prompt.override although I haven't looked into the implementation of it specifically.

I didn't want to change the behaviour of inject as it was meant for testing only and it works in a different way.

override really overrides the input of existing fields and in combination with e.g. yargs you can easily pass given arguments on.

As an example I added a little code snippet:

const prompts = require('prompts');

// Passing all arguments that was given to `node file.js` with `--argument` or what not.

// Regular questionnaire
const response = await prompts([
    type: 'text',
    name: 'twitter',
    message: `What's your twitter handle?`
    type: 'multiselect',
    name: 'color',
    message: 'Pick colors',
    choices: [
      { title: 'Red', value: '#ff0000' },
      { title: 'Green', value: '#00ff00' },
      { title: 'Blue', value: '#0000ff' }

// Calling the script as `node file.js --twitter "terkelg"` would
// skip the first question and jump right to the next one.

This comment has been minimized.

Copy link

terkelg commented Feb 24, 2019

Thank you! Really awesome and good idea to add that to the readme. 👍 💯

@terkelg terkelg merged commit 6c55528 into terkelg:master Feb 24, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.