difftreelog
Merge pull request #18 from CertainLach/upgrade-clap
in: master
Help headings and colors
9 files changed
Cargo.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",
cmds/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"
cmds/jrsonnet/src/main.rsdiffbeforeafterboth1use clap::AppSettings;2use clap::Clap;3use jrsonnet_cli::{ConfigureState, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};4use jrsonnet_evaluator::{error::LocError, EvaluationState, ManifestFormat};5use std::{6 fs::{create_dir_all, File},7 io::Write,8 path::PathBuf,9 rc::Rc,10};1112#[cfg(feature = "mimalloc")]13#[global_allocator]14static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;1516#[derive(Clap)]17#[clap(help_heading = "DEBUG")]18struct DebugOpts {19 /// Required OS stack size.20 /// This shouldn't be changed unless jrsonnet is failing with stack overflow error.21 #[clap(long, name = "size")]22 pub os_stack: Option<usize>,23}2425#[derive(Clap)]26#[clap(27 global_setting = AppSettings::ColoredHelp,28 global_setting = AppSettings::DeriveDisplayOrder,29)]30struct Opts {31 #[clap(flatten)]32 input: InputOpts,33 #[clap(flatten)]34 general: GeneralOpts,35 #[clap(flatten)]36 manifest: ManifestOpts,37 #[clap(flatten)]38 output: OutputOpts,39 #[clap(flatten)]40 debug: DebugOpts,41}4243fn main() {44 let opts: Opts = Opts::parse();45 if let Some(size) = opts.debug.os_stack {46 std::thread::Builder::new()47 .stack_size(size * 1024 * 1024)48 .spawn(|| main_catch(opts))49 .expect("new thread spawned")50 .join()51 .expect("thread finished successfully");52 } else {53 main_catch(opts)54 }55}5657#[derive(thiserror::Error, Debug)]58enum Error {59 // Handled differently60 #[error("evaluation error")]61 Evaluation(jrsonnet_evaluator::error::LocError),62 #[error("io error")]63 Io(#[from] std::io::Error),64}65impl From<LocError> for Error {66 fn from(e: LocError) -> Self {67 Self::Evaluation(e)68 }69}7071fn main_catch(opts: Opts) {72 let state = EvaluationState::default();73 if let Err(e) = main_real(&state, opts) {74 if let Error::Evaluation(e) = e {75 println!("{}", state.stringify_err(&e));76 } else {77 println!("{}", e);78 }79 }80}8182fn main_real(state: &EvaluationState, opts: Opts) -> Result<(), Error> {83 opts.general.configure(&state)?;84 opts.manifest.configure(&state)?;8586 let val = if opts.input.exec {87 state.set_manifest_format(ManifestFormat::ToString);88 state.evaluate_snippet_raw(89 Rc::new(PathBuf::from("args")),90 (&opts.input.input as &str).into(),91 )?92 } else {93 state.evaluate_file_raw(&PathBuf::from(opts.input.input))?94 };9596 let val = state.with_tla(val)?;9798 if let Some(multi) = opts.output.multi {99 if opts.output.create_output_dirs {100 let mut dir = multi.clone();101 dir.pop();102 create_dir_all(dir)?;103 }104 for (file, data) in state.manifest_multi(val)?.iter() {105 let mut path = multi.clone();106 path.push(&file as &str);107 if opts.output.create_output_dirs {108 let mut dir = path.clone();109 dir.pop();110 create_dir_all(dir)?;111 }112 println!("{}", path.to_str().expect("path"));113 let mut file = File::create(path)?;114 writeln!(file, "{}", data)?;115 }116 } else if let Some(path) = opts.output.output_file {117 if opts.output.create_output_dirs {118 let mut dir = path.clone();119 dir.pop();120 create_dir_all(dir)?;121 }122 let mut file = File::create(path)?;123 writeln!(file, "{}", state.manifest(val)?)?;124 } else {125 println!("{}", state.manifest(val)?);126 }127128 Ok(())129}crates/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"
crates/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
crates/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.
crates/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')]
crates/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.
crates/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