Skip to content

Make prompts when support function. #385

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

Closed
wants to merge 5 commits into from
Closed

Conversation

likun7981
Copy link

@likun7981 likun7981 commented Mar 8, 2017

Now we only set prompts when is an attribute from the other prompts , and the prompt must be a boolean . but sometimes we want set the when to a special value, when a prompt choice the value , we return a boolean.
so I resolve this problem; I through this example to illustrate;

previously , we can only set prompt like this

q1: {
  type: 'confirm',
  require: true,
  message: 'this is a question?',
  default: true
},
q2: {
  when: 'q1',
  type: 'list',
  message: 'Which choice ?',
  choices:[] // some choices
}

If q1 is not a confirm , it is a list, like this

q1: {
  type: 'list',
  message: 'make choice?',
  choices:['c1','c2'] // some choices
},
q2: {
  when: ????,
  type: 'list',
  message: 'Which choice ?',
  choices:[] // some choices
}

now we want to when q1 choice c1 , then ask q2, otherwise do not ask q2;

so when should like inquirer to support set function value to when

we can set like this:

q1: {
  type: 'list',
  message: 'make choice?',
  choices:['c1','c2'] // some choices
},
q2: {
  when: function(answers){
    return answers.q1 === 'c1';
  },
  type: 'list',
  message: 'Which choice ?',
  choices:[] // some choices
}

@posva
Copy link
Member

posva commented Mar 8, 2017

Can you add a test for this, please? 🙂

@likun7981
Copy link
Author

The test is ok

@posva
Copy link
Member

posva commented Mar 9, 2017

ping @egoist @zigomir

@zigomir
Copy link
Contributor

zigomir commented Mar 13, 2017

Looks good to me! I only maybe miss a test case that exercises previous when functionality. I know this is not a concern for this PR, but it might be useful to prevent any regressions.

@yyx990803
Copy link
Member

Thanks for the PR and sorry for letting it sit for so long. As of now, we are no longer adding new features of vue-cli 2.x, so I am closing this PR. Again, thanks for the contribution.

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.

4 participants