Skip to content

Commit

Permalink
Some simplifications because extension() starts at the last dot.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmice committed Mar 18, 2024
1 parent 531bc10 commit 7ac8e39
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions naga-cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,23 +561,19 @@ fn parse_input(
) -> Result<Parsed, Box<dyn std::error::Error>> {
let input_kind = match params.input_kind {
Some(kind) => kind,
None => {
let ext = input_path
None => InputKind::from_str(
input_path
.extension()
.ok_or(CliError::from("Input filename has no extension"))?
.to_str()
.ok_or(CliError::from("Input filename not valid unicode"))?;
InputKind::from_str(ext).or_else(|_| {
InputKind::from_str(
Path::new(ext)
.extension()
.ok_or(CliError::from("Input filename has unknown extension"))?
.to_str()
.ok_or(CliError::from("Input filename not valid unicode"))?,
)
.map_err(|e| CliError::from(e).context(CliError::from("from input filename")))
})?
}
.ok_or(CliError::from("Input filename not valid unicode"))?,
)
.map_err(|e| {
CliError::from(e).context(CliError::from(format!(
"for input filename {}",
input_path.display()
)))
})?,
};
let (module, input_text) = match input_kind {
InputKind::Bincode => (bincode::deserialize(&input)?, None),
Expand Down

0 comments on commit 7ac8e39

Please sign in to comment.