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

difftreelog

source

crates/jrsonnet-cli/src/tla.rs1.7 KiBsourcehistory
1use clap::Parser;2use jrsonnet_evaluator::{IStr, error::Result, function::TlaArg, gc::WithCapacityExt as _, rustc_hash::FxHashMap};34use crate::{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 TlaOpts {29	pub fn tla_opts(&self) -> Result<FxHashMap<IStr, TlaArg>> {30		let mut out = FxHashMap::new();31		for ext in &self.tla_str {32			out.insert(33				ext.name.as_str().into(),34				TlaArg::String(ext.value.as_str().into()),35			);36		}37		for ext in &self.tla_str_file {38			out.insert(39				ext.name.as_str().into(),40				TlaArg::ImportStr(ext.name.as_str().into()),41			);42		}43		for ext in &self.tla_code {44			out.insert(45				ext.name.as_str().into(),46				TlaArg::InlineCode(ext.value.clone()),47			);48		}49		for ext in &self.tla_code_file {50			out.insert(ext.name.as_str().into(), TlaArg::Import(ext.path.clone()));51		}52		Ok(out)53	}54}