It makes easier to build user command-line interface
Project description
EVERON (Python Library)
This module makes easier to write user command-line interfaces.
everon.BaseCommand makes use of the argparse, which is part of Python library.
everon.MixinFontColor is a mixin class, which allows to render color fonts in terminal.
Basic Example
Below, a basic example of what the custom command should look like:
# whats_time.py
from datetime import datetime
import everon
class WhatsTime(everon.BaseCommand):
help = 'Display current time'
def handle(self, *args, **kwargs):
current_time = datetime.now().strftime('%X')
print("It's now {}".format(current_time))
if __name__ == '__main__':
whatstime = WhatsTime()
whatstime.run()
See how we named our module whatstime.py.
This command can be executed as:
python -m whats_time
Output:
It's now 11:54:19
Handling Arguments
To handle arguments in command, we should define a method named add_args.
# rand_str.py
import argparse
import random
import string
from everon import BaseCommand
class RandString(BaseCommand):
def add_args(self, parser: argparse.ArgumentParser):
parser.add_argument('length', type=int, help='Indicates length of string')
parser.add_argument('-l', '--lowercase', action='store_true', help='Only get lowercase letters')
def handle(self, *args, **kwargs):
string_length = kwargs.get('length')
allow_lowercase = kwargs.get('lowercase')
letters = string.ascii_lowercase if allow_lowercase else string.ascii_letters
print("Random String is {}".format(
''.join(random.choice(letters) for _ in range(string_length)))
)
if __name__ == '__main__':
rand_str = RandString()
rand_str.run()
Usage:
python -m rand_str 10 -l
Or
python -m rand_str 10 --lower
Output
Random String is wjaehxsnxc
Font Color
We could setting an appropriate color to the out message with the example
# say_hello.py
from everon import BaseCommand, MixinFontColor
class SayHello(BaseCommand, MixinFontColor):
def __init__(self):
MixinFontColor.__init__(self)
def handle(self, *args, **kwargs):
self.print_ok('Printing text ok')
self.print_err('Printing text error')
print(self.text_as_link('Printing text as link'))
print(self.color.LIGHTMAGENTA_EX + 'Printing text with custom color')
if __name__ == '__main__':
foo = SayHello()
foo.run()
Checking with the following command
python -m say_hello
Output
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file everon-0.0.1.tar.gz.
File metadata
- Download URL: everon-0.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de28f554886c98ae2444b82186a48bf27ad67d04733881a225421844e22810dc
|
|
| MD5 |
95fba3a96fab52fffd22c38343a6a1a5
|
|
| BLAKE2b-256 |
88a20425d3cbf64a15c9752eee16f1d3369339510faee4fe001fcefcad124ccf
|
File details
Details for the file everon-0.0.1-py3-none-any.whl.
File metadata
- Download URL: everon-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82dcafb53036cf171edf6ba36f762e7afcb9111113908fa9815ae2387489b9cd
|
|
| MD5 |
0739e457fc9c1d4c0e83494c04401dd9
|
|
| BLAKE2b-256 |
ffbd7245f30eddf223bd27fe31f7d9840f6e4504c1036b6358892ed077a8ffc2
|