quizcomp.cli.parse.file

Parse a single file and output the results of the parse.

usage: python3 -m quizcomp.cli.parse.file [-h] [--version]
                                          [--format {canvas,html,json,md,tex,text}]
                                          PATH

Parse a single file and output the results of the parse.

positional arguments:
    PATH                The path to parse.

options:
    -h, --help          show this help message and exit
    --version           show program's version number and exit
    --format {canvas,html,json,md,tex,text}
                        Output the parsed document in this format (default:
                        Format.JSON).
 1"""
 2Parse a single file and output the results of the parse.
 3"""
 4
 5import argparse
 6import sys
 7
 8import quizcomp.cli.parser
 9import quizcomp.model.constants
10import quizcomp.parser.document
11
12def run_cli(args: argparse.Namespace) -> int:
13    """ Run the CLI. """
14
15    document = quizcomp.parser.document.ParsedDocument.parse_file(args.path)
16
17    content = document.to_format(quizcomp.model.constants.Format(args.format), pretty = True)
18    print(content)
19
20    return 0
21
22def main() -> int:
23    """ Get a parser, parse the args, and call run. """
24
25    return run_cli(_get_parser().parse_args())
26
27def _get_parser() -> argparse.ArgumentParser:
28    """ Get the parser. """
29
30    parser = quizcomp.cli.parser.get_parser(__doc__.strip(),
31        include_katex = True,
32    )
33
34    parser.add_argument('path', metavar = 'PATH',
35        type = str,
36        help = 'The path to parse.')
37
38    parser.add_argument('--format',
39        action = 'store', type = str, default = quizcomp.model.constants.Format.JSON,
40        choices = [choice.value for choice in quizcomp.model.constants.PARSER_FORMATS],
41        help = 'Output the parsed document in this format (default: %(default)s).')
42
43    return parser
44
45if (__name__ == '__main__'):
46    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
13def run_cli(args: argparse.Namespace) -> int:
14    """ Run the CLI. """
15
16    document = quizcomp.parser.document.ParsedDocument.parse_file(args.path)
17
18    content = document.to_format(quizcomp.model.constants.Format(args.format), pretty = True)
19    print(content)
20
21    return 0

Run the CLI.

def main() -> int:
23def main() -> int:
24    """ Get a parser, parse the args, and call run. """
25
26    return run_cli(_get_parser().parse_args())

Get a parser, parse the args, and call run.