Skip to main content

zouqi is a CLI starter similar to [python-fire](https://github.com/google/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.

Example

Code

import zouqi


class Runner(zouqi.Runner):
    def __init__(self):
        self.add_argument("who")

        # Call init after argument adding to make sure it is updated.
        super().__init__()

    # (This is not a command.)
    def show(self, action):
        print(self.args.who, action, self.args.something)

    # Decorate the command with the zouqi.command decorator
    @zouqi.command
    def drive(self):
        self.add_argument("something")
        self.update_args()  # call update_args after add new args
        self.show("drives")

    @zouqi.command
    def wash(self):
        self.add_argument("something")
        self.update_args()
        self.show("washes")


if __name__ == "__main__":
    Runner().run()

Runs

$ python3 example.py 
usage: example.py [-h] {drive,wash} who
example.py: error: the following arguments are required: command, who
$ python3 example.py drive John car
John drives car

Project details


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.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

zouqi-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file zouqi-1.0.0.tar.gz.

File metadata

  • Download URL: zouqi-1.0.0.tar.gz
  • Upload date:
  • Size: 2.6 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

Hashes for zouqi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fbf923a39e00c4558cf6dcf09e2ac115ae7cd4674c05068fe2766f6b298d5ad2
MD5 be578ff819a4a5744c7682544bd09b65
BLAKE2b-256 1bd4e0bb8281032845110bf5b109a3f39bdaf6329ee022e07cbc8e82ffb1fd87

See more details on using hashes here.

File details

Details for the file zouqi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zouqi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 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

Hashes for zouqi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f69bb1489833b7924401d817182a4b9c76bae8540180efa1d0edda01c6934ef
MD5 958de6bcd4ce4b2fbca42d80f1671b89
BLAKE2b-256 13c87a06e612f4e75d13e81f0317a56f6bfd5bacdb4ac9a59a703b8779ac5276

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page