Skip to content

Commit

Permalink
Issues rollup (#637)
Browse files Browse the repository at this point in the history
* feat: adds App::with_defaults to automatically use crate_authors! and crate_version! macros

One can now use

```rust
let a = App::with_defaults("My Program");

// same as
let a2 = App::new("My Program")
	.version(crate_version!())
	.author(crate_authors!());
```

Closes #600

* imp(YAML Errors): vastly improves error messages when using YAML

When errors are made while developing, the panic error messages have
been improved instead of relying on the default panic message which is
extremely unhelpful.

Closes #574

* imp(Completions): uses standard conventions for bash completion files, namely '{bin}.bash-completion'

Closes #567

* imp(Help): automatically moves help text to the next line and wraps when term width is determined to be too small, or help text is too long

Now `clap` will check if it should automatically place long help
messages on the next line after the flag/option. This is determined by
checking to see if the space taken by flag/option plus spaces and values
doesn't leave enough room for the entirety of the help message, with the
single exception of of if the flag/option/spaces/values is less than 25%
of the width.

Closes #597

* tests: updates help tests to new forced new line rules

* fix(Groups): fixes some usage strings that contain both args in groups and ones that conflict with each other

Args that conflict *and* are in a group will now only display in the
group and not in the usage string itself.

Closes #616

* chore: updates dep graph

Closes #633

* chore: clippy run

* style: changes debug header to match other Rust projects

* chore: increase version
  • Loading branch information
kbknapp authored Aug 28, 2016
1 parent 13fe03b commit b7793a2
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 210 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
<a name="v2.11.0"></a>
### v2.11.0 (2016-08-28)


#### Bug Fixes

* **Groups:** fixes some usage strings that contain both args in groups and ones that conflict with each other ([3d782def](https://github.com/kbknapp/clap-rs/commit/3d782def57725e2de26ca5a5bc5cc2e40ddebefb), closes [#616](https://github.com/kbknapp/clap-rs/issues/616))

#### Documentation

* moves docs to docs.rs ([03209d5e](https://github.com/kbknapp/clap-rs/commit/03209d5e1300906f00bafec1869c2047a92e5071), closes [#634](https://github.com/kbknapp/clap-rs/issues/634))

#### Improvements

* **Completions:** uses standard conventions for bash completion files, namely '{bin}.bash-completion' ([27f5bbfb](https://github.com/kbknapp/clap-rs/commit/27f5bbfbcc9474c2f57c2b92b1feb898ae46ee70), closes [#567](https://github.com/kbknapp/clap-rs/issues/567))
* **Help:** automatically moves help text to the next line and wraps when term width is determined to be too small, or help text is too long ([150964c4](https://github.com/kbknapp/clap-rs/commit/150964c4e7124d54476c9d9b4b3f2406f0fd00e5), closes [#597](https://github.com/kbknapp/clap-rs/issues/597))
* **YAML Errors:** vastly improves error messages when using YAML ([f43b7c65](https://github.com/kbknapp/clap-rs/commit/f43b7c65941c53adc0616b8646a21dc255862eb2), closes [#574](https://github.com/kbknapp/clap-rs/issues/574))

#### Features

* adds App::with_defaults to automatically use crate_authors! and crate_version! macros ([5520bb01](https://github.com/kbknapp/clap-rs/commit/5520bb012c127dfd299fd55699443c744d8dcd5b), closes [#600](https://github.com/kbknapp/clap-rs/issues/600))



<a name="v2.10.4"></a>
### v2.10.4 (2016-08-25)

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "clap"
version = "2.10.4"
version = "2.11.0"
authors = ["Kevin K. <[email protected]>"]
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
repository = "https://github.com/kbknapp/clap-rs.git"
Expand All @@ -21,7 +21,7 @@ libc = { version = "~0.2.9", optional = true }
ansi_term = { version = "~0.8.0", optional = true }
strsim = { version = "~0.5.1", optional = true }
yaml-rust = { version = "~0.3.2", optional = true }
clippy = { version = "~0.0.79", optional = true }
clippy = { version = "~0.0.85", optional = true }
unicode-width = "~0.1.3"
unicode-segmentation = "~0.1.2"
term_size = { version = "~0.1.0", optional = true }
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)

## What's New

Here's the highlights for v2.11.0

* Adds the ability to wrap help text intelligently on Windows!
* Moves docs to [docs.rs!](https://docs.rs/clap/)
* Fixes some usage strings that contain both args in groups and ones that conflict with each other
* Uses standard conventions for bash completion files, namely `{bin}.bash-completion`
* Automatically moves help text to the next line and wraps when term width is determined to be too small, or help text is too long
* Vastly improves *development* error messages when using YAML
* Adds `App::with_defaults` to automatically use `crate_authors!` and `crate_version!` macros
* Other minor improvements and bug fixes

Here's the highlights for v2.10.4

* Fixes a bug where help is wrapped incorrectly and causing a panic with some non-English characters
Expand Down
74 changes: 30 additions & 44 deletions clap_dep_graph.dot
Original file line number Diff line number Diff line change
@@ -1,55 +1,41 @@
digraph dependencies {
N0[label="clap"];
N1[label="ansi_term",style=dashed];
N1[label="ansi_term"];
N2[label="bitflags"];
N3[label="clippy",color=blue,style=dashed];
N4[label="libc",style=dashed];
N5[label="strsim",style=dashed];
N6[label="unicode-width",style=dashed];
N7[label="vec_map"];
N8[label="yaml-rust",style=dashed,color=red];
N10[label="aho-corasick",color=blue,style=dashed];
N11[label="memchr",color=blue,style=dashed];
N12[label="regex",color=blue,style=dashed];
N13[label="quine-mc_cluskey",color=blue,style=dashed];
N14[label="regex-syntax",color=blue,style=dashed];
N15[label="semver",color=blue,style=dashed];
N16[label="toml",color=blue,style=dashed];
N17[label="unicode-normalization",color=blue,style=dashed];
N18[label="kernel32-sys",color=blue,style=dashed];
N19[label="winapi",color=blue,style=dashed];
N20[label="winapi-build",color=blue,style=dashed];
N21[label="nom",color=blue,style=dashed];
N22[label="thread_local",color=blue,style=dashed];
N23[label="utf8-ranges",color=blue,style=dashed];
N24[label="rustc-serialize",color=blue,style=dashed];
N25[label="thread-id"color=blue,style=dashed];
N3[label="clippy",color=blue];
N4[label="strsim"];
N5[label="term_size"];
N6[label="unicode-segmentation"];
N7[label="unicode-width"];
N8[label="vec_map"];
N9[label="yaml-rust",color=red];
N10[label="clippy_lints",color=blue];
N11[label="matches",color=blue];
N12[label="quine-mc_cluskey",color=blue];
N13[label="regex-syntax",color=red];
N14[label="rustc-serialize",color=blue];
N15[label="semver",color=blue];
N16[label="toml",color=blue];
N17[label="unicode-normalization",color=blue];
N0 -> N1[label="",style=dashed];
N0 -> N2[label=""];
N0 -> N3[label="",style=dashed,color=blue];
N0 -> N4[label="",style=dashed];
N0 -> N5[label="",style=dashed];
N0 -> N6[label="",style=dashed];
N0 -> N6[label=""];
N0 -> N7[label=""];
N0 -> N8[label="",style=dashed,color=red];
N0 -> N12[label="",style=dashed,color=blue];
N3 -> N13[label="",style=dashed,color=blue];
N3 -> N14[label="",style=dashed,color=blue];
N3 -> N15[label="",style=dashed,color=blue];
N3 -> N16[label="",style=dashed,color=blue];
N3 -> N17[label="",style=dashed,color=blue];
N0 -> N8[label=""];
N0 -> N9[label="",style=dashed,color=red];
N3 -> N10[label="",style=dashed,color=blue];
N5 -> N3[label="",style=dashed,color=blue];
N9 -> N3[label="",style=dashed,color=blue];
N9 -> N13[label="",style=dashed,color=red];
N10 -> N11[label="",style=dashed,color=blue];
N11 -> N4[label="",style=dashed,color=blue];
N12 -> N10[label="",style=dashed,color=blue];
N12 -> N11[label="",style=dashed,color=blue];
N12 -> N14[label="",style=dashed,color=blue];
N12 -> N22[label="",style=dashed,color=blue];
N12 -> N23[label="",style=dashed,color=blue];
N15 -> N21[label="",style=dashed,color=blue];
N16 -> N24[label="",style=dashed,color=blue];
N18 -> N19[label="",style=dashed,color=blue];
N18 -> N20[label="",style=dashed,color=blue];
N22 -> N25[label="",style=dashed,color=blue];
N25 -> N4[label="",style=dashed,color=blue];
N25 -> N18[label="",style=dashed,color=blue];
N10 -> N12[label="",style=dashed,color=blue];
N10 -> N13[label="",style=dashed,color=blue];
N10 -> N14[label="",style=dashed,color=blue];
N10 -> N15[label="",style=dashed,color=blue];
N10 -> N16[label="",style=dashed,color=blue];
N10 -> N17[label="",style=dashed,color=blue];
N16 -> N14[label="",style=dashed,color=blue];
}
Binary file modified clap_dep_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/17_yaml.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yml_app
version: 1.0
version: "1.0"
about: an example using a .yml file to build a CLI
author: Kevin K. <[email protected]>

Expand Down Expand Up @@ -69,7 +69,7 @@ subcommands:
# Rust code later
- subcmd:
about: demos subcommands from yaml
version: 0.1
version: "0.1"
author: Kevin K. <[email protected]>
# Subcommand args are exactly like App args
args:
Expand Down
36 changes: 28 additions & 8 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,16 @@ impl<'a> Help<'a> {
} else {
try!(color!(self, "{}", arg, good));
}

let spec_vals = self.spec_vals(arg);
let h = arg.help().unwrap_or("");
let nlh = self.next_line_help || arg.is_set(ArgSettings::NextLineHelp);
let width = self.term_w;
let taken = (longest + 12) + str_width(&*spec_vals);
let force_next_line = !nlh && width >= taken && str_width(h) > (width - taken) && (taken as f32 / width as f32) > 0.25;

if arg.has_switch() {
if !(self.next_line_help || arg.is_set(ArgSettings::NextLineHelp)) {
if !(nlh || force_next_line) {
let self_len = arg.to_string().len();
// subtract ourself
let mut spcs = longest - self_len;
Expand All @@ -356,7 +364,7 @@ impl<'a> Help<'a> {

write_nspaces!(self.writer, spcs);
}
} else if !(self.next_line_help || arg.is_set(ArgSettings::NextLineHelp)) {
} else if !(nlh || force_next_line) {
write_nspaces!(self.writer, longest + 4 - (arg.to_string().len()));
}
Ok(())
Expand Down Expand Up @@ -416,19 +424,30 @@ impl<'a> Help<'a> {
let spec_vals = self.spec_vals(arg);
let mut help = String::new();
let h = arg.help().unwrap_or("");
let spcs = if self.next_line_help || arg.is_set(ArgSettings::NextLineHelp) {
let nlh = self.next_line_help || arg.is_set(ArgSettings::NextLineHelp);
debugln!("Next Line...{:?}", nlh);

// determine if our help fits or needs to wrap
let width = self.term_w;
debugln!("Term width...{}", width);

// We calculate with longest+12 since if it's already NLH we don't care
let taken = (longest + 12) + str_width(&*spec_vals);
let force_next_line = !nlh && width >= taken && str_width(h) > (width - taken) && (taken as f32 / width as f32) > 0.25;
debugln!("Force Next Line...{:?}", force_next_line);
debugln!("Force Next Line math (help_len > (width - flags/opts/spcs))...{} > ({} - {})", str_width(h), width, taken);

let spcs = if nlh || force_next_line {
8 // "tab" + "tab"
} else {
longest + 12
};
// determine if our help fits or needs to wrap
let width = self.term_w;
debugln!("Term width...{}", width);

let too_long = spcs + str_width(h) + str_width(&*spec_vals) >= width;
debugln!("Spaces: {}", spcs);

// Is help on next line, if so newline + 2x tab
if self.next_line_help || arg.is_set(ArgSettings::NextLineHelp) {
if nlh || force_next_line {
try!(write!(self.writer, "\n{}{}", TAB, TAB));
}

Expand Down Expand Up @@ -470,7 +489,7 @@ impl<'a> Help<'a> {
}
for part in help.split("{n}").skip(1) {
try!(write!(self.writer, "\n"));
if self.next_line_help || arg.is_set(ArgSettings::NextLineHelp) {
if nlh || force_next_line {
try!(write!(self.writer, "{}{}", TAB, TAB));
} else if arg.has_switch() {
write_nspaces!(self.writer, longest + 12);
Expand Down Expand Up @@ -916,6 +935,7 @@ impl<'a> Help<'a> {
}
}

#[cfg_attr(feature = "lints", allow(explicit_counter_loop))]
fn wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) {
debugln!("fn=wrap_help;longest_w={},avail_chars={}", longest_w, avail_chars);
debug!("Enough space to wrap...");
Expand Down
Loading

0 comments on commit b7793a2

Please sign in to comment.