Files
coursebank/src/main.rs
T
alexm abae39bd54
Pipeline / check (pull_request) Failing after 12m11s
Pipeline / docs (pull_request) Skipped
Pipeline / nightly (pull_request) Skipped
Pipeline / release (pull_request) Skipped
chore: relicense under Apache-2.0
Replace the Prosperity Public License 3.0.0 with the Apache License 2.0:
LICENSE.md, a new NOTICE.md, the Cargo license field, every SPDX header,
and the README's license and contributing sections.
2026-11-18 18:57:08 -05:00

57 lines
2.1 KiB
Rust

// SPDX-License-Identifier: Apache-2.0
// Copyright Scienting
// Source: https://git.scient.ing/education/coursebank
//! The `coursebank` command-line interface.
//!
//! Command names follow the workflow rather than the data model: you `assemble` an
//! exam, `ingest` the grading export, `analyze` it, and `report`. Every command that
//! modifies a bank prints what it would change and requires `--apply` to do it,
//! because these files are reviewed artifacts in a git repository and a silent
//! rewrite is not something you want to discover in a diff later.
//!
//! Exit codes are meaningful for scripting and CI: `0` for success, `1` for a
//! failure, `2` when validation or linting found problems. That last one is the
//! reason a course repository can have a pre-commit hook.
//!
//! # Module layout
//!
//! `main.rs` is deliberately thin. The pieces live in sibling modules:
//!
//! - [`cli`] — the `clap` argument model (every flag, subcommand, and the small
//! conversions from CLI-facing enums into the library's domain enums).
//! - [`commands`] — the [`run`](commands::run) dispatcher plus one submodule per
//! workflow stage, each holding the handlers for its subcommands.
//! - [`helpers`] — shared plumbing used by more than one handler: loading the
//! catalog, resolving records and forms, parsing `KEY=VALUE` flags, and the
//! text formatting used by the various listings.
//! - [`import`] — the one-off legacy-JSON importer, kept apart because it is large
//! and touched rarely.
mod cli;
mod commands;
mod helpers;
use std::process::ExitCode;
use clap::Parser;
use crate::cli::Cli;
use crate::commands::{Outcome, run};
/// Parses the command line, runs the requested command, and maps its result onto
/// a process exit code.
///
/// See the crate-level documentation for the meaning of each code.
fn main() -> ExitCode {
let cli = Cli::parse();
match run(&cli) {
Ok(Outcome::Ok) => ExitCode::SUCCESS,
Ok(Outcome::Findings) => ExitCode::from(2),
Err(e) => {
eprintln!("error: {e}");
ExitCode::FAILURE
}
}
}