1use clap::Parser;2use jrsonnet_evaluator::{3 error::{ErrorKind, Result},4 function::TlaArg,5 gc::WithCapacityExt as _,6 rustc_hash::FxHashMap,7 IStr,8};9use jrsonnet_parser::{ParserSettings, Source};1011use crate::{ExtFile, ExtStr};1213#[derive(Parser)]14#[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]15pub struct TlaOpts {16 17 18 19 20 #[clap(long, short = 'A', name = "name[=tla data]", number_of_values = 1)]21 tla_str: Vec<ExtStr>,22 23 24 #[clap(long, name = "name=tla path", number_of_values = 1)]25 tla_str_file: Vec<ExtFile>,26 27 28 #[clap(long, name = "name[=tla source]", number_of_values = 1)]29 tla_code: Vec<ExtStr>,30 31 32 #[clap(long, name = "name=tla code path", number_of_values = 1)]33 tla_code_file: Vec<ExtFile>,34}35impl TlaOpts {36 pub fn tla_opts(&self) -> Result<FxHashMap<IStr, TlaArg>> {37 let mut out = FxHashMap::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| ErrorKind::ImportSyntaxError {63 path: source,64 error: Box::new(e),65 })?,66 ),67 );68 }69 Ok(out)70 }71}