Command-Line Interface

Entry Function

The command-line interface assignment-checker directs to the cli:cli method;

cli()

CLI handle for the assignment submission checker package.

which serves to parse the command-line arguments and pass the corresponding Python values to the backend function.

The CLIParser class is defined to have the command-line interface automatically display the help message when the user inputs invalid arguments.

class CLIParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)

A custom subclass of argparse.ArgumentParser, which changes the default behaviour on an error in CLI parsing to print the command-line help, as opposed to throwing an error to stderr.

error(message: string)

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

print_help_and_exit(msg: str = '', code: int = 2) None

Have the parser print the command-line help before exiting with the code provided.

An optional message msg can be provided, and will be printed to the screen prior to displaying the help. ‘Refer to CLI usage below’ will automatically be appended to this message.

Backend Function

The cli_main module contains the function that actually runs the validation workflow of the assignment-checker, main:

main(assignment_lookup: str | None = None, github_clone_url: str | None = None, local_specs: Path | None = None, submission: Path | None = None) None

Online specs take priority over local specs (assignment > local_specs) Online repo takes priority over local submission (github_clone_url > submission)

This function is deliberately separated from the command-line interface entry function to allow the validation workflow to be run from within Python scripts and workflows directly, without the need to open a subprocess and delegate to the shell.

The only other function in this module is the fetch_spec function, which handles fetching assignment specifications from the GitHub repository.

fetch_spec(assignment_spec: str) None

Fetches the assignment specification given from the assignment checker repository.

Raises a runtime error if the assignment specification is not recognised.