git.delta.rocks / jrsonnet / refs/commits / fe52b32db444

difftreelog

source

crates/jrsonnet-cli/src/tla.rs1.6 KiBsourcehistory
1use clap::Parser;2use jrsonnet_evaluator::{error::Result, State};34use crate::{ConfigureState, ExtFile, ExtStr};56#[derive(Parser)]7#[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]8pub struct TLAOpts {9	/// Add top level string argument.10	/// Top level arguments will be passed to function before manifestification stage.11	/// This is preferred to ExtVars method.12	/// If [=data] is not set then it will be read from `name` env variable.13	#[clap(long, short = 'A', name = "name[=tla data]", number_of_values = 1)]14	tla_str: Vec<ExtStr>,15	/// Read top level argument string from file.16	/// See also `--tla-str`17	#[clap(long, name = "name=tla path", number_of_values = 1)]18	tla_str_file: Vec<ExtFile>,19	/// Add top level argument from code.20	/// See also `--tla-str`21	#[clap(long, name = "name[=tla source]", number_of_values = 1)]22	tla_code: Vec<ExtStr>,23	/// Read top level argument code from file.24	/// See also `--tla-str`25	#[clap(long, name = "name=tla code path", number_of_values = 1)]26	tla_code_file: Vec<ExtFile>,27}28impl ConfigureState for TLAOpts {29	type Guards = ();30	fn configure(&self, s: &State) -> Result<()> {31		for tla in self.tla_str.iter() {32			s.add_tla_str((&tla.name as &str).into(), (&tla.value as &str).into());33		}34		for tla in self.tla_str_file.iter() {35			s.add_tla_str((&tla.name as &str).into(), (&tla.value as &str).into())36		}37		for tla in self.tla_code.iter() {38			s.add_tla_code((&tla.name as &str).into(), &tla.value as &str)?;39		}40		for tla in self.tla_code_file.iter() {41			s.add_tla_code((&tla.name as &str).into(), &tla.value as &str)?;42		}43		Ok(())44	}45}