git.delta.rocks / jrsonnet / refs/commits / 9b1cb43cbd7b

difftreelog

source

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