#![deny(missing_docs)]
#![deny(clippy::panic)]
#![warn(clippy::all, clippy::pedantic)]
pub mod commands;
pub mod output;
use clap::{Parser, Subcommand};
use std::process::ExitCode;
#[derive(Parser)]
#[command(name = "trueno-zram")]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[arg(long, default_value = "table")]
pub format: output::OutputFormat,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Create(commands::CreateArgs),
Remove(commands::RemoveArgs),
Status(commands::StatusArgs),
Benchmark(commands::BenchmarkArgs),
}
#[must_use]
pub fn run() -> ExitCode {
let cli = Cli::parse();
match dispatch(&cli.command, cli.format) {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("Error: {e}");
ExitCode::FAILURE
}
}
}
pub fn dispatch(
command: &Commands,
format: output::OutputFormat,
) -> Result<(), Box<dyn std::error::Error>> {
match command {
Commands::Create(args) => commands::create(args),
Commands::Remove(args) => commands::remove(args),
Commands::Status(args) => commands::status(args, format),
Commands::Benchmark(args) => commands::benchmark(args),
}
}