Easily define your Command line and sub-commands using argparse.
Project description
easycli
Command line interface for python application on top of the argparse including sub-parsers.
Installation
pip install easycli
Quickstart
quickstart.py
from easycli import Root, SubCommand, Argument
__version__ = '0.1.0'
DEFAULT_TCP_PORT = 8585
DEFAULT_HOST = 'WPP.local'
class SubCommand1(SubCommand):
__command__ = 'sub-command1'
__arguments__ = [
Argument(
'-V', '--version',
action='store_true',
help='Show programmer\'s version'
),
Argument(
'-p', '--port',
type=int,
default=DEFAULT_TCP_PORT,
help=f'TCP port, default: {DEFAULT_TCP_PORT}'
),
Argument(
'-H', '--host',
default=DEFAULT_HOST,
help=f'Hostname, default: {DEFAULT_HOST}'
)
]
def __call__(self, args):
print('Sub command 1, args:', args)
class Example(Root):
__help__ = 'easycli example'
__completion__ = True
__arguments__ = [
Argument('-V', '--version', action='store_true', help='Show version'),
SubCommand1,
]
def __call__(self, args):
if args.version:
print(__version__)
return
return super().__call__(args)
if __name__ == '__main__':
Example().main()
$ python quickstart.py
usage: quickstart.py [-h] [-V] {sub-command1,completion} ...
easycli example
optional arguments:
-h, --help show this help message and exit
-V, --version Show version
Sub commands:
{sub-command1,completion}
sub-command1
completion Bash auto completion using argcomplete python package.
Bash Auto Completion
$ python quickstart.py completion
usage: quickstart.py completion [-h] {install,uninstall} ...
optional arguments:
-h, --help show this help message and exit
Sub commands:
{install,uninstall}
install Enables the autocompletion.
uninstall Disables the autocompletion.
ProgressBar
from easycli import ProgressBar
steps = 100
with ProgressBar(steps) as pb:
for i in range(steps):
# Do what you want here
pb.increment()
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
easycli-1.1.0.tar.gz
(6.5 kB
view details)
File details
Details for the file easycli-1.1.0.tar.gz.
File metadata
- Download URL: easycli-1.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f8978bd941280079cc5e2b5688358e1da63000243cc06bda65ed9b84c9ca70c
|
|
| MD5 |
d574ca81fd601c1f3762f0b677fffb49
|
|
| BLAKE2b-256 |
8aa4fd0b023fc6aecf129fdf006a6d4c3af891b743b4b37fa94fcfc959a68625
|