git.delta.rocks / jrsonnet / refs/commits / 8a2b9747ed0e

difftreelog

Merge pull request #18 from CertainLach/upgrade-clap

Yaroslav Bulyukin2020-10-19parents: #712f004 #88be4ee.patch.diff
in: master
Help headings and colors

9 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -62,8 +62,8 @@
 
 [[package]]
 name = "clap"
-version = "3.0.0-beta.1"
-source = "git+https://github.com/clap-rs/clap?rev=3e9ee86713b5c407b50ba76f30cffaed25952063#3e9ee86713b5c407b50ba76f30cffaed25952063"
+version = "3.0.0-beta.2"
+source = "git+https://github.com/clap-rs/clap?rev=1d0b21908f93478e75b4b1a21533d86325d39386#1d0b21908f93478e75b4b1a21533d86325d39386"
 dependencies = [
  "atty",
  "bitflags",
@@ -80,8 +80,8 @@
 
 [[package]]
 name = "clap_derive"
-version = "3.0.0-beta.1"
-source = "git+https://github.com/clap-rs/clap?rev=3e9ee86713b5c407b50ba76f30cffaed25952063#3e9ee86713b5c407b50ba76f30cffaed25952063"
+version = "3.0.0-beta.2"
+source = "git+https://github.com/clap-rs/clap?rev=1d0b21908f93478e75b4b1a21533d86325d39386#1d0b21908f93478e75b4b1a21533d86325d39386"
 dependencies = [
  "heck",
  "proc-macro-error",
modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -23,4 +23,4 @@
 
 [dependencies.clap]
 git = "https://github.com/clap-rs/clap"
-rev = "3e9ee86713b5c407b50ba76f30cffaed25952063"
+rev = "1d0b21908f93478e75b4b1a21533d86325d39386"
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -1,3 +1,4 @@
+use clap::AppSettings;
 use clap::Clap;
 use jrsonnet_cli::{ConfigureState, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};
 use jrsonnet_evaluator::{error::LocError, EvaluationState, ManifestFormat};
@@ -13,7 +14,7 @@
 static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;
 
 #[derive(Clap)]
-// #[clap(help_heading = "DEBUG")]
+#[clap(help_heading = "DEBUG")]
 struct DebugOpts {
 	/// Required OS stack size.
 	/// This shouldn't be changed unless jrsonnet is failing with stack overflow error.
@@ -22,6 +23,10 @@
 }
 
 #[derive(Clap)]
+#[clap(
+	global_setting = AppSettings::ColoredHelp,
+	global_setting = AppSettings::DeriveDisplayOrder,
+)]
 struct Opts {
 	#[clap(flatten)]
 	input: InputOpts,
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -13,4 +13,4 @@
 
 [dependencies.clap]
 git = "https://github.com/clap-rs/clap"
-rev = "3e9ee86713b5c407b50ba76f30cffaed25952063"
+rev = "1d0b21908f93478e75b4b1a21533d86325d39386"
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::{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}
after · crates/jrsonnet-cli/src/ext.rs
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(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}
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -17,7 +17,7 @@
 }
 
 #[derive(Clap)]
-// #[clap(help_heading = "INPUT")]
+#[clap(help_heading = "INPUT")]
 pub struct InputOpts {
 	#[clap(
 		long,
@@ -33,7 +33,7 @@
 }
 
 #[derive(Clap)]
-// #[clap(help_heading = "OPTIONS")]
+#[clap(help_heading = "OPTIONS")]
 pub struct MiscOpts {
 	/// Disable standard library.
 	/// By default standard library will be available via global `std` variable.
modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -23,8 +23,7 @@
 }
 
 #[derive(Clap)]
-// TODO: Restore arg group after issue fixed in clap
-// #[clap(group = clap::ArgGroup::new("output_format"), help_heading = "MANIFESTIFICATION OUTPUT")]
+#[clap(group = clap::ArgGroup::new("output_format"), help_heading = "MANIFESTIFICATION OUTPUT")]
 pub struct ManifestOpts {
 	/// Output format, wraps resulting value to corresponding std.manifest call.
 	/// If set to `string` then plain string value is expected to be returned,
@@ -33,7 +32,7 @@
 	format: ManifestFormatName,
 	/// Expect plain string as output.
 	/// Shortcut for `--format=string` thus this option is mutually exclusive with `format` option.
-	#[clap(long, short = 'S'/*, group = "output_format"*/)]
+	#[clap(long, short = 'S', group = "output_format")]
 	string: bool,
 	/// Write output as YAML stream, can be used with --format json/yaml
 	#[clap(long, short = 'y')]
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -3,7 +3,7 @@
 use jrsonnet_evaluator::{error::Result, EvaluationState};
 
 #[derive(Clap)]
-// #[clap(help_heading = "TOP LEVEL ARGUMENTS")]
+#[clap(help_heading = "TOP LEVEL ARGUMENTS")]
 pub struct TLAOpts {
 	/// Add top level string argument.
 	/// Top level arguments will be passed to function before manifestification stage.
modifiedcrates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -25,7 +25,7 @@
 }
 
 #[derive(Clap)]
-// #[clap(help_heading = "STACK TRACE VISUAL")]
+#[clap(help_heading = "STACK TRACE VISUAL")]
 pub struct TraceOpts {
 	/// Format of stack traces' display in console.
 	/// `compact` format only shows `filename:line:column`s