difftreelog
fix clap now requires multiple_occurrences
in: master
2 files changed
crates/jrsonnet-cli/src/ext.rsdiffbeforeafterboth1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState};4use std::{fs::read_to_string, 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(Clone)]32pub struct ExtFile {33 pub name: String,34 pub value: String,35}3637impl FromStr for ExtFile {38 type Err = String;3940 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {41 let out: Vec<&str> = s.split('=').collect();42 if out.len() != 2 {43 return Err("bad ext-file syntax".to_owned());44 }45 let file = read_to_string(&out[1]);46 match file {47 Ok(content) => Ok(Self {48 name: out[0].into(),49 value: content,50 }),51 Err(e) => Err(format!("{}", e)),52 }53 }54}5556#[derive(Clap)]57#[clap(help_heading = "EXTERNAL VARIABLES")]58pub struct ExtVarOpts {59 /// Add string external variable.60 /// External variables are globally available so it is preferred61 /// to use top level arguments whenever it's possible.62 /// If [=data] is not set then it will be read from `name` env variable.63 /// Can be accessed from code via `std.extVar("name")`.64 #[clap(long, short = 'V', name = "name[=var data]", number_of_values = 1)]65 ext_str: Vec<ExtStr>,66 /// Read string external variable from file.67 /// See also `--ext-str`68 #[clap(long, name = "name=var path", number_of_values = 1)]69 ext_str_file: Vec<ExtFile>,70 /// Add external variable from code.71 /// See also `--ext-str`72 #[clap(long, name = "name[=var source]", number_of_values = 1)]73 ext_code: Vec<ExtStr>,74 /// Read string external variable from file.75 /// See also `--ext-str`76 #[clap(long, name = "name=var code path", number_of_values = 1)]77 ext_code_file: Vec<ExtFile>,78}79impl ConfigureState for ExtVarOpts {80 fn configure(&self, state: &EvaluationState) -> Result<()> {81 for ext in self.ext_str.iter() {82 state.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());83 }84 for ext in self.ext_str_file.iter() {85 state.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());86 }87 for ext in self.ext_code.iter() {88 state.add_ext_code((&ext.name as &str).into(), (&ext.value as &str).into())?;89 }90 for ext in self.ext_code_file.iter() {91 state.add_ext_code((&ext.name as &str).into(), (&ext.value as &str).into())?;92 }93 Ok(())94 }95}1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState};4use std::{fs::read_to_string, 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(Clone)]32pub struct ExtFile {33 pub name: String,34 pub value: String,35}3637impl FromStr for ExtFile {38 type Err = String;3940 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {41 let out: Vec<&str> = s.split('=').collect();42 if out.len() != 2 {43 return Err("bad ext-file syntax".to_owned());44 }45 let file = read_to_string(&out[1]);46 match file {47 Ok(content) => Ok(Self {48 name: out[0].into(),49 value: content,50 }),51 Err(e) => Err(format!("{}", e)),52 }53 }54}5556#[derive(Clap)]57#[clap(help_heading = "EXTERNAL VARIABLES")]58pub struct ExtVarOpts {59 /// Add string external variable.60 /// External variables are globally available so it is preferred61 /// to use top level arguments whenever it's possible.62 /// If [=data] is not set then it will be read from `name` env variable.63 /// Can be accessed from code via `std.extVar("name")`.64 #[clap(65 long,66 short = 'V',67 name = "name[=var data]",68 number_of_values = 1,69 multiple_occurrences = true70 )]71 ext_str: Vec<ExtStr>,72 /// Read string external variable from file.73 /// See also `--ext-str`74 #[clap(75 long,76 name = "name=var path",77 number_of_values = 1,78 multiple_occurrences = true79 )]80 ext_str_file: Vec<ExtFile>,81 /// Add external variable from code.82 /// See also `--ext-str`83 #[clap(84 long,85 name = "name[=var source]",86 number_of_values = 1,87 multiple_occurrences = true88 )]89 ext_code: Vec<ExtStr>,90 /// Read string external variable from file.91 /// See also `--ext-str`92 #[clap(93 long,94 name = "name=var code path",95 number_of_values = 1,96 multiple_occurrences = true97 )]98 ext_code_file: Vec<ExtFile>,99}100impl ConfigureState for ExtVarOpts {101 fn configure(&self, state: &EvaluationState) -> Result<()> {102 for ext in self.ext_str.iter() {103 state.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());104 }105 for ext in self.ext_str_file.iter() {106 state.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());107 }108 for ext in self.ext_code.iter() {109 state.add_ext_code((&ext.name as &str).into(), (&ext.value as &str).into())?;110 }111 for ext in self.ext_code_file.iter() {112 state.add_ext_code((&ext.name as &str).into(), (&ext.value as &str).into())?;113 }114 Ok(())115 }116}crates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -9,19 +9,40 @@
/// Top level arguments will be passed to function before manifestification stage.
/// This is preferred to ExtVars method.
/// If [=data] is not set then it will be read from `name` env variable.
- #[clap(long, short = 'A', name = "name[=tla data]", number_of_values = 1)]
+ #[clap(
+ long,
+ short = 'A',
+ name = "name[=tla data]",
+ number_of_values = 1,
+ multiple_occurrences = true
+ )]
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)]
+ #[clap(
+ long,
+ name = "name=tla path",
+ number_of_values = 1,
+ multiple_occurrences = true
+ )]
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)]
+ #[clap(
+ long,
+ name = "name[=tla source]",
+ number_of_values = 1,
+ multiple_occurrences = true
+ )]
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)]
+ #[clap(
+ long,
+ name = "name=tla code path",
+ number_of_values = 1,
+ multiple_occurrences = true
+ )]
tla_code_file: Vec<ExtFile>,
}
impl ConfigureState for TLAOpts {