Skip to content

Commit

Permalink
Merge pull request #4 from olorin37/e
Browse files Browse the repository at this point in the history
Support for output option (writing to spedified file)
  • Loading branch information
olorin37 authored Jan 14, 2020
2 parents a66356a + 97353cf commit 845757e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions fixtures/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
num: 1234567899
1 change: 1 addition & 0 deletions fixtures/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cześć 1234567899.
1 change: 1 addition & 0 deletions fixtures/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cześć {{num}}.
6 changes: 6 additions & 0 deletions fixtures/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

## run it from /fixtures

../target/debug/hbs-cli data.yaml template.hbs -o a.txt
diff out.txt a.txt
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let data: Value = serde_yaml::from_reader(propsfile)?;
let template = fs::read_to_string(opt.template)?;

println!(
"{}",
reg.render_template(&template, &data)?
);
let text = reg.render_template(&template, &data)?;
match opt.output {
Some(path) => fs::write(path, text)?,
None => println!("{}", text),
};

Ok(())
}

0 comments on commit 845757e

Please sign in to comment.