feat: сделал первую версию CLI
Проект в целом получил свой MVP
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import rulesparser
|
||||
import rulebook
|
||||
from rulesparser import RulesParser
|
||||
from rulebook import Rulebook
|
||||
from interactive import interactve_mode
|
||||
import argparse
|
||||
|
||||
def main():
|
||||
@ -8,7 +9,7 @@ def main():
|
||||
description = "Simple tool to apply Markov's normal algorithms"
|
||||
)
|
||||
parser.add_argument("rulebook", type=str, help="File with the rules for algorithm")
|
||||
parser.add_argument("-c", "--command-line-input", type=str, nargs='?',
|
||||
parser.add_argument("-c", "--command-line-input",
|
||||
help="Takes input from user via command line "
|
||||
"arguments. There should be only one string. "
|
||||
"Please, use quotation marks")
|
||||
@ -16,7 +17,23 @@ def main():
|
||||
help="If set, verbose output will be produced. "
|
||||
"It'll contain all intermediate transformations, "
|
||||
"reason of stop etc.")
|
||||
parser.parse_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
rules = RulesParser().parse(args.rulebook)
|
||||
rulebook = Rulebook(rules)
|
||||
print(args.command_line_input)
|
||||
if not args.command_line_input:
|
||||
interactve_mode(rulebook)
|
||||
return
|
||||
|
||||
transformer = (rulebook.logged_transform if args.verbose
|
||||
else rulebook.transform)
|
||||
if args.verbose:
|
||||
_, log = transformer(args.command_line_input)
|
||||
print(log)
|
||||
else:
|
||||
print(transformer(args.command_line_input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user