1use clap::Parser;2use jrsonnet_evaluator::{3 error::{Error, Result},4 function::TlaArg,5 gc::GcHashMap,6 IStr, State,7};8use jrsonnet_parser::{ParserSettings, Source};910use crate::{ConfigureState, ExtFile, ExtStr};1112#[derive(Parser)]13#[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]14pub struct TlaOpts {15 16 17 18 19 #[clap(long, short = 'A', name = "name[=tla data]", number_of_values = 1)]20 tla_str: Vec<ExtStr>,21 22 23 #[clap(long, name = "name=tla path", number_of_values = 1)]24 tla_str_file: Vec<ExtFile>,25 26 27 #[clap(long, name = "name[=tla source]", number_of_values = 1)]28 tla_code: Vec<ExtStr>,29 30 31 #[clap(long, name = "name=tla code path", number_of_values = 1)]32 tla_code_file: Vec<ExtFile>,33}34impl ConfigureState for TlaOpts {35 type Guards = GcHashMap<IStr, TlaArg>;36 fn configure(&self, _s: &State) -> Result<Self::Guards> {37 let mut out = GcHashMap::new();38 for (name, value) in self39 .tla_str40 .iter()41 .map(|c| (&c.name, &c.value))42 .chain(self.tla_str_file.iter().map(|c| (&c.name, &c.value)))43 {44 out.insert(name.into(), TlaArg::String(value.into()));45 }46 for (name, code) in self47 .tla_code48 .iter()49 .map(|c| (&c.name, &c.value))50 .chain(self.tla_code_file.iter().map(|c| (&c.name, &c.value)))51 {52 let source = Source::new_virtual(format!("<top-level-arg:{name}>").into(), code.into());53 out.insert(54 (&name as &str).into(),55 TlaArg::Code(56 jrsonnet_parser::parse(57 &code,58 &ParserSettings {59 source: source.clone(),60 },61 )62 .map_err(|e| Error::ImportSyntaxError {63 path: source,64 error: Box::new(e),65 })?,66 ),67 );68 }69 Ok(out)70 }71}