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

difftreelog

source

crates/jrsonnet-cli/src/tla.rs1.8 KiBsourcehistory
1use clap::Parser;2use jrsonnet_evaluator::{error::Result, EvaluationState};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(14		long,15		short = 'A',16		name = "name[=tla data]",17		number_of_values = 1,18		multiple_occurrences = true19	)]20	tla_str: Vec<ExtStr>,21	/// Read top level argument string from file.22	/// See also `--tla-str`23	#[clap(24		long,25		name = "name=tla path",26		number_of_values = 1,27		multiple_occurrences = true28	)]29	tla_str_file: Vec<ExtFile>,30	/// Add top level argument from code.31	/// See also `--tla-str`32	#[clap(33		long,34		name = "name[=tla source]",35		number_of_values = 1,36		multiple_occurrences = true37	)]38	tla_code: Vec<ExtStr>,39	/// Read top level argument code from file.40	/// See also `--tla-str`41	#[clap(42		long,43		name = "name=tla code path",44		number_of_values = 1,45		multiple_occurrences = true46	)]47	tla_code_file: Vec<ExtFile>,48}49impl ConfigureState for TLAOpts {50	fn configure(&self, state: &EvaluationState) -> Result<()> {51		for tla in self.tla_str.iter() {52			state.add_tla_str((&tla.name as &str).into(), (&tla.value as &str).into());53		}54		for tla in self.tla_str_file.iter() {55			state.add_tla_str((&tla.name as &str).into(), (&tla.value as &str).into())56		}57		for tla in self.tla_code.iter() {58			state.add_tla_code((&tla.name as &str).into(), (&tla.value as &str).into())?;59		}60		for tla in self.tla_code_file.iter() {61			state.add_tla_code((&tla.name as &str).into(), (&tla.value as &str).into())?;62		}63		Ok(())64	}65}