A package that contains a lot of presets for cli interfaces
Project description
cliutil
A pack of premade functions to make command-line user interfaces easier to build and take up less of your script
Documentation
Questions
CliUtil comes with a variety of built-in question formats. These are:
Question Function | Returns |
---|---|
yesnoquestion | Boolean |
stringquestion | String |
numberquestion | Float |
yesnoquestion
Ask a yes or no question
Argument | Type | Doc |
---|---|---|
text | String | The text of the question asked |
verify | Boolean | Should the user be given a chance to correct any mistakes? |
returns | Boolean | True or False depending on the y/N input of the user |
Example:
from cliutil.Questions import yesnoquestion
answer = yesnoquestion("Are you having a nice day", verify=True)
print(answer)
This will output
Are you having a nice day? y/N y
True
stringquestion
Ask for a string from the user
Argument | Type | Doc |
---|---|---|
text | String | The text of the question asked |
verify | Boolean | Should the user be given a chance to correct any mistakes? |
returns | String | The user input |
Example:
from cliutil.Questions import stringquestion
answer = stringquestion("How are you today?")
print(answer)
Will output
How are you today? Good
Good
numberquestion
Ask for a float from the user
Argument | Type | Doc |
---|---|---|
text | String | The text of the question asked |
verify | Boolean | Should the user be given a chance to correct any mistakes? |
returns | Float | The user input cast as a float |
Example:
from cliutil.Questions import numberquestion
answer = numberquestion("How many fingers am I holding up")
print(answer)
Will output
How many fingers am I holding up? 15
15.0
Command Line Argumet Handling
CliUtil comes with POSIX-complaint functions for handling command-line arguments.
clarguments
Handle arguments passed to the script through the command line. Any arguments with values will be returned as strings. Arguments with multiple values will have them comma separated inside of the string. Simple flags will have a value of type None.
Argument | Type | Doc |
---|---|---|
returns | Dict | Contains the variables and all the values assigned to them. Flags will have a None type. |
Example:
python script.py -Snp 1 -r 10 -b "str" arg2 --long arg1 arg3
Where script.py is
from cliutil.Arguments import clarguments
arguments = clarguments()
print(arguments)
Will output
{
'_args': 'arg2,arg3',
'S': None,
'n': None,
'p': '1',
'r': '10',
'b': 'str',
'long': 'arg1'
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.