git.delta.rocks / jrsonnet / refs/commits / 88be4ee7c720

difftreelog

feat help headings and colors

Yaroslav Bolyukin2020-10-19parent: #e99c281.patch.diff
in: master

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
before · cmds/jrsonnet/src/main.rs
1use clap::Clap;2use jrsonnet_cli::{ConfigureState, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};3use jrsonnet_evaluator::{error::LocError, EvaluationState};4use std::{5	fs::{create_dir_all, File},6	io::Write,7	path::PathBuf,8	rc::Rc,9};1011#[cfg(feature = "mimalloc")]12#[global_allocator]13static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;1415#[derive(Clap)]16// #[clap(help_heading = "DEBUG")]17struct DebugOpts {18	/// Required OS stack size.19	/// This shouldn't be changed unless jrsonnet is failing with stack overflow error.20	#[clap(long, name = "size")]21	pub os_stack: Option<usize>,22}2324#[derive(Clap)]25struct Opts {26	#[clap(flatten)]27	input: InputOpts,28	#[clap(flatten)]29	general: GeneralOpts,30	#[clap(flatten)]31	manifest: ManifestOpts,32	#[clap(flatten)]33	output: OutputOpts,34	#[clap(flatten)]35	debug: DebugOpts,36}3738fn main() {39	let opts: Opts = Opts::parse();40	if let Some(size) = opts.debug.os_stack {41		std::thread::Builder::new()42			.stack_size(size * 1024 * 1024)43			.spawn(|| main_catch(opts))44			.expect("new thread spawned")45			.join()46			.expect("thread finished successfully");47	} else {48		main_catch(opts)49	}50}5152#[derive(thiserror::Error, Debug)]53enum Error {54	// Handled differently55	#[error("evaluation error")]56	Evaluation(jrsonnet_evaluator::error::LocError),57	#[error("io error")]58	Io(#[from] std::io::Error),59}60impl From<LocError> for Error {61	fn from(e: LocError) -> Self {62		Self::Evaluation(e)63	}64}6566fn main_catch(opts: Opts) {67	let state = EvaluationState::default();68	if let Err(e) = main_real(&state, opts) {69		if let Error::Evaluation(e) = e {70			println!("{}", state.stringify_err(&e));71		} else {72			println!("{}", e);73		}74	}75}7677fn main_real(state: &EvaluationState, opts: Opts) -> Result<(), Error> {78	opts.general.configure(&state)?;79	opts.manifest.configure(&state)?;8081	let val = if opts.input.exec {82		state.evaluate_snippet_raw(83			Rc::new(PathBuf::from("args")),84			(&opts.input.input as &str).into(),85		)?86	} else {87		state.evaluate_file_raw(&PathBuf::from(opts.input.input))?88	};8990	let val = state.with_tla(val)?;9192	if let Some(multi) = opts.output.multi {93		if opts.output.create_output_dirs {94			let mut dir = multi.clone();95			dir.pop();96			create_dir_all(dir)?;97		}98		for (file, data) in state.manifest_multi(val)?.iter() {99			let mut path = multi.clone();100			path.push(&file as &str);101			if opts.output.create_output_dirs {102				let mut dir = path.clone();103				dir.pop();104				create_dir_all(dir)?;105			}106			println!("{}", path.to_str().expect("path"));107			let mut file = File::create(path)?;108			writeln!(file, "{}", data)?;109		}110	} else if let Some(path) = opts.output.output_file {111		if opts.output.create_output_dirs {112			let mut dir = path.clone();113			dir.pop();114			create_dir_all(dir)?;115		}116		let mut file = File::create(path)?;117		writeln!(file, "{}", state.manifest(val)?)?;118	} else {119		println!("{}", state.manifest(val)?);120	}121122	Ok(())123}
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
--- a/crates/jrsonnet-cli/src/ext.rs
+++ b/crates/jrsonnet-cli/src/ext.rs
@@ -54,7 +54,7 @@
 }
 
 #[derive(Clap)]
-// #[clap(help_heading = "EXTERNAL VARIABLES")]
+#[clap(help_heading = "EXTERNAL VARIABLES")]
 pub struct ExtVarOpts {
 	/// Add string external variable.
 	/// External variables are globally available so it is preferred
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