Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilash1in committed Sep 21, 2020
1 parent 1b4fb5e commit 75fde34
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,52 @@

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:
Paperplane orchestrates I/O operations by delegating work to different backends. Supported backends:
- [click](https://click.palletsprojects.com/)
- More backends coming soon!

Currently supports:
- Reading an int, string, boolean, one-of-many (choice) inputs.
- The `click` integration backend automatically calls [`click.prompt()`](https://click.palletsprojects.com/prompts/)
- Display a styled output (bold, foreground color, background color, etc)
- The `click` integration backend automatically calls [`click.secho()`](https://click.palletsprojects.com/api/#click.secho)

The I/O order and parameters (prompt, data type, available choices, default, etc) can be provided in the following formats:
- YAML
- JSON
- Python dictionary

See [Getting Started](#getting-started) for more info!

## Installation
Assuming you have Python (>= 3.6), run:
```
pip install paperplane
```

## Documentation
Full documentation is available at [paperplane.readthedocs.io](https://paperplane.readthedocs.io).
Preliminary documentation is available at [paperplane.readthedocs.io](https://paperplane.readthedocs.io).

Detailed documentation coming soon!

## 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 use `https://github.com/<io:username>` to auto-compute the default value for the subsequent `github_url` input.
- 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.
- Dynamic defaults and prompts (the question/message shown to the user) via macros.
- Use the value from one input to calculate the default value for subsequent inputs.
- For example, collect a `username` input and use `https://github.com/<io:username>` to auto-compute the default value for the subsequent `github_url` input.
- 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, the environment variable names are different on Windows and Linux. Or simply, if you're unsure about which of them will be set.

See the example **config.yml** below for more awesome features!

## Getting Started
Configuration:
Paperplane has a convenient `paperplane collect CONFIG_FILE` command that lets you run and test your config file. It triggers I/O operations based on the provided parameters and dumps the collected information to your terminal (Python dict format by default or alternatively, JSON) for debugging/verifying.

For usage inside a Python script, see [here](#usage-within-a-python-script).


To get started, create a new YAML configuration file as follows:
**config.yml**
```yaml
backend: click
Expand Down Expand Up @@ -67,26 +87,37 @@ io:
- 'No'
default: 'Yes'
```
Run:
To run and trigger I/O operations:
```
paperplane collect /path/to/config.yml
```

If you have a JSON config file instead:
Result:
![Sample Usage](assets/images/sample_usage.png)

---
If you want a JSON output (instead of the default Python dict dump):
```
paperplane collect /path/to/config.yml --json-out
```

If you have an input JSON config file instead of YAML:
```
paperplane collect /path/to/config.json --format=json
```
```

If you want DEBUG level logs:
```
paperplane --debug collect /path/to/config.yml
```

To see all available options:
```
paparplane --help
paparplane collect --help
```

Result:<br/>
![Sample Usage](assets/images/sample_usage.png)

#### Usage within a Python script
## Usage within a Python script
```python
from paperplane import parse_and_execute

Expand Down Expand Up @@ -145,10 +176,11 @@ config = {

values = parse_and_execute(config)

# Do your own stuff with the values
# Do your own stuff with the collected values
print(values)
```

## Coming soon
- Tests
- Input validators
- Jinja2 template rendering in YAML config
- Lazy Jinja2 template rendering in YAML config

0 comments on commit 75fde34

Please sign in to comment.