mirror of
https://github.com/ratspeak/rsLXMF
synced 2026-11-22 23:10:35 +00:00
lxmd: accept the released -c and -V spellings with a warning
This commit is contained in:
1 parent
c6fd9e488b
commit
c90b371c3d
3 files changed
+56
-11
No files matched your search
@@ -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!(
|
||||
|
||||
@@ -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<String>,
|
||||
|
||||
/// 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]
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
Reference in new issue
Block a user