示例#1
0
    > If no commands are entered, you will be prompted for a file name.
    
    '''
    arg_parser = argparse.ArgumentParser(
        description="Extract filename if present")
    arg_parser.add_argument("-f",
                            "--file",
                            help="Name of the file",
                            default=None)
    args = arg_parser.parse_args()
    the_exception_handler = TigrExceptionHandler(
        "TIGr encountered an error and had to exit")

    if args.file:
        # file name provided - read input from file
        TigrReader(RegexParser(CommandFactory(TurtleDrawer()),
                               the_exception_handler),
                   the_exception_handler,
                   optional_file_name=args.file).go()
    else:
        # read from stdin
        # TODO examine if this section of the code can be incorporated within the class structure
        source = None
        if sys.stdin.isatty():
            # read from input at prompt
            print("Enter your commands. Ctrl + Z to exit or finish.")
            # only on windows, if this was portable we should add the linux interrupt command x3
            print(
                "If no commands are entered, you will be prompted for a file name."
            )
            source = sys.stdin.readlines()