1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
//! # lz
//!
//! A command-line interface for various math/tech subjects. Based on the [ladderz](https://github.com/rzmk/ladderz) library.
//!
//! # Installation
//!
//! To install the command-line interface, run the following command in your terminal:
//!
//! ```bash
//! cargo install --git https://github.com/rzmk/ladderz --branch main
//! ```
//!
//! # Example
//!
//! ```bash
//! lz prealgebra is-factor 3 12
//! ```
//!
//! ```console
//! 3 is a factor of 12.
//! ```
//!
//! You may view the help menu for a subject and a function by running the command with the `-h` or `--help` flag:
//!
//! ```bash
//! lz prealgebra is-factor -h
//! ```
//!
//! Learn more on [GitHub](https://github.com/rzmk/ladderz).
// External modules
use clap::{Parser, Subcommand};
// Local modules
pub mod prealgebra;
use prealgebra::{match_prealgebra, Prealgebra};
pub mod dsa;
use dsa::{match_dsa, Dsa};
#[derive(Parser)]
#[command(
author = "Mueez Khan",
about = "Run various functions from a range of math/tech subjects on the command line.",
subcommand_value_name = "SUBJECT",
arg_required_else_help(true)
)]
struct Cli {
#[command(subcommand)]
subject: Option<Subjects>,
}
/// The subjects that can be used.
#[derive(Subcommand)]
#[command(arg_required_else_help(true))]
enum Subjects {
Prealgebra {
/// The function (command) to run.
#[command(subcommand)]
function: Option<Prealgebra>,
},
Dsa {
#[command(subcommand)]
function: Option<Dsa>,
},
}
fn main() {
let cli: Cli = Cli::parse();
// Match the subject to run the correct function.
match cli.subject {
Some(Subjects::Prealgebra { function }) => match_prealgebra(function),
Some(Subjects::Dsa { function }) => match_dsa(function),
None => println!("Please provide a subject to use."),
}
}