-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
64 lines (59 loc) · 1.65 KB
/
Copy pathlib.rs
File metadata and controls
64 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! # tmpltool
//!
//! A template rendering tool that uses Tera templates with environment variables.
//!
//! This library provides functionality to render Tera templates with all environment
//! variables available as context. It can output to either a file or stdout.
//!
//! # Custom Functions
//!
//! tmpltool provides custom Tera functions that can be used in templates:
//!
//! - `env()` - Get environment variables with optional default values
//!
//! See the [`functions`] module for more details on available functions.
pub mod cli;
pub mod context;
pub mod filters;
pub mod functions;
pub mod renderer;
pub mod validator;
pub use cli::Cli;
pub use context::TemplateContext;
pub use renderer::render_template;
use clap::Parser;
use std::ffi::OsString;
/// Run the template tool with the given command line arguments.
///
/// This function parses command line arguments and renders the template.
/// It's designed to be testable by accepting arguments programmatically.
///
/// # Arguments
///
/// * `args` - Iterator of command line arguments (including program name as first element)
///
/// # Returns
///
/// Returns `Ok(())` on success, or an error describing what went wrong.
///
/// # Example
///
/// ```no_run
/// use tmpltool::run;
///
/// // Run with custom arguments
/// let result = run(["tmpltool", "template.tmpl", "-o", "output.txt"]);
/// ```
pub fn run<I, T>(args: I) -> Result<(), Box<dyn std::error::Error>>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
let cli = Cli::try_parse_from(args)?;
render_template(
cli.template.as_deref(),
cli.output.as_deref(),
cli.trust,
cli.validate,
)
}