1use anyhow::Result;
2use clap::Parser;
3
4use crate::{eval, model, query};
5
6#[derive(Parser, Clone, Debug)]
8#[command(author, about, long_about)]
9pub struct EvalOptions {
10 #[arg(long, short = 'D')]
12 define: Vec<String>,
13 expr: String,
15 tree: Option<String>,
17 garden: Option<String>,
19}
20
21pub fn main(app_context: &model::ApplicationContext, eval: &EvalOptions) -> Result<()> {
23 app_context
24 .get_root_config_mut()
25 .apply_defines(&eval.define);
26 match eval.tree.as_ref() {
27 None => {
28 let config = app_context.get_root_config();
31 let value = eval::value(app_context, config, &eval.expr);
32 println!("{value}");
33 }
34 Some(tree) => {
35 let garden = eval.garden.as_deref();
37 let ctx = query::find_tree(app_context, app_context.get_root_id(), tree, garden)?;
38 let graft_config = ctx.config.map(|graft_id| app_context.get_config(graft_id));
39 let value = eval::tree_value(
40 app_context,
41 app_context.get_root_config(),
42 graft_config,
43 &eval.expr,
44 &ctx.tree,
45 ctx.garden.as_ref(),
46 );
47 println!("{value}");
48 }
49 }
50
51 Ok(())
52}