use clap::{Parser, ValueEnum};
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum Action {
Update,
Install,
Uninstall,
}
#[derive(Debug, Parser)]
#[command(name = "tr300")]
#[command(
author,
version,
about = "TR-300 Machine Report - Cross-platform system information"
)]
#[command(
long_about = "TR-300 displays comprehensive system information including OS, network, CPU, \n\
memory, disk usage, and session details in a formatted table.\n\n\
After installation with --install, you can also use the 'report' alias."
)]
pub struct Cli {
#[arg(value_enum, conflicts_with_all = ["update", "install", "uninstall"])]
pub action: Option<Action>,
#[arg(long)]
pub ascii: bool,
#[arg(long)]
pub json: bool,
#[arg(long, conflicts_with_all = ["update", "uninstall", "action"])]
pub install: bool,
#[arg(long, conflicts_with_all = ["update", "install", "action"])]
pub uninstall: bool,
#[arg(long, conflicts_with_all = ["install", "uninstall", "action"])]
pub update: bool,
#[arg(short = 't', long)]
pub title: Option<String>,
#[arg(long)]
pub no_color: bool,
#[arg(long)]
pub fast: bool,
#[arg(long)]
pub no_elevation_hint: bool,
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[test]
fn parses_positional_update_action() {
let cli = Cli::try_parse_from(["tr300", "update"]).expect("update action should parse");
assert_eq!(cli.action, Some(Action::Update));
}
#[test]
fn parses_legacy_update_flag() {
let cli = Cli::try_parse_from(["tr300", "--update"]).expect("--update should parse");
assert!(cli.update);
assert_eq!(cli.action, None);
}
#[test]
fn parses_json_before_positional_update_action() {
let cli =
Cli::try_parse_from(["tr300", "--json", "update"]).expect("--json update should parse");
assert!(cli.json);
assert_eq!(cli.action, Some(Action::Update));
}
#[test]
fn parses_json_after_positional_update_action() {
let cli =
Cli::try_parse_from(["tr300", "update", "--json"]).expect("update --json should parse");
assert!(cli.json);
assert_eq!(cli.action, Some(Action::Update));
}
#[test]
fn parses_install_and_uninstall_actions() {
let install =
Cli::try_parse_from(["tr300", "install"]).expect("install action should parse");
let uninstall =
Cli::try_parse_from(["tr300", "uninstall"]).expect("uninstall action should parse");
assert_eq!(install.action, Some(Action::Install));
assert_eq!(uninstall.action, Some(Action::Uninstall));
}
#[test]
fn rejects_positional_and_flag_action_conflict() {
let err = Cli::try_parse_from(["tr300", "update", "--install"]).unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::ArgumentConflict);
}
}