#![allow(missing_docs)]
use cirious_codex_cli::{CodexCommand, GlobalArgs};
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(name = "test_app")]
struct TestCLI {
#[command(flatten)]
global: GlobalArgs,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug, PartialEq)]
enum Commands {
Start { port: u16 },
Ping,
}
impl CodexCommand for TestCLI {
fn global_args(&self) -> &GlobalArgs {
&self.global
}
}
#[test]
fn test_global_flags_extraction() {
let mock_args = vec!["test_app", "--verbose", "--config", "env.toml", "start", "8080"];
let parsed_cli = TestCLI::try_parse_from(mock_args).expect("Failed to parse valid CLI arguments");
let globals = parsed_cli.global_args();
assert!(globals.verbose, "The verbose flag should be true");
assert_eq!(
globals.config.as_deref(),
Some("env.toml"),
"The config path did not match"
);
match parsed_cli.command {
Commands::Start { port } => assert_eq!(port, 8080, "The port should be parsed as 8080"),
_ => panic!("The router selected the wrong sub-command!"),
}
}
#[test]
fn test_missing_required_subcommand_fails() {
let mock_args = vec!["test_app", "--verbose"];
let result = TestCLI::try_parse_from(mock_args);
assert!(
result.is_err(),
"Clap should have rejected the input due to a missing subcommand"
);
}