A simple interactive CLI builder
Project description
Paperplane
Paperplane allows you to build interactive CLIs straight from a configuration file (or a Python dict) without having to write your own code for I/O.
Supported configuration formats:
- YAML
- JSON
- Python dictionary
Installation
Assuming you have Python (>= 3.6), run:
pip install paperplane
Documentation
Full documentation is available at paperplane.readthedocs.io.
Features
- Collect interactive inputs and display styled output text based on simple configurations.
- Use the value from one input to calculate the default value for subsequent inputs.
- For example, collect a
username
input and usehttps://github.com/<io:username>
to auto-compute the default value for the subsequentgithub_url
input.
- For example, collect a
- Use the
<cwd>
macro to get the current working directory - Use the
<env:NAME>
macro to fetch the value for an environment variable.- Using the macro
<env:NAME1,NAME2>
will fetch the first available environment variable. Useful if, for example, if the environment variable names are different on Windows and Linux. Or simply, if you're unsure about which of them will be set.
- Using the macro
See the example config.yml below for more awesome features!
Getting Started
Configuration: config.yml
backend: click
io:
- name:
type: str
prompt: Your name
- username:
type: str
prompt: Your GitHub username
default: <env:USER,USERNAME>
- prompt1:
type: echo
prompt: |-
Hello, <io:name> (<io:username>)!
Your GitHub URL is https://github.com/<io:username>
Your current working directory is '<cwd>'
fg: green
- project_dir:
type: str
prompt: Enter project directory
default: <cwd>
- prompt2:
type: echo
prompt: Enter a name for your new project. It will be created at <io:project_dir>/<project name>
fg: blue
- project_name:
type: str
prompt: Project name
- feature_x:
type: choice
prompt: Do you want to enable feature X?
choices:
- 'Yes'
- 'No'
default: 'Yes'
Run:
paperplane collect /path/to/config.yml
If you have a JSON config file instead:
paperplane collect /path/to/config.json --format=json
If you want DEBUG level logs:
paperplane --debug collect /path/to/config.yml
Result:
Usage within a Python script
from paperplane import parse_and_execute
config = {
'backend': 'click',
'io': [{
'name': {
'type': 'str',
'prompt': 'Your name'
}
},
{
'username': {
'type': 'str',
'prompt': 'Your GitHub username',
'default': '<env:USER,USERNAME>'
}
},
{
'prompt1': {
'type': 'echo',
'prompt': "Hello, <io:name> (<io:username>)!\nYour GitHub URL is https://github.com/<io:username>\nYour current working directory is '<cwd>'",
'fg': 'green'
}
},
{
'project_dir': {
'type': 'str',
'prompt': 'Enter project directory',
'default': '<cwd>'
}
},
{
'prompt2': {
'type': 'echo',
'prompt': 'Enter a name for your new project. It will be created at <io:project_dir>/<project_name>',
'fg': 'blue',
}
},
{
'project_name': {
'type': 'str',
'prompt': 'Project name'
}
},
{
'feature_x': {
'type': 'choice',
'prompt': 'Do you want to enable feature X?',
'choices': ['Yes', 'No'],
'default': 'Yes',
}
}
]
}
values = parse_and_execute(config)
# Do your own stuff with the values
print(values)
Coming soon
- Tests
- Input validators
- Jinja2 template rendering in YAML config
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.
Source Distribution
paperplane-0.0.2.tar.gz
(107.7 kB
view details)
Built Distribution
File details
Details for the file paperplane-0.0.2.tar.gz
.
File metadata
- Download URL: paperplane-0.0.2.tar.gz
- Upload date:
- Size: 107.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f31aa6e0cf56d9817d2462413cf63029cd72bdd260777be4e82e83278e5ea2dc |
|
MD5 | 30f58350727968ceabc1d2a0d0fd908f |
|
BLAKE2b-256 | 68c10f95143c84a6d53d4413fa6ebcb57dbb1344568bd380daf5e7e7debef2d7 |
File details
Details for the file paperplane-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: paperplane-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 785db39d1e19524b41cd1b91cb082375e1af95d7fcfa25cdee67cab92160d5b2 |
|
MD5 | f63b5e3e91491e8e5a297ab9bb9d5cb5 |
|
BLAKE2b-256 | 159c836b2485ee35c7d1967d89aee2a657d85ee1f630017e9aaec9baa391cf30 |