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
Metadata
Release files for everon 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| everon-0.0.1.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| everon-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.8 kB
Release files / everon-0.0.1.tar.gz
| Download URL | everon-0.0.1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de28f554886c98ae2444b82186a48bf27ad67d04733881a225421844e22810dc
|
|
BLAKE2b-256 checksum How to use checksums |
88a20425d3cbf64a15c9752eee16f1d3369339510faee4fe001fcefcad124ccf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / everon-0.0.1-py3-none-any.whl
| Download URL | everon-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82dcafb53036cf171edf6ba36f762e7afcb9111113908fa9815ae2387489b9cd
|
|
BLAKE2b-256 checksum How to use checksums |
ffbd7245f30eddf223bd27fe31f7d9840f6e4504c1036b6358892ed077a8ffc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|