Skip to content

Commit

Permalink
Call this PR "Raid" cause it's squashin bugs! (#843)
Browse files Browse the repository at this point in the history
* tests: adds tests for default values triggering conditional requirements

* fix: fixes a bug where default values should have triggered a conditional requirement but didnt

Closes #831

* tests: adds tests for missing conditional requirements in usage string of errors

* fix: fixes a bug where conditionally required args werent appearing in errors

* tests: adds tests for completion generators

* tests: adds tests for completions with binaries names that have underscores

* fix: fixes a bug where ZSH completions would panic if the binary name had an underscore in it

Closes #581

* fix: fixes bash completions for commands that have an underscore in the name

Closes #581

* chore: fix the category for crates.io

* docs(Macros): adds a warning about changing values in Cargo.toml not triggering a rebuild automatically

Closes #838

* fix(Completions): fixes a bug where global args weren't included in the generated completion scripts

Closes #841

* fix: fixes a println->debugln typo

* chore: increase version
  • Loading branch information
kbknapp authored Feb 3, 2017
1 parent 07d985d commit 92919f5
Show file tree
Hide file tree
Showing 12 changed files with 971 additions and 217 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
<a name="v2.20.3"></a>
### v2.20.3 (2017-02-03)


#### Documentation

* **Macros:** adds a warning about changing values in Cargo.toml not triggering a rebuild automatically ([112aea3e](https://github.com/kbknapp/clap-rs/commit/112aea3e42ae9e0c0a2d33ebad89496dbdd95e5d), closes [#838](https://github.com/kbknapp/clap-rs/issues/838))

#### Bug Fixes

* fixes a println->debugln typo ([279aa62e](https://github.com/kbknapp/clap-rs/commit/279aa62eaf08f56ce090ba16b937bc763cbb45be))
* fixes bash completions for commands that have an underscore in the name ([7f5cfa72](https://github.com/kbknapp/clap-rs/commit/7f5cfa724f0ac4e098f5fe466c903febddb2d994), closes [#581](https://github.com/kbknapp/clap-rs/issues/581))
* fixes a bug where ZSH completions would panic if the binary name had an underscore in it ([891a2a00](https://github.com/kbknapp/clap-rs/commit/891a2a006f775e92c556dda48bb32fac9807c4fb), closes [#581](https://github.com/kbknapp/clap-rs/issues/581))
* allow final word to be wrapped in wrap_help ([564c5f0f](https://github.com/kbknapp/clap-rs/commit/564c5f0f1730f4a2c1cdd128664f1a981c31dcd4), closes [#828](https://github.com/kbknapp/clap-rs/issues/828))
* fixes a bug where global args weren't included in the generated completion scripts ([9a1e006e](https://github.com/kbknapp/clap-rs/commit/9a1e006eb75ad5a6057ebd119aa90f7e06c0ace8), closes [#841](https://github.com/kbknapp/clap-rs/issues/841))



<a name="v2.20.2"></a>
### v2.20.2 (2017-02-03)

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.20.2"
version = "2.20.3"
authors = ["Kevin K. <kbknapp@gmail.com>"]
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
repository = "https://github.com/kbknapp/clap-rs.git"
Expand All @@ -10,7 +10,7 @@ homepage = "https://clap.rs/"
readme = "README.md"
license = "MIT"
keywords = ["argument", "command", "arg", "parser", "parse"]
categories = ["command-line-interface"]
categories = ["command-line interface"]
description = """
A simple to use, efficient, and full featured Command Line Argument Parser
"""
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)

Here's the highlights for v2.20.2

* fixes a critical bug where subcommand settings were being propogated too far
* adds ArgGroup::multiple to the supported YAML fields for building ArgGroups from YAML
* fixes a println->debugln typo
* **Completions**: fixes bash completions for commands that have an underscore in the name
* **Completions**: fixes a bug where ZSH completions would panic if the binary name had an underscore in it
* allow final word to be wrapped in wrap_help
* **Completions**: fixes a bug where global args weren't included in the generated completion scripts
* **Macros Documentation:** adds a warning about changing values in Cargo.toml not triggering a rebuild automatically

Here's the highlights from v2.0.0 to v2.20.2

Here's the highlights from v2.0.0 to v2.20.1

* Fixes a critical bug where subcommand settings were being propogated too far
* Adds ArgGroup::multiple to the supported YAML fields for building ArgGroups from YAML
* Fixes a bug where the final word wasn't wrapped in help messages
* Fixes finding required arguments in group arguments
* **ArgsNegateSubcommands:** disables args being allowed between subcommands
Expand Down
2 changes: 1 addition & 1 deletion src/app/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ macro_rules! validate_multiples {
if $m.contains(&$a.b.name) && !$a.b.settings.is_set(ArgSettings::Multiple) {
// Not the first time, and we don't allow multiples
return Err(Error::unexpected_multiple_usage($a,
&*$_self.create_current_usage($m),
&*$_self.create_current_usage($m, None),
$_self.color()))
}
};
Expand Down
113 changes: 67 additions & 46 deletions src/app/parser.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/completions/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ complete -F _{name} -o bashdefault -o default {name}
for sc in &scs {
subcmds = format!("{}
{name})
cmd+=\"_{name}\"
cmd+=\"__{name}\"
;;",
subcmds,
name = sc.replace("-", "_"));
name = sc.replace("-", "__"));
}

subcmds
Expand Down Expand Up @@ -111,9 +111,9 @@ complete -F _{name} -o bashdefault -o default {name}
return 0
;;",
subcmd_dets,
subcmd = sc.replace("-", "_"),
subcmd = sc.replace("-", "__"),
sc_opts = self.all_options_for_path(&*sc),
level = sc.split("_").map(|_| 1).fold(0, |acc, n| acc + n),
level = sc.split("__").map(|_| 1).fold(0, |acc, n| acc + n),
opts_details = self.option_details_for_path(&*sc));
}

Expand All @@ -123,7 +123,7 @@ complete -F _{name} -o bashdefault -o default {name}
fn option_details_for_path(&self, path: &str) -> String {
debugln!("BashGen::option_details_for_path: path={}", path);
let mut p = self.p;
for sc in path.split('_').skip(1) {
for sc in path.split("__").skip(1) {
debugln!("BashGen::option_details_for_path:iter: sc={}", sc);
p = &p.subcommands
.iter()
Expand Down Expand Up @@ -212,7 +212,7 @@ complete -F _{name} -o bashdefault -o default {name}
fn all_options_for_path(&self, path: &str) -> String {
debugln!("BashGen::all_options_for_path: path={}", path);
let mut p = self.p;
for sc in path.split('_').skip(1) {
for sc in path.split("__").skip(1) {
debugln!("BashGen::all_options_for_path:iter: sc={}", sc);
p = &p.subcommands
.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/completions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn get_all_subcommand_paths(p: &Parser, first: bool) -> Vec<String> {
if !p.has_subcommands() {
if !first {
let name = &*p.meta.name;
let path = p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "_");
let path = p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "__");
let mut ret = vec![path.clone()];
if let Some(ref aliases) = p.meta.aliases {
for &(n, _) in aliases {
Expand All @@ -138,7 +138,7 @@ pub fn get_all_subcommand_paths(p: &Parser, first: bool) -> Vec<String> {
}
for sc in &p.subcommands {
let name = &*sc.p.meta.name;
let path = sc.p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "_");
let path = sc.p.meta.bin_name.as_ref().unwrap().clone().replace(" ", "__");
subcmds.push(path.clone());
if let Some(ref aliases) = sc.p.meta.aliases {
for &(n, _) in aliases {
Expand Down
12 changes: 6 additions & 6 deletions src/completions/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl<'a, 'b> ZshGen<'a, 'b> {
#compdef {name}
_{name}() {{
typeset -A opt_args
local ret=1
typeset -A opt_args
local ret=1
local context curcontext=\"$curcontext\" state line
local context curcontext=\"$curcontext\" state line
{initial_args}
{subcommands}
}}
Expand Down Expand Up @@ -86,7 +86,7 @@ _{bin_name_underscore}_commands() {{
)
_describe -t commands '{bin_name} commands' commands \"$@\"
}}",
bin_name_underscore = p.meta.bin_name.as_ref().unwrap().replace(" ", "_"),
bin_name_underscore = p.meta.bin_name.as_ref().unwrap().replace(" ", "__"),
bin_name = p.meta.bin_name.as_ref().unwrap(),
subcommands_and_args = subcommands_and_args_of(p))];

Expand All @@ -104,7 +104,7 @@ _{bin_name_underscore}_commands() {{
)
_describe -t commands '{bin_name} commands' commands \"$@\"
}}",
bin_name_underscore = bin_name.replace(" ", "_"),
bin_name_underscore = bin_name.replace(" ", "__"),
bin_name = bin_name,
subcommands_and_args = subcommands_and_args_of(parser_of(p, bin_name))));
}
Expand Down Expand Up @@ -265,7 +265,7 @@ fn get_args_of(p: &Parser) -> String {
let flags = write_flags_of(p);
let sc_or_a = if p.has_subcommands() || p.has_positionals() {
format!("\"1:: :_{name}_commands\" \\",
name = p.meta.bin_name.as_ref().unwrap().replace(" ", "_"))
name = p.meta.bin_name.as_ref().unwrap().replace(" ", "__"))
} else {
String::new()
};
Expand Down
7 changes: 7 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,13 @@ macro_rules! crate_name {
/// Provided separator is for the [`crate_authors!`](macro.crate_authors.html) macro,
/// refer to the documentation therefor.
///
/// **NOTE:** Changing the values in your `Cargo.toml` does not trigger a re-build automatically,
/// and therefore won't change the generated output until you recompile.
///
/// **Pro Tip:** In some cases you can "trick" the compiler into triggering a rebuild when your
/// `Cargo.toml` is changed by including this in your `src/main.rs` file
/// `include_str!("../Cargo.toml");`
///
/// # Examples
///
/// ```no_run
Expand Down
Loading

0 comments on commit 92919f5

Please sign in to comment.