git.delta.rocks / jrsonnet / refs/commits / 5858c9313e03

difftreelog

source

crates/jrsonnet-cli/src/tla.rs1.7 KiBsourcehistory
1use clap::Parser;2use jrsonnet_evaluator::{3	IStr, error::Result, gc::WithCapacityExt as _, rustc_hash::FxHashMap, tla::TlaArg,4};56use crate::{ExtFile, ExtStr};78#[derive(Parser)]9#[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]10#[allow(clippy::struct_field_names)]11pub struct TlaOpts {12	/// Add top level string argument.13	/// Top level arguments will be passed to function before manifestification stage.14	/// This is preferred to [`ExtVars`] method.15	/// If [=data] is not set then it will be read from `name` env variable.16	#[clap(long, short = 'A', name = "name[=tla data]", number_of_values = 1)]17	tla_str: Vec<ExtStr>,18	/// Read top level argument string from file.19	/// See also `--tla-str`20	#[clap(long, name = "name=tla path", number_of_values = 1)]21	tla_str_file: Vec<ExtFile>,22	/// Add top level argument from code.23	/// See also `--tla-str`24	#[clap(long, name = "name[=tla source]", number_of_values = 1)]25	tla_code: Vec<ExtStr>,26	/// Read top level argument code from file.27	/// See also `--tla-str`28	#[clap(long, name = "name=tla code path", number_of_values = 1)]29	tla_code_file: Vec<ExtFile>,30}31impl TlaOpts {32	pub fn tla_opts(&self) -> Result<FxHashMap<IStr, TlaArg>> {33		let mut out = FxHashMap::new();34		for ext in &self.tla_str {35			out.insert(36				ext.name.as_str().into(),37				TlaArg::String(ext.value.as_str().into()),38			);39		}40		for ext in &self.tla_str_file {41			out.insert(42				ext.name.as_str().into(),43				TlaArg::ImportStr(ext.name.as_str().into()),44			);45		}46		for ext in &self.tla_code {47			out.insert(48				ext.name.as_str().into(),49				TlaArg::InlineCode(ext.value.clone()),50			);51		}52		for ext in &self.tla_code_file {53			out.insert(ext.name.as_str().into(), TlaArg::Import(ext.path.clone()));54		}55		Ok(out)56	}57}