Added interactive mode
This commit is contained in:
@@ -1,22 +1,28 @@
|
|||||||
import getopt
|
import getopt
|
||||||
import sys
|
import sys
|
||||||
import logging
|
from os import path
|
||||||
|
import click
|
||||||
import core.utils
|
import core.utils
|
||||||
from core.sheerka.Sheerka import Sheerka
|
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():
|
def usage():
|
||||||
print("Sheerka v0.1\n")
|
print("Sheerka v0.1\n")
|
||||||
print("usage:")
|
print("usage:")
|
||||||
print(sys.argv[0] + "[-hdl:] command ")
|
print(sys.argv[0] + "[-hdl:] command | [-i]")
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(argv, "hdl:", ["help", "debug", "logger="])
|
|
||||||
debug = False
|
debug = False
|
||||||
|
interactive = False
|
||||||
loggers = set()
|
loggers = set()
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(argv, "hdl:i", ["help", "debug", "logger=", "interactive"])
|
||||||
|
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o in ('-h', "--help"):
|
if o in ('-h', "--help"):
|
||||||
usage()
|
usage()
|
||||||
@@ -25,21 +31,44 @@ def main(argv):
|
|||||||
debug = True
|
debug = True
|
||||||
if o in ('-l', '-logger'):
|
if o in ('-l', '-logger'):
|
||||||
loggers.add(a)
|
loggers.add(a)
|
||||||
|
if o in ('-i', '--interactive'):
|
||||||
|
interactive = True
|
||||||
|
except getopt.GetoptError:
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
sheerka = Sheerka(debug=debug, loggers=loggers)
|
sheerka = Sheerka(debug=debug, loggers=loggers)
|
||||||
sheerka.initialize()
|
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)
|
_in = core.utils.sysarg_to_string(args)
|
||||||
result = sheerka.evaluate_user_input(_in)
|
result = sheerka.evaluate_user_input(_in)
|
||||||
sheerka.print(result)
|
sheerka.print(result)
|
||||||
|
|
||||||
# for res in result:
|
|
||||||
# logging.info(res)
|
|
||||||
|
|
||||||
return result[-1].status if len(result) > 0 else 1
|
return result[-1].status if len(result) > 0 else 1
|
||||||
except getopt.GetoptError:
|
|
||||||
usage()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
appdirs==1.4.3
|
appdirs==1.4.3
|
||||||
atomicwrites==1.3.0
|
atomicwrites==1.3.0
|
||||||
attrs==19.3.0
|
attrs==19.3.0
|
||||||
|
click==7.1.1
|
||||||
fs==2.4.11
|
fs==2.4.11
|
||||||
|
gprof2dot==2017.9.19
|
||||||
more-itertools==7.2.0
|
more-itertools==7.2.0
|
||||||
packaging==19.2
|
packaging==19.2
|
||||||
pluggy==0.13.0
|
pluggy==0.13.0
|
||||||
|
prompt-toolkit==3.0.5
|
||||||
py==1.8.0
|
py==1.8.0
|
||||||
Pygments==2.4.2
|
Pygments==2.4.2
|
||||||
pyparsing==2.4.4
|
pyparsing==2.4.4
|
||||||
pytest==5.2.2
|
pytest==5.2.2
|
||||||
|
pytest-profiling==1.7.0
|
||||||
pytz==2019.3
|
pytz==2019.3
|
||||||
six==1.13.0
|
six==1.13.0
|
||||||
wcwidth==0.1.7
|
wcwidth==0.1.7
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import click
|
||||||
from core.builtin_concepts import BuiltinConcepts
|
from core.builtin_concepts import BuiltinConcepts
|
||||||
from core.concept import Concept
|
from core.concept import Concept
|
||||||
from printer.FormatInstructions import FormatInstructions, FormatDetailType
|
from printer.FormatInstructions import FormatInstructions, FormatDetailType
|
||||||
|
|||||||
Reference in New Issue
Block a user