-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_cli.py
More file actions
77 lines (57 loc) · 2.52 KB
/
run_cli.py
File metadata and controls
77 lines (57 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import pprint
import os.path
import os
from manspy.utils.settings import Settings, InitSettings
from manspy.utils.unit import BaseUnit
from manspy.runners.simple import runner
console_cur_dir = os.path.abspath('')
READ = '\033[0;31m'
NORM = '\033[0;0m'
GREEN = '\033[0;32m'
ORANGE = '\033[0;33m'
def print_error(msg):
print('{READ} {0} {NORM}'.format(msg, READ=READ, NORM=NORM))
class CLI:
def __init__(self):
self.settings = Settings(language='esperanto', answer_type='fake')
def cmd_exec(self, args):
def send_to_in(text, settings, level):
results = runner(text, settings, pipeline=level)
if isinstance(results, BaseUnit):
pprint.pprint(results.export_unit(ignore_units=dict))
elif isinstance(results, dict):
pprint.pprint(results)
else:
for result in results:
print(result)
self.settings.language = args.language
self.settings.answer_type = args.type
self.settings.history = args.history
# self.settings.print_time = args.print_time
if args.text:
send_to_in(args.text, self.settings, args.level)
manspy_cur_dir = os.getcwd()
for filename in args.filenames:
os.chdir(console_cur_dir)
filepath = os.path.abspath(filename)
os.chdir(manspy_cur_dir)
with open(filepath, 'r') as filef:
send_to_in(filef.read(), self.settings)
def run(args_list=None):
cli = CLI()
with InitSettings():
parser = argparse.ArgumentParser(description='ManSPy')
parser.add_argument('--version', action='version', version='%(prog)s 0.0.0')
parser.add_argument('--level', default='graphmath:exec')
parser.add_argument('--type', default='fake', help='answer type: fake (default), construct, real')
parser.add_argument('--language', default='esperanto', help='nature language')
# parser.add_argument('--print-levels', action='store_true', help='print analysyses of every level')
# parser.add_argument('--print-time', action='store_true', help='print time of every level')
parser.add_argument('--history', action='store_true', help='save the history of dialog')
parser.add_argument('--text', default=None, help='input text')
parser.add_argument('filenames', nargs='*', help='files with input text')
args = parser.parse_args(args_list)
cli.cmd_exec(args)
if __name__ == '__main__':
run()