From c90b371c3d2b768265c93068479ccce4fd2fd77b Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:59:58 -0700 Subject: [PATCH] lxmd: accept the released -c and -V spellings with a warning --- crates/lxmf-tools/src/commands/lxmd.rs | 5 ++++ crates/lxmf-tools/src/lxmd_cli.rs | 27 ++++++++++++-------- crates/lxmf-tools/tests/lxmd_cli.rs | 35 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/crates/lxmf-tools/src/commands/lxmd.rs b/crates/lxmf-tools/src/commands/lxmd.rs index 04d81ae..dea1368 100644 --- a/crates/lxmf-tools/src/commands/lxmd.rs +++ b/crates/lxmf-tools/src/commands/lxmd.rs @@ -6334,9 +6334,14 @@ fn initialize_storage_namespace(config_dir: &Path) -> std::io::Result<()> { Ok(()) } +/// Rust-only spellings the 1.3 and 1.4 releases accepted, kept for existing +/// scripts (lxmd.py has `--config` and `--version` only). +const DEPRECATED_SPELLINGS: &[(&str, &str)] = &[("-c", "--config"), ("-V", "--version")]; + #[tokio::main] pub(crate) async fn main() { let args = Args::parse(); + rns_tools::warn_deprecated_spellings("lxmd-rs", DEPRECATED_SPELLINGS); if args.version { println!( diff --git a/crates/lxmf-tools/src/lxmd_cli.rs b/crates/lxmf-tools/src/lxmd_cli.rs index e57f45e..558072d 100644 --- a/crates/lxmf-tools/src/lxmd_cli.rs +++ b/crates/lxmf-tools/src/lxmd_cli.rs @@ -39,7 +39,7 @@ pub const LXMF_COMPAT_VERSION: &str = "1.3.0"; )] pub struct Args { /// Path to configuration directory. - #[arg(long)] + #[arg(long, short_alias = 'c')] pub config: Option, /// Path to alternative Reticulum configuration directory. @@ -84,7 +84,7 @@ pub struct Args { pub exampleconfig: bool, /// Print version and exit. - #[arg(long)] + #[arg(long, short_alias = 'V')] pub version: bool, /// Service mode; the process remains in the foreground. @@ -271,17 +271,22 @@ mod tests { assert_eq!(args.identity.as_deref(), Some(Path::new("/tmp/id"))); } - // lxmd.py has `--config` and `--version` only: no `-c`, no `-V`. + // lxmd.py has `--config` and `--version` only; the releases also took + // `-c` and `-V`, which still parse and stay out of the help. #[test] - fn short_forms_upstream_lacks_are_refused() { - for flag in [&["-c", "/tmp/lxmd"][..], &["-V"]] { - let error = Args::try_parse_from(["lxmd"].iter().chain(flag)) - .err() - .unwrap_or_else(|| panic!("{flag:?} must be refused")); - assert_eq!(error.kind(), clap::error::ErrorKind::UnknownArgument); - assert_eq!(error.exit_code(), 2, "argparse exits 2"); - } + fn released_short_forms_still_parse_and_are_hidden() { + let args = Args::try_parse_from(["lxmd", "-c", "/tmp/lxmd"]).unwrap(); + assert_eq!(args.config.as_deref(), Some("/tmp/lxmd")); + assert!(Args::try_parse_from(["lxmd", "-V"]).unwrap().version); assert!(Args::try_parse_from(["lxmd", "--version"]).unwrap().version); + + use clap::CommandFactory; + let help = Args::command().render_long_help().to_string(); + assert!(help.contains("--config") && help.contains("--version")); + assert!(!help.contains("-c,") && !help.contains("-V,"), "{help}"); + + let error = Args::try_parse_from(["lxmd", "-x"]).err().unwrap(); + assert_eq!(error.exit_code(), 2, "argparse exits 2"); } #[test] diff --git a/crates/lxmf-tools/tests/lxmd_cli.rs b/crates/lxmf-tools/tests/lxmd_cli.rs index 381c50f..0f0c476 100644 --- a/crates/lxmf-tools/tests/lxmd_cli.rs +++ b/crates/lxmf-tools/tests/lxmd_cli.rs @@ -219,6 +219,41 @@ fn rust_binary_runs_cli() { assert!(stderr(&output).is_empty()); } +/// `-c` and `-V` are spellings the 1.3 and 1.4 releases accepted and +/// upstream never had: they still work and are announced on stderr. +#[test] +fn released_short_spellings_work_with_a_warning() { + let long = lxmd(&["--config", "/nonexistent/lxmd", "--exampleconfig"]); + assert!(long.status.success(), "{}", combined_output(&long)); + assert!(stderr(&long).is_empty()); + for short in [ + &["-c", "/nonexistent/lxmd", "--exampleconfig"][..], + &["-c/nonexistent/lxmd", "--exampleconfig"], + ] { + let output = lxmd(short); + assert!(output.status.success(), "{}", combined_output(&output)); + assert_eq!(stdout(&output), stdout(&long), "{short:?}"); + assert_eq!( + stderr(&output), + "lxmd-rs: warning: -c is deprecated, use --config\n", + "{short:?}" + ); + } + + let version = lxmd(&["--version"]); + let short = lxmd(&["-V"]); + assert!(short.status.success(), "{}", combined_output(&short)); + assert_eq!(stdout(&short), stdout(&version)); + assert_eq!( + stderr(&short), + "lxmd-rs: warning: -V is deprecated, use --version\n" + ); + + let help = stdout(&lxmd(&["--help"])); + assert!(help.contains("--config") && help.contains("--version")); + assert!(!help.contains("-c,") && !help.contains("-V,"), "{help}"); +} + #[test] fn example_config_exits_before_runtime_initialisation() { let output = lxmd(&["--exampleconfig"]);