Skip to content

Commit

Permalink
fix(deps): update rust crate clap-stdin to 0.5.0 (#28)
Browse files Browse the repository at this point in the history
* 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 <backwardspy@pigeon.life>
  • Loading branch information
renovate[bot] and backwardspy authored Sep 8, 2024
1 parent 088fc13 commit 7e123b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 16 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?,
);
Expand Down Expand Up @@ -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<PathBuf> {
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())
}
}

Expand Down

0 comments on commit 7e123b7

Please sign in to comment.