36 lines
1.0 KiB
Rust
36 lines
1.0 KiB
Rust
|
use clap::Parser;
|
||
|
use std::collections::HashMap;
|
||
|
|
||
|
mod tera_lib;
|
||
|
use crate::tera_lib::{hash_from_data, data_templated};
|
||
|
|
||
|
#[derive(Parser, Debug)]
|
||
|
#[clap(author, version, about, long_about = None)]
|
||
|
struct Args {
|
||
|
/// Data file
|
||
|
#[clap(short, long)]
|
||
|
data: String,
|
||
|
|
||
|
/// Template file
|
||
|
#[clap(short, long)]
|
||
|
tpl: String,
|
||
|
|
||
|
/// Number of times to greet
|
||
|
#[clap(short, long, default_value_t = 1)]
|
||
|
count: u8,
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let args = Args::parse();
|
||
|
let mut data_hash: HashMap<String, String> = HashMap::new();
|
||
|
let mut tpl_context = tera::Context::new();
|
||
|
match hash_from_data(&args.data, &mut tpl_context, &mut data_hash, true) {
|
||
|
Ok(_) =>
|
||
|
match data_templated(&"".to_string(),&args.tpl,&mut tpl_context, &data_hash) {
|
||
|
Ok(result) => println!("{}",result),
|
||
|
Err(e) => println!("Error with {} data in {} template: {}", args.data, args.tpl, e),
|
||
|
},
|
||
|
Err(e) => println!("Error with {} data in {} template: {}", args.data, args.tpl, e),
|
||
|
}
|
||
|
}
|