From 7e123b78a2cf0f88962fc14401d156488db1f0ed Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:58:42 +0100 Subject: [PATCH] fix(deps): update rust crate clap-stdin to 0.5.0 (#28) * fix(deps): update rust crate clap-stdin to 0.5.0 * fix: adapt to clap-stdin breaking change --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: backwardspy --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/main.rs | 30 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f94e449..b2c4408 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,9 +244,9 @@ dependencies = [ [[package]] name = "clap-stdin" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc126d12a0930c94c3548581294d5f19360ac02e408600b4d7619d7234e8b505" +checksum = "471df7896633bfc1e7d3da5b598422891e4cb8931210168ec63ea586e285803f" dependencies = [ "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index e0b3baa..ab72af7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ anyhow = "1.0.86" base64 = "0.22.1" catppuccin = { version = "2.4.0", features = ["serde", "css-colors"] } clap = { version = "4.5.4", features = ["derive"] } -clap-stdin = "0.4.0" +clap-stdin = "0.5.0" css-colors = "1.0.1" detect-newline-style = "0.1.2" encoding_rs_io = "0.1.7" diff --git a/src/main.rs b/src/main.rs index 93457d1..5010f4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,17 +104,17 @@ fn main() -> anyhow::Result<()> { let args = Args::parse(); handle_list_flags(&args); - let template = args + let template_arg = args .template - .as_ref() + .clone() .expect("args.template is guaranteed by clap to be set"); - let template_from_stdin = matches!(template.source, clap_stdin::Source::Stdin); - let template_name = template_name(template); + let template_from_stdin = template_arg.is_stdin(); + let template_name = template_name(&template_arg); let template_directory = - template_directory(template).context("Template file does not exist")?; + template_directory(&template_arg).context("Template file does not exist")?; let mut decoder = DecodeReaderBytes::new( - template + template_arg .into_reader() .context("Failed to open template file")?, ); @@ -421,23 +421,25 @@ fn list_accents(format: OutputFormat) { } fn template_name(template: &clap_stdin::FileOrStdin) -> String { - match &template.source { - clap_stdin::Source::Stdin => "template".to_string(), - clap_stdin::Source::Arg(arg) => Path::new(&arg).file_name().map_or_else( + if template.is_stdin() { + "template".to_string() + } else { + Path::new(template.filename()).file_name().map_or_else( || "template".to_string(), |name| name.to_string_lossy().to_string(), - ), + ) } } fn template_directory(template: &clap_stdin::FileOrStdin) -> anyhow::Result { - match &template.source { - clap_stdin::Source::Stdin => Ok(std::env::current_dir()?), - clap_stdin::Source::Arg(arg) => Ok(Path::new(&arg) + if template.is_stdin() { + Ok(std::env::current_dir()?) + } else { + Ok(Path::new(template.filename()) .canonicalize()? .parent() .expect("file path must have a parent") - .to_owned()), + .to_owned()) } }