Shell
Introduction to the Shell Utilities
Prompting User Input
from cement import shell
### simple user response prompt
p = shell.Prompt("Press Enter To Continue", default='ENTER')
res = p.prompt()
### provide a numbered list for longer selections
p = shell.Prompt("Where do you live?",
options=[
'San Antonio, TX',
'Austin, TX',
'Dallas, TX',
'Houston, TX',
],
numbered = True)
res = p.prompt()
### Create a more complex prompt, and process the input
class MyPrompt(shell.Prompt):
class Meta:
text = "Do you agree to the terms?"
options = ['Yes', 'no', 'maybe-so']
options_separator = '|'
default = 'no'
clear = True
max_attempts = 99
def process_input(self):
if self.input.lower() == 'yes':
# do something crazy
pass
else:
# don't do anything... maybe exit?
print("User doesn't agree! I'm outa here")
p = MyPrompt()Executing Commands
Spawning Processes and Threads
Last updated