Skip to main content

k3shell

Action-CI Documentation Status Package

A python module to manage commands.

k3shell is a component of pykit3 project: a python3 toolkit set.

Name

k3shell

Status

The library is considered production ready.

Install

pip install k3shell

Synopsis

import k3shell
import sys
arguments = {
    'echo_repr': (
        lambda x: sys.stdout.write(repr(x)),
        ('x', {'nargs': '+', 'help': 'just an input message'}),
    ),

    'foo': {
        'bar': lambda: sys.stdout.write('bar'),

        'bob': {
            'plus': (
                lambda x, y: sys.stdout.write(str(x + y)),
                ('x', {'type': int, help: 'an int is needed'}),
                ('y', {'type': int, help: 'an int is needed'}),
            ),
        },
    },

    '__add_help__': {
        ('echo_repr',)           : 'output what is input.',
        ('foo', 'bar',)          : 'print a "bar".',
        ('foo', 'bob', 'plus',)  : 'do addition operation with 2 numbers.',
    },

    '__description__': 'this is an example command.',
}

k3shell.command(**arguments)
"""

then you can execute your command as:

python demo.py echo_repr hello!
# 'hello!'

python demo.py foo bar
# 'bar'

python demo.py foo bob plus 1 2
# 3


and you can get a usage help message like:

$ python demo.py -h
---------------------------
usage: demo.py [-h] {echo_repr, foo bar, foo bob plus} ...

this is an example command.

positional arguments:
  {echo_repr, foo bar, foo bob plus} commands to select ...
    echo_repr            output what is input.
    foo bar              print a "bar".
    foo bob plus         do addition operation with 2 numbers.

optional arguments:
    -h, --help           show this help message and exit


$ python demo.py foo bob plus -h
--------------------------
usage: demo.py foo bob plus [-h] x y

positional arguments:
    x   an int is need
    y   an int is need

optional arguments:
    -h, --help           show this help message and exit

"""

Author

Wenbo Li(李文博) wenbo.li@baishancloud.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2017 Wenbo Li(李文博) wenbo.li@baishancloud.com

Metadata

Release files for k3shell 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3shell 0.1.5
File Size Uploaded
k3shell-0.1.5.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3shell 0.1.5
File Interpreter ABI Platform
k3shell-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / k3shell-0.1.5.tar.gz

Download URL k3shell-0.1.5.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
399f5fc930fe26da71c100680bcf68f3be454e25f51798db4865fda3ff5096cc
BLAKE2b-256 checksum
How to use checksums
330dbeb2b4c5702c72f23f4d9b9f0709dd18bb25f815f2a1eb0d7087723c100c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / k3shell-0.1.5-py3-none-any.whl

Download URL k3shell-0.1.5-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccbcb72a51a2490df225a7d34d59d2ae504cd97c4d93fec5c8f9c119666ea09b
BLAKE2b-256 checksum
How to use checksums
1d0f6409626b34503af1ab5e98379e9920c2588db77b35a7851ca3c689236a39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page