migrate to argparse

This commit is contained in:
Maxim Slipenko 2021-09-17 21:56:12 +03:00
parent c2712885d5
commit d619623eb3

View File

@ -1,15 +1,26 @@
import sys import sys
from argparse import ArgumentParser
from turinglab.input import from_file from turinglab.input import from_file
from turinglab.emulator import Emulator from turinglab.emulator import Emulator
from turinglab.output import to_docx from turinglab.output import to_docx
def get_parser() -> ArgumentParser:
parser = ArgumentParser()
parser.add_argument("input_file", type=str, help="Path to file with program")
parser.add_argument("input_string", type=str, help="Input symbols")
parser.add_argument("output_file", type=str, help="Output file")
return parser
def main(): def main():
program_file, input_string, docx = sys.argv[1:] parser = get_parser()
program = from_file(program_file) args = parser.parse_args()
tm = Emulator(program, input_string)
program = from_file(args.input_file)
tm = Emulator(program, args.input_string)
data = [tm.info()] data = [tm.info()]
@ -17,7 +28,7 @@ def main():
tm.step() tm.step()
data.append(tm.info()) data.append(tm.info())
to_docx(docx, data) to_docx(args.output_file, data)
if __name__ == '__main__': if __name__ == '__main__':
main() main()