Add a simple query system

- Extend clint.textui.prompt with a query function.
- Add clint.textui.validators to validate the user input.
- Add a prompt example showing different usages.
- Update the README to demo the query function.
This commit is contained in:
Reto Aebersold
2014-05-08 17:18:10 -06:00
parent df7b9594a4
commit b99f79c98e
4 changed files with 166 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
from clint.textui import prompt, puts, colored, validators
if __name__ == '__main__':
# Standard non-empty input
name = prompt.query("What's your name?")
# Set validators to an empty list for an optional input
language = prompt.query("Your favorite tool (optional)?", validators=[])
# Use a default value and a validator
path = prompt.query('Installation Path', default='/usr/local/bin/', validators=[validators.PathValidator()])
puts(colored.blue('Hi {0}. Install {1} to {2}'.format(name, language or 'nothing', path)))