Skip to content

Commit

Permalink
error message when template file doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mothsART committed Aug 23, 2024
1 parent 0392c62 commit e720e11
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ fn main() {

if let Some(template_m) = matches.subcommand_matches("template") {
if let Some(input) = template_m.get_one::<PathBuf>("input") {
let contents =
fs::read_to_string(input).expect("Should have been able to read the file");

let ast = Ast::from_str(&contents, &Syntax::default()).unwrap();

let mut g = Generator::new(template_m);

if let Err(err) = g.handle(ast.nodes(), AstLevel::Top) {
eprint!("{}", err);
return;
if let Ok(contents) = fs::read_to_string(input) {
let ast = Ast::from_str(&contents, &Syntax::default()).unwrap();

let mut g = Generator::new(template_m);

if let Err(err) = g.handle(ast.nodes(), AstLevel::Top) {
eprint!("{}", err);
return;
}
println!("{}", g.render());
} else {
eprint!("Should have been able to read the file \"{}\"", input.as_path().display());
}
println!("{}", g.render());
}
return;
}
Expand Down

0 comments on commit e720e11

Please sign in to comment.