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
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 args
self.show("drives a", something)
@zouqi.command
def wash(self, something):
self.show("washes a", something)
@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)
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
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.1.tar.gz
(3.5 kB
view details)
File details
Details for the file zouqi-1.0.1.tar.gz
.
File metadata
- Download URL: zouqi-1.0.1.tar.gz
- Upload date:
- Size: 3.5 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 | 08a2394055e6c743a72e541ce736c1619bc2287c084c82ecb1c3953b1f02f04f |
|
MD5 | faae795856e7cf22c844f11ad42c4809 |
|
BLAKE2b-256 | 65ffecb18bb1587284e20810a2719e716e93dc9cc7dcc9139481b138bfcd2645 |