lms.cli.courses.get

Get a specific course.

usage: python3 -m lms.cli.courses.get [-h] [--version] [--server SERVER]
                                      [--server-type {blackboard,canvas,moodle}]
                                      [--auth-user AUTH_USER]
                                      [--auth-password AUTH_PASSWORD]
                                      [--auth-token AUTH_TOKEN]
                                      [--format {json,table,text}]
                                      [--include-extra-fields]
                                      [--pretty-headers] [--skip-headers]
                                      [--strict]
                                      [COURSE_QUERY ...]

Get a specific course.

positional arguments:
  COURSE_QUERY          A query for a course to get.

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --strict              Enable strict mode, which is stricter about what
                        counts as an error (default: False).

server options:
  --server SERVER       The address of the LMS server to connect to.
  --server-type {blackboard,canvas,moodle}
                        The type of LMS being connected to (this can normally
                        be guessed from the server address).

authentication options:
  --auth-user AUTH_USER
                        The user to authenticate with.
  --auth-password AUTH_PASSWORD
                        The password to authenticate with.
  --auth-token AUTH_TOKEN
                        The token to authenticate with.

output formatting options:
  --format {json,table,text}
                        The format to display the output as (default: text).
  --include-extra-fields
                        Include non-common (usually LMS-specific) fields in
                        results (default: False).
  --pretty-headers      When displaying headers, try to make them look
                        "pretty" (default: False).
  --skip-headers        Skip headers when outputting results, will not apply
                        to all formats (default: False).
 1"""
 2Get a specific course.
 3"""
 4
 5import argparse
 6import sys
 7
 8import lms.backend.instance
 9import lms.cli.common
10import lms.cli.parser
11import lms.model.base
12
13def run_cli(args: argparse.Namespace) -> int:
14    """ Run the CLI. """
15
16    config = args._config
17
18    backend = lms.backend.instance.get_backend(**config)
19    queries = backend.parse_course_queries(args.courses)
20    courses = backend.courses_get(queries)
21
22    output = lms.model.base.base_list_to_output_format(courses, args.output_format,
23            skip_headers = args.skip_headers,
24            pretty_headers = args.pretty_headers,
25            include_extra_fields = args.include_extra_fields,
26    )
27
28    print(output)
29
30    return lms.cli.common.strict_check(args.strict, (len(courses) != len(queries)),
31        f"Expected to find {len(queries)} courses, but found {len(courses)}.")
32
33def main() -> int:
34    """ Get a parser, parse the args, and call run. """
35    return run_cli(_get_parser().parse_args())
36
37def _get_parser() -> argparse.ArgumentParser:
38    """ Get the parser. """
39
40    parser = lms.cli.parser.get_parser(__doc__.strip(),
41            include_output_format = True,
42            include_strict = True,
43    )
44
45    parser.add_argument('courses', metavar = 'COURSE_QUERY',
46        type = str, nargs = '*',
47        help = 'A query for a course to get.')
48
49    return parser
50
51if (__name__ == '__main__'):
52    sys.exit(main())
def run_cli(args: argparse.Namespace) -> int:
14def run_cli(args: argparse.Namespace) -> int:
15    """ Run the CLI. """
16
17    config = args._config
18
19    backend = lms.backend.instance.get_backend(**config)
20    queries = backend.parse_course_queries(args.courses)
21    courses = backend.courses_get(queries)
22
23    output = lms.model.base.base_list_to_output_format(courses, args.output_format,
24            skip_headers = args.skip_headers,
25            pretty_headers = args.pretty_headers,
26            include_extra_fields = args.include_extra_fields,
27    )
28
29    print(output)
30
31    return lms.cli.common.strict_check(args.strict, (len(courses) != len(queries)),
32        f"Expected to find {len(queries)} courses, but found {len(courses)}.")

Run the CLI.

def main() -> int:
34def main() -> int:
35    """ Get a parser, parse the args, and call run. """
36    return run_cli(_get_parser().parse_args())

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