Mini framework for console apps.
# main.py
import sys
from src.Console import Console
def hello_callback(context):
print ('Hello world!')
c = Console()
c.router.route('hello', hello_callback)
c.listen()
Now if you run:
python main.py hello
You will get the message
Hello world!
in your screen.
python main.py
calling the script directly will start the console in interactive mode
you will see something like:
$
Now lets run help:
$ help
this will print a message like this one:
$ help
Available commands:
hello
exit
die
and if we run:
$ hello
We got our hello world!
$ hello
Hello world!
# main.py
from HelloController import HelloController
c = Console()
c.router.route('hello', HelloController())
c.listen()
# HelloController.py
class HelloController:
def __init__(self):
self.message = "Hello world!"
def __call__(self, context):
print(self.message)