Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Main program."""
from my_awesome_script.parser import create_parser


def main():
"""
Call the parser.

:return:
"""
create_parser()


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Commands for the script."""

from datetime import datetime

from cowpy.cow import Cowacter
from pygments import highlight as hl
from pygments.formatters import get_formatter_by_name
from pygments.lexers import get_lexer_by_name
from pytz import timezone


def run_command(command: str):
"""
Select command.

Args:
command: command name

Returns:
:return: selected command
"""
return commands[command]


def highlight(code: str):
"""
Highlight code.

Args:
code: code to highlight
"""
this_lexer = get_lexer_by_name('python')
this_formatter = get_formatter_by_name('terminal')
print(hl(code, lexer=this_lexer, formatter=this_formatter)) # noqa: WPS421


def cowsay(text: str):
"""
Make the cow talk.

Args:
text: text that the cow say
"""
cow = Cowacter()
print(cow.milk(text)) # noqa: WPS421


def time(region: str):
"""
Show time in the region.

Args:
region: selected region
"""
ftime = '%H:%M:%S'
time_zone = timezone(region)
print(datetime.now(time_zone).strftime(ftime)) # noqa: WPS421


commands = {'highlight': highlight, 'cowsay': cowsay, 'time': time}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Poetry shell parser."""
from argparse import ArgumentParser

from my_awesome_script.commands import run_command


def create_parser():
"""
Create a poetry shell parser.

:return:
"""
parser = ArgumentParser()
parser.add_argument('command', type=str, help=', '.join(commands))
parser.add_argument('parameter', type=str, help=', '.join(comm_param))
args = parser.parse_args()

command = args.command
parameter = args.parameter

run_command(command)(parameter)


commands = ('highlight', 'cowsay', 'time')
comm_param = ('code to highlight', 'text that the cow say', 'selected region')
Loading