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.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,
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.rsdiffbeforeafterboth1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};4use std::{path::PathBuf, str::FromStr};56pub enum ManifestFormatName {7 /// Expect string as output, and write them directly8 String,9 Json,10 Yaml,11}1213impl FromStr for ManifestFormatName {14 type Err = &'static str;15 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {16 Ok(match s {17 "string" => ManifestFormatName::String,18 "json" => ManifestFormatName::Json,19 "yaml" => ManifestFormatName::Yaml,20 _ => return Err("no such format"),21 })22 }23}2425#[derive(Clap)]26// TODO: Restore arg group after issue fixed in clap27// #[clap(group = clap::ArgGroup::new("output_format"), help_heading = "MANIFESTIFICATION OUTPUT")]28pub struct ManifestOpts {29 /// Output format, wraps resulting value to corresponding std.manifest call.30 /// If set to `string` then plain string value is expected to be returned,31 /// otherwise output will be serialized to the specified format.32 #[clap(long, short = 'f', default_value = "json", possible_values = &["string", "json", "yaml"]/*, group = "output_format"*/)]33 format: ManifestFormatName,34 /// Expect plain string as output.35 /// Shortcut for `--format=string` thus this option is mutually exclusive with `format` option.36 #[clap(long, short = 'S'/*, group = "output_format"*/)]37 string: bool,38 /// Write output as YAML stream, can be used with --format json/yaml39 #[clap(long, short = 'y')]40 yaml_stream: bool,41 /// Number of spaces to pad output manifest with.42 /// `0` for hard tabs, `-1` for single line output/43 #[clap(long, default_value = "3")]44 line_padding: usize,45}46impl ConfigureState for ManifestOpts {47 fn configure(&self, state: &EvaluationState) -> Result<()> {48 if self.string {49 state.set_manifest_format(ManifestFormat::String);50 } else {51 match self.format {52 ManifestFormatName::String => state.set_manifest_format(ManifestFormat::String),53 ManifestFormatName::Json => {54 state.set_manifest_format(ManifestFormat::Json(self.line_padding))55 }56 ManifestFormatName::Yaml => {57 state.set_manifest_format(ManifestFormat::Yaml(self.line_padding))58 }59 }60 }61 if self.yaml_stream {62 state.set_manifest_format(ManifestFormat::YamlStream(Box::new(63 state.manifest_format(),64 )))65 }66 Ok(())67 }68}6970#[derive(Clap)]71pub struct OutputOpts {72 /// Write to the output file rather than stdout73 #[clap(long, short = 'o')]74 pub output_file: Option<PathBuf>,75 /// Automatically creates all parent directories for files76 #[clap(long, short = 'c')]77 pub create_output_dirs: bool,78 /// Write multiple files to the directory, list files on stdout79 #[clap(long, short = 'm')]80 pub multi: Option<PathBuf>,81}1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};4use std::{path::PathBuf, str::FromStr};56pub enum ManifestFormatName {7 /// Expect string as output, and write them directly8 String,9 Json,10 Yaml,11}1213impl FromStr for ManifestFormatName {14 type Err = &'static str;15 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {16 Ok(match s {17 "string" => ManifestFormatName::String,18 "json" => ManifestFormatName::Json,19 "yaml" => ManifestFormatName::Yaml,20 _ => return Err("no such format"),21 })22 }23}2425#[derive(Clap)]26#[clap(group = clap::ArgGroup::new("output_format"), help_heading = "MANIFESTIFICATION OUTPUT")]27pub struct ManifestOpts {28 /// Output format, wraps resulting value to corresponding std.manifest call.29 /// If set to `string` then plain string value is expected to be returned,30 /// otherwise output will be serialized to the specified format.31 #[clap(long, short = 'f', default_value = "json", possible_values = &["string", "json", "yaml"]/*, group = "output_format"*/)]32 format: ManifestFormatName,33 /// Expect plain string as output.34 /// Shortcut for `--format=string` thus this option is mutually exclusive with `format` option.35 #[clap(long, short = 'S', group = "output_format")]36 string: bool,37 /// Write output as YAML stream, can be used with --format json/yaml38 #[clap(long, short = 'y')]39 yaml_stream: bool,40 /// Number of spaces to pad output manifest with.41 /// `0` for hard tabs, `-1` for single line output/42 #[clap(long, default_value = "3")]43 line_padding: usize,44}45impl ConfigureState for ManifestOpts {46 fn configure(&self, state: &EvaluationState) -> Result<()> {47 if self.string {48 state.set_manifest_format(ManifestFormat::String);49 } else {50 match self.format {51 ManifestFormatName::String => state.set_manifest_format(ManifestFormat::String),52 ManifestFormatName::Json => {53 state.set_manifest_format(ManifestFormat::Json(self.line_padding))54 }55 ManifestFormatName::Yaml => {56 state.set_manifest_format(ManifestFormat::Yaml(self.line_padding))57 }58 }59 }60 if self.yaml_stream {61 state.set_manifest_format(ManifestFormat::YamlStream(Box::new(62 state.manifest_format(),63 )))64 }65 Ok(())66 }67}6869#[derive(Clap)]70pub struct OutputOpts {71 /// Write to the output file rather than stdout72 #[clap(long, short = 'o')]73 pub output_file: Option<PathBuf>,74 /// Automatically creates all parent directories for files75 #[clap(long, short = 'c')]76 pub create_output_dirs: bool,77 /// Write multiple files to the directory, list files on stdout78 #[clap(long, short = 'm')]79 pub multi: Option<PathBuf>,80}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