kallo_cli/lib.rs
1//! `kalo` — the command line front end for Kallo.
2//!
3//! The binary itself is a three-line wrapper. Everything lives in this crate so
4//! that a command can be exercised from a test without spawning a process:
5//!
6//! ```
7//! use clap::Parser;
8//! use kallo_cli::cli::Cli;
9//!
10//! let cli = Cli::parse_from(["kalo", "stocks"]);
11//! kallo_cli::run(cli).unwrap();
12//! ```
13
14#![forbid(unsafe_code)]
15
16pub mod cli;
17pub mod commands;
18pub mod error;
19pub mod filmfile;
20pub mod stockfile;
21
22use cli::{Cli, Command};
23use error::CliError;
24
25/// Run a parsed command.
26///
27/// Parsing is separate from execution on purpose: it keeps the argument surface
28/// testable and the error type inspectable.
29pub fn run(cli: Cli) -> Result<(), CliError> {
30 match cli.command {
31 Command::Render(args) => commands::render::run(args),
32 Command::Contact(args) => commands::contact::run(args),
33 Command::Curve(args) => commands::curve::run(args),
34 Command::Stocks { json } => {
35 commands::stocks::run(json);
36 Ok(())
37 }
38 Command::Stock { command } => match command {
39 cli::StockCommand::Check(args) => commands::stock::run(args),
40 },
41 Command::Bake(args) => commands::bake::run(args),
42 }
43}