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

difftreelog

feat --tla-str-file

Lach2020-08-25parent: #cb35228.patch.diff
in: master

4 files changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -53,7 +53,7 @@
 	opts.general.configure(&state)?;
 	opts.manifest.configure(&state)?;
 
-	let val = if opts.input.evaluate {
+	let val = if opts.input.exec {
 		state.evaluate_snippet_raw(
 			Rc::new(PathBuf::from("args")),
 			(&opts.input.input as &str).into(),
modifiedcrates/jrsonnet-cli/src/ext.rsdiffbeforeafterboth
before · crates/jrsonnet-cli/src/ext.rs
1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState};4use std::str::FromStr;56#[derive(Clone)]7pub struct ExtStr {8	pub name: String,9	pub value: String,10}1112impl FromStr for ExtStr {13	type Err = &'static str;14	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {15		let out: Vec<_> = s.split('=').collect();16		match out.len() {17			1 => Ok(ExtStr {18				name: out[0].to_owned(),19				value: std::env::var(out[0]).or(Err("missing env var"))?,20			}),21			2 => Ok(ExtStr {22				name: out[0].to_owned(),23				value: out[1].to_owned(),24			}),2526			_ => Err("bad ext-str syntax"),27		}28	}29}3031#[derive(Clap)]32// #[clap(help_heading = "EXTERNAL VARIABLES")]33pub struct ExtVarOpts {34	/// Add string external variable.35	/// External variables are globally available so it is preferred36	/// to use top level arguments whenever it's possible.37	/// If [=data] is not set then it will be read from `name` env variable.38	/// Can be accessed from code via `std.extVar("name")`.39	#[clap(long, short = 'V', name = "name[=var data]", number_of_values = 1)]40	ext_str: Vec<ExtStr>,41	// / Read string external variable from file.42	// / See also `--ext-str`43	// #[clap(long, name = "name[=var path]", number_of_values = 1)]44	// ext_str_file: Vec<ExtStr>,45	/// Add external variable from code.46	/// See also `--ext-str`47	#[clap(long, name = "name[=var source]", number_of_values = 1)]48	ext_code: Vec<ExtStr>,49}50impl ConfigureState for ExtVarOpts {51	fn configure(&self, state: &EvaluationState) -> Result<()> {52		for ext in self.ext_str.iter() {53			state.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());54		}55		for ext in self.ext_code.iter() {56			state.add_ext_code((&ext.name as &str).into(), (&ext.value as &str).into())?;57		}58		Ok(())59	}60}
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -24,7 +24,7 @@
 		short = 'e',
 		about = "Treat input as code, evaluate them instead of reading file"
 	)]
-	pub evaluate: bool,
+	pub exec: bool,
 
 	#[clap(
 		about = "Path to the file to be compiled if `--evaluate` is unset, otherwise code itself"
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -1,4 +1,4 @@
-use crate::{ConfigureState, ExtStr};
+use crate::{ConfigureState, ExtFile, ExtStr};
 use clap::Clap;
 use jrsonnet_evaluator::{error::Result, EvaluationState};
 
@@ -13,21 +13,31 @@
 	tla_str: Vec<ExtStr>,
 	/// Read top level argument string from file.
 	/// See also `--tla-str`
-	// #[clap(long, name = "name[=tla path]", number_of_values = 1)]
-	// tla_str_file: Vec<ExtStr>,
+	#[clap(long, name = "name=tla path", number_of_values = 1)]
+	tla_str_file: Vec<ExtFile>,
 	/// Add top level argument from code.
 	/// See also `--tla-str`
 	#[clap(long, name = "name[=tla source]", number_of_values = 1)]
 	tla_code: Vec<ExtStr>,
+	/// Read top level argument code from file.
+	/// See also `--tla-str`
+	#[clap(long, name = "name=tla code path", number_of_values = 1)]
+	tla_code_file: Vec<ExtFile>,
 }
 impl ConfigureState for TLAOpts {
 	fn configure(&self, state: &EvaluationState) -> Result<()> {
 		for tla in self.tla_str.iter() {
 			state.add_tla_str((&tla.name as &str).into(), (&tla.value as &str).into());
 		}
+		for tla in self.tla_str_file.iter() {
+			state.add_tla_str((&tla.name as &str).into(), (&tla.value as &str).into())
+		}
 		for tla in self.tla_code.iter() {
 			state.add_tla_code((&tla.name as &str).into(), (&tla.value as &str).into())?;
 		}
+		for tla in self.tla_code_file.iter() {
+			state.add_tla_code((&tla.name as &str).into(), (&tla.value as &str).into())?;
+		}
 		Ok(())
 	}
 }