Files
Sheerka-Old/main.py
T
2020-04-17 22:09:18 +02:00

77 lines
2.1 KiB
Python

import getopt
import sys
from os import path
import click
import core.utils
from core.sheerka.Sheerka import Sheerka
from prompt_toolkit import prompt
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.history import FileHistory
def usage():
print("Sheerka v0.1\n")
print("usage:")
print(sys.argv[0] + "[-hdl:] command | [-i]")
def main(argv):
debug = False
interactive = False
loggers = set()
try:
opts, args = getopt.getopt(argv, "hdl:i", ["help", "debug", "logger=", "interactive"])
for o, a in opts:
if o in ('-h', "--help"):
usage()
return True
if o in ('-d', "--debug"):
debug = True
if o in ('-l', '-logger'):
loggers.add(a)
if o in ('-i', '--interactive'):
interactive = True
except getopt.GetoptError:
usage()
sys.exit(2)
sheerka = Sheerka(debug=debug, loggers=loggers)
sheerka.initialize()
history_file = path.abspath(path.join(path.expanduser("~"), ".sheerka", "history.txt"))
if interactive:
while True:
try:
_in = prompt('sheerka> ',
history=FileHistory(history_file),
auto_suggest=AutoSuggestFromHistory(),
)
if _in in ("exit", "quit", "bye"):
print("Take care.")
break
if _in == '__':
_in = click.edit()
result = sheerka.evaluate_user_input(_in)
sheerka.print(result)
except KeyboardInterrupt:
continue
except EOFError:
print("EOFError...")
sys.exit(3)
sys.exit(0)
else:
_in = core.utils.sysarg_to_string(args)
result = sheerka.evaluate_user_input(_in)
sheerka.print(result)
return result[-1].status if len(result) > 0 else 1
if __name__ == '__main__':
res = main(sys.argv[1:])
exit(0 if res else 1)