flowtool.ui

This module contains some functions for command line user interaction, that reach beyond the offerings of click (click.prompt, click.confirm).

flowtool.ui.abort(message, returncode=1)[source]

Abort the program, returning returncode as requested. By default the nonzero exit status 1 is returned.

class flowtool.ui.ChoiceItem(name, args)

Bases: tuple

args

Alias for field number 1

count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

name

Alias for field number 0

flowtool.ui.make_item(name, *values)[source]

Make a ChoiceItem. Currently only internal use. May come in use to customize the choice menu item later.

flowtool.ui.ask_choice(heading, choices, question, blind=None, answer=None)[source]

Ask the User for a choice from a list through numeric selection.

>>> ask_choice(
...     'What is the question?',
...     ['hah?', 'hum?', 'i dont understand...'],
...     'Your choice',
...     answer=2,
... )
What is the question?
1     hah?
2     hum?
3     i dont understand...
'hum?'
>>> ask_choice(
...     'Is there a question?',
...     [
...         ('hah?', 'c1'),
...         ('hum?', 'c2'),
...         ('i dont understand...', 'c3'),
...     ],
...     'Your choice',
...     answer=2,
... )
Is there a question?
1     hah?
2     hum?
3     i dont understand...
'c2'
>>> ask_choice(
...     '',
...     [
...         ('hah?', 'c1', 'args'),
...         ('hum?', 'c2', 'args'),
...         ('i dont understand...', 'c3', 'args'),
...     ],
...     'Your choice',
...     answer=2,
... )
1     hah?
2     hum?
3     i dont understand...
('hum?', 'c2', 'args')
>>> ask_choice(
...     '',
...     [
...         ('hah?', 'c3', 'args', 'orgs'),
...         ('hum?', 'c4', 'args', 'urgs'),
...         ('i dont understand...', 'c3', 'args', 'xrgx'),
...     ],
...     'Your choice',
...     blind=True,
...     answer=2,
... )
('hum?', 'c4', 'args', 'urgs')