feat: сделал первую версию CLI

Проект в целом получил свой MVP
This commit is contained in:
ElectronixTM
2025-03-16 03:52:07 +03:00
parent 8734e1eba9
commit 666657926b
3 changed files with 69 additions and 8 deletions

View File

@ -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()