zouqi is a CLI starter similar to python-fire. It is purely built on argparse.
Project description
Zouqi: A Python CLI Starter Purely Built on argparse.
Zouqi (『走起』 in Chinese) is a CLI starter similar to python-fire. It is purely built on argparse.
Why not python-fire?
- Fire cannot be used to share options between commands easily.
- Fire treat all member functions as its command, which is not desirable in many situations.
Installation
pip install zouqi
Example
Code
import zouqi
from zouqi.parsing import ignored
def prettify(something):
return f"pretty {something}"
class Runner(zouqi.Runner):
def __init__(self):
super().__init__()
self.add_argument("who", type=str)
self.parse_args()
# (This is not a command.)
def show(self, action, something):
print(self.args.who, action, something)
# Decorate the command with the zouqi.command decorator.
@zouqi.command
def drive(self, something):
# Equivalent to: parser.add_argument('something').
# the parsed args will be stored in self.drive.args instead of self.args
self.show("drives a", something)
@zouqi.command
def wash(self, something, hidden_option: ignored = ""):
# hidden option will be ignored during parsing but still passable by another function
self.show("washes a", something + hidden_option)
@zouqi.command
def drive_and_wash(self, something: prettify = "car"):
# Equivalent to: parser.add_argument('--something', type=prettify, default='car').
# Type hint is used as argument parser (a little bit abuse of type hint here).
self.drive(something)
self.wash(something, ", good.")
if __name__ == "__main__":
Runner().run()
Runs
$ python3 example.py
usage: example.py [-h] {drive,drive_and_wash,wash} who
example.py: error: the following arguments are required: command, who
$ python3 example.py drive John car
John drives a car
$ python3 example.py drive_and_wash John --something truck
John drives a pretty truck
John washes a pretty truck, good.
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
zouqi-1.0.2.tar.gz
(3.7 kB
view details)
Built Distribution
zouqi-1.0.2-py3-none-any.whl
(5.0 kB
view details)
File details
Details for the file zouqi-1.0.2.tar.gz
.
File metadata
- Download URL: zouqi-1.0.2.tar.gz
- Upload date:
- Size: 3.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/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e89f56685ca79013021f7e0122e8aafaff28ab29fe136e0ae0202885c1a6edb6 |
|
MD5 | e7f867c5b2208fdfa62c6b2ce3a1b3b4 |
|
BLAKE2b-256 | 3c20f36c336eacb3fc33d5520903477ed4aa0ad62d583116b298555a0b07aa18 |
File details
Details for the file zouqi-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: zouqi-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.0 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/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6de31de68c834744fc9b83fa55867d00fbd6a7cdd7ed48b789455184f1b8dec7 |
|
MD5 | 0b97c471acf15214cd9c23c93aab5e17 |
|
BLAKE2b-256 | d687f58b5e34f7191ea2312eddb8ef1cb24deb174b3cd0b674ef7ee61c8bf151 |