use super::*; use clap::Parser; /// Parse `sm121 health ` and return the parsed `--format`. fn health_format(args: &[&str]) -> Result<(OutputFormat, bool), clap::Error> { let cli = Cli::try_parse_from( std::iter::once("sm121") .chain(std::iter::once("health")) .chain(args.iter().copied()), )?; let Commands::Health { fingerprint, format, .. } = cli.command else { panic!("expected Health") }; Ok((format, fingerprint)) } #[test] fn health_format_defaults_to_plain() { assert_eq!(health_format(&[]).unwrap(), (OutputFormat::Plain, false)); } #[test] fn health_format_parses_each_variant() { assert_eq!( health_format(&["--format", "plain"]).unwrap().0, OutputFormat::Plain ); assert_eq!( health_format(&["--format", "md"]).unwrap().0, OutputFormat::Md ); assert_eq!( health_format(&["--format", "html"]).unwrap().0, OutputFormat::Html ); } #[test] fn health_format_combines_with_cluster_and_fingerprint() { let (fmt, fp) = health_format(&["--cluster", "c1", "--format", "md"]).unwrap(); assert_eq!((fmt, fp), (OutputFormat::Md, false)); let (fmt, fp) = health_format(&["--fingerprint", "--format", "html"]).unwrap(); assert_eq!((fmt, fp), (OutputFormat::Html, true)); } #[test] fn health_format_rejects_invalid_value() { assert!(health_format(&["--format", "bogus"]).is_err()); } #[test] fn report_flag_defaults_and_overrides() { let cli = Cli::try_parse_from(["sm121", "report"]).unwrap(); let Commands::Report { serve, port, open, archive: _, unarchive: _, archived: _, } = cli.command else { unreachable!() }; assert!(!serve && !open); assert_eq!(port, 3101); let cli = Cli::try_parse_from(["sm121", "report", "--open", "--port", "4000"]).unwrap(); let Commands::Report { open, port, .. } = cli.command else { unreachable!() }; assert!(open); assert_eq!(port, 4000); }