-
Notifications
You must be signed in to change notification settings - Fork 236
/
when.py
46 lines (38 loc) · 1.06 KB
/
when.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
When example
"""
from __future__ import print_function, unicode_literals
from PyInquirer import prompt, print_json
from examples import custom_style_2
def dislikes_bacon(answers):
# demonstrate use of a function... here a lambda function would be enough
return not answers['bacon']
questions = [
{
'type': 'confirm',
'name': 'bacon',
'message': 'Do you like bacon?'
},
{
'type': 'input',
'name': 'favorite',
'message': 'Bacon lover, what is your favorite type of bacon?',
'when': lambda answers: answers['bacon']
},
{
'type': 'confirm',
'name': 'pizza',
'message': 'Ok... Do you like pizza?',
'default': False, # only for demo :)
'when': dislikes_bacon
},
{
'type': 'input',
'name': 'favorite',
'message': 'Whew! What is your favorite type of pizza?',
'when': lambda answers: answers.get('pizza', False)
}
]
answers = prompt.prompt(questions, style=custom_style_2)
print_json(answers)