Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update rust crate clap-stdin to 0.5.0 #28

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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