Skip to main content

image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg

Project description

https://yourlabs.io/oss/cli2/badges/master/pipeline.svg https://codecov.io/gh/yourlabs/cli2/branch/master/graph/badge.svg https://img.shields.io/pypi/v/cli2.svg

cli2: Dynamic CLI for Python 3

Expose Python functions or objects with a minimalist argument typing style, or building your own command try during runtime.

Documentation available on RTFD.

Demo

cli2 is a little library to build CLIs, which documentation is available on RTFD, but it comes with its own demo command that may as well be useful to explore Python libraries and call functions on the fly.

Because, initially, cli2 was supposed to just bring Python callables on the CLI without even a single line of code:

cli2 path.to.your.callable arg1 kwarg1=value

This command was implemented again in this 10th rewrite of the CLI engine extracted from Playlabs, however this implementation features something pretty funny: cli2 is a Group subclass which overrides the default Group implementation based on the first argument passed on the command line.

Basically, when you call cli2 path.to.module, it will load a Group of name path.to.module which whill load one Command per callable in path.to.module.

When you call cli2 path.to.function it will execute the function.

As a result, these three commands are strictly equivalent:

cli2 cli2.test_node.example_function foo=bar
cli2 cli2.test_node example_function foo=bar

That is because cli2 generates a group with every member of the previous group!

See for yourself with:

cli2 help cli2.test_node

Or just:

cli2 cli2.test_node

Because cli2.test_node is not a callable but a module, cli2’s cli2 CLI created a command Group on the fly with the module and added every callable member as command.

When you call a group on the command line, it displays help by default to drive the user.

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

cli2-2.4.0.tar.gz (17.6 kB view details)

Uploaded Source

File details

Details for the file cli2-2.4.0.tar.gz.

File metadata

  • Download URL: cli2-2.4.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for cli2-2.4.0.tar.gz
Algorithm Hash digest
SHA256 ef045f05129797514928e4eb9236fff664f2bc41a9b90cc26ef056f7683880d7
MD5 c23a7e8e7fb8eb288fef6ca16a332e96
BLAKE2b-256 6a28575b4519a6df599455238a8534b85a54d2708f11494608196bd0c4582b28

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