Skip to main content

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

```bash
pip install easycli
```


## Quickstart

`quickstart.py`

```python
from easycli import Root, SubCommand, Argument


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 Main(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__':
Main()

```

```bash
$ 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

```bash
$ 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

```python
from easycli import ProgressBar


steps = 100
with ProgressBar(steps) as pb:
for i in range(steps):
# Do what you want here
pb.increment()
```

For more information refer to [examples/progressbar.py](examples/progressbar.py)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for easycli, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size easycli-0.2.0-py3-none-any.whl (7.8 kB) File type Wheel Python version 3.6 Upload date Hashes View
Filename, size easycli-0.2.0.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page