Skip to main content

Build robust command line interface fast.

Project description

nutcli - cli in a nutshell

The Python nutcli package allows you to easily create robust command-based command line interface that can combine the best of the two worlds of python and shell.

It also provides several useful classes and decorators that can help you improve the user experience by producing nicely formatted output and allowing dry runs for operations with side effects.

Links

Installation

pip3 install nutcli

Example instead of thousands words

Bellow is the very basic example to get the idea of what this package does and how its used.

class HelloActor(Actor):
    def setup_parser(self, parser):
        parser.add_argument('--hello', action='store', type=str)

    def __call__(self, hello):
        self.info(hello)
        return 0

class Program:
    def main(self, argv):
        # Create argument parser.
        parser = argparse.ArgumentParser()

        CommandParser('Example Commands')([
            Command('hello', 'Print hello message', HelloActor()),
        ]).setup_parser(parser)

        # Create the runner object.
        runner = Runner('my-cli', parser).setup_parser()

        # Parse arguments - the runner internally process its own arguments
        # that were setup by previous call to `setup_parser()`.
        args = runner.parse_args(argv)

        # You can handle your own global arguments here.

        # Now we setup the default logger - it produces output to stdout
        # and stderr.
        runner.default_logger()

        # And finally, we execute the requested command and return its exit
        # code.
        return runner.execute(args)


if __name__ == "__main__":
    program = Program()
    sys.exit(program.main(sys.argv[1:]))
$ python3 ./main.py hello --hello world
[my-cli] world
$ python3 ./main.py --help
usage: main.py [-h] [--log-execution] [--dry-run] [--no-colors] COMMANDS ...

optional arguments:
-h, --help       show this help message and exit
--log-execution  Log execution of operations that supports it.
--dry-run        Do not execute operations with side effects. Only log what
                    would be done.
--no-colors      Do not execute operations with side effects. Only log what
                    would be done.

Example Commands:
COMMANDS
    hello          Print hello message

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

nutcli-1.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

nutcli-1.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file nutcli-1.0.tar.gz.

File metadata

  • Download URL: nutcli-1.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/47.1.1 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.7.5

File hashes

Hashes for nutcli-1.0.tar.gz
Algorithm Hash digest
SHA256 07d69d04c4495e1ffaa6b3527f63a6a8fa72c14a6beafa888cc18bb51377e1c5
MD5 1a99bddb6b6282ca149c5a89cf416a6f
BLAKE2b-256 8e201263cb0d01d4354f5a29f88a56b4554f13c60236ef31cc43c1e3b1976942

See more details on using hashes here.

File details

Details for the file nutcli-1.0-py3-none-any.whl.

File metadata

  • Download URL: nutcli-1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/47.1.1 requests-toolbelt/0.8.0 tqdm/4.46.1 CPython/3.7.5

File hashes

Hashes for nutcli-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 157094e7394b0929f997da86dc39d0b6adac9c7dbeea56a438612dae66654f82
MD5 12d29cbd2da154bda9cdc1779d261a31
BLAKE2b-256 3a79c042e21340cd82fa6f9208f68226d5a5acc9d686b005a82c26c57dd650e7

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