Commit graph

550 commits

Author SHA1 Message Date
bors[bot]
19c20f7c00
Merge #1727
1727: Fix `-- subcommand` error r=pksunkara a=ldm0



Co-authored-by: Donough Liu <ldm2993593805@163.com>
2020-03-05 13:01:05 +00:00
Donough Liu
5b9f6197b1 Test added, Apply rustfmt 2020-03-05 20:02:48 +08:00
CreepySkeleton
821b0792ea Fix test 2020-03-05 14:06:11 +03:00
CreepySkeleton
5d9ef1527f Fix warnings in tests & examples 2020-03-05 13:40:25 +03:00
bors[bot]
5e0898c175
Merge #1718
1718: Fix core dump with mutually `requires()` args r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-03-04 12:51:19 +00:00
CreepySkeleton
839ed2588c Fix core dump with mutually requires() args
Fixes #1643
2020-03-04 15:21:06 +03:00
Ivan Tham
908b7aeb44 Ambiguous suggetions for InferSubcommands
Closes #1655
2020-03-01 19:36:05 +08:00
bors[bot]
e4a7f50128
Merge #1669
1669: refactor: Rename Arg::conflicts_with_everything to Arg::exclusive (#1… r=pksunkara a=CreepySkeleton



Co-authored-by: Gregor Pfeifer <gpfeifer@dxc.com>
2020-02-22 21:58:29 +00:00
Pavan Kumar Sunkara
b8851a7d5e Allow replacing input on the fly 2020-02-21 18:15:33 +01:00
bors[bot]
1e7c9efc9d
Merge #1612
1612: Use about() with help() and long_about() with long_help() r=pksunkara a=TheLostLambda

I was going through the clap documentation and was under the impression that calling `help()` would call `about()` and `long_help()` would call `long_about()`, but I've actually discovered this not to be the case. Instead, the `long_about()` was always shown when it existed, rendering the output (in the about section) of programs called with `-h` and `--help` identical. Issue #1472 shows this and that is fixed here.

Note this doesn't remove the ability to use the same about in both cases: if `long_about()` is unset, then `about()` is used in both cases.

I've changed the implementation here to use `is_some()` and `unwrap()` as opposed to `if let` because it ultimately allows for less repetitive code. Ideally, I'd be able to pair `if let` with a secondary condition (namely `self.use_long`), but to my dismay, let-chains are not stabilized yet.

For a second opinion, here is the code a settled on:
```
if self.use_long && parser.meta.long_about.is_some() {
    debugln!("Help::write_default_help: writing long about");
    write_thing!(parser.meta.long_about.unwrap())
} else if parser.meta.about.is_some() {
    debugln!("Help::write_default_help: writing about");
    write_thing!(parser.meta.about.unwrap())
}
```
Here is the alternative:
```
if self.use_long {
    if let Some(about) = parser.meta.long_about {
        debugln!("Help::write_default_help: writing long about");
        write_thing!(about)
    } else if let Some(about) = parser.meta.about {
        debugln!("Help::write_default_help: writing about");
        write_thing!(about)
   }
} else {
    if let Some(about) = parser.meta.about {
        debugln!("Help::write_default_help: writing about");
        write_thing!(about)
    }
}
```

Co-authored-by: Brooks J Rady <b.j.rady@gmail.com>
2020-02-13 07:21:05 +00:00
Brooks J Rady
9cde072b61 Use about() with help() and long_about() with long_help() 2020-02-13 00:31:45 +00:00
bors[bot]
53f72be8d0
Merge #1686
1686: Use 'Clap Maintainers' as authors r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-02-10 22:20:27 +00:00
Pavan Kumar Sunkara
970d7140a3 Use 'Clap Maintainers' as authors 2020-02-10 20:16:25 +01:00
thomasfermi
aa97a4e8aa Added test for HelpRequired setting, which checks subcommands. Fixed bug that was discovered. 2020-02-10 14:33:26 +01:00
thomasfermi
2059bf1035 Implemented review findings for pull request #1683 2020-02-10 11:04:18 +01:00
Gregor Pfeifer
7781fd8813 refactor: Rename Arg::conflicts_with_everything to Arg::exclusive (#1583) (#1624)
https://github.com/clap-rs/clap/pull/1624#issuecomment-571372359
2020-02-04 18:02:47 +03:00
Pavan Kumar Sunkara
b7f76d8e8d Put the test helper in tests 2020-02-04 09:51:46 +01:00
rleungx
4082d1e85c exactly match a subcommand when using the infersubcommands 2020-02-04 09:41:05 +01:00
Alex van de Sandt
050bb7484a Fix formatting 2020-02-03 13:04:07 -05:00
Alex van de Sandt
1055bbe4aa Remove #[macro_use] from tests 2020-02-03 12:01:36 -05:00
Pavan Kumar Sunkara
506f5e4965 Added tests for cargo macros, fixes #1478 2020-02-02 08:50:40 +01:00
Pavan Kumar Sunkara
dd75cee72c fix: Clippy should pass 2020-02-01 06:48:50 +01:00
Pavan Kumar Sunkara
8e4a189ab0 fmt: Use standardized rustfmt rules 2020-01-31 18:37:56 +01:00
danieleades
af45420027 style: format code with rustfmt (#1632)
> incidentally, how do we feel about adding a rustfmt check to the CI(s)?
yes we should be doing that. you can send another pr that adds the check to the Ci
2020-01-11 23:45:46 +05:30
Gregor Pfeifer
6180d42c00 feat: Add Arg::conflicts_with_everything method #1583 (#1624)
* feat: Add `Arg::conflicts_with_everything` method #1583

* fix: Typo in  src/build/arg/mod.rs

Co-Authored-By: Dylan DPC <dylan.dpc@gmail.com>

Co-authored-by: Dylan DPC <dylan.dpc@gmail.com>
2020-01-06 00:16:28 +05:30
ncaq
fc359e3c46 fixed: failed of multiple_occurrences with env (#1609)
The example code.

~~~rust
use clap::{App, Arg};

fn main() {
  let matches = App::new("My Super Program")
    .arg(
      Arg::with_name("verbose")
        .help("Sets the level of verbosity")
        .short('v')
        .long("verbose")
        .takes_value(false)
        .multiple_occurrences(true)
        .env("VERBOSE"),
    )
    .get_matches();

  match matches.occurrences_of("verbose") {
    0 => println!("0 No verbose info"),
    1 => println!("1 Some verbose info"),
    2 => println!("2 Tons of verbose info"),
    3 | _ => println!("3 >= Don't be crazy"),
  }
}
~~~

It code use multiple_occurrences with env.
But it do not work.
`env` method set require take value.

It result see under.

~~~console
% cargo run -- -v
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/foo -v`
error: The argument '--verbose <verbose>...' requires a value but none was supplied

USAGE:
    foo [OPTIONS]

For more information try --help
~~~

And, structopt or clap_derive may be create similar code.
So I am confused by structopt.

This to fix code small.
2019-12-22 23:03:23 +05:30
Mara Bos
2a2969aee4 Don't write --version output directly to stdout. (#1602)
Fixes #1390.
2019-11-26 18:39:12 +01:00
shua
452b80d334 add subcommand expr macro 2019-10-30 00:22:05 -04:00
Thiago Arrais
c3b7c01f54
Provide default_values mimicking default_value 2019-10-29 21:48:10 -04:00
Oleksii Filonenko
1e39967044
Fix some clippy lints
- Manually fix some problems
- Run 'cargo fix --clippy'

Commits taken from similar PRs open at that time:

- Replace indexmap remove with swap_remove
  Resolves #1562 and closes #1563
- Use cognitive_complexity for clippy lint
  Resolves #1564 and closes #1565
- Replace deprecated trim_left_matches with trim_start_matches
  Closes #1539

Co-authored-by: Antoine Martin <antoine97.martin@gmail.com>
Co-authored-by: Brian Foley <bpfoley@users.noreply.github.com>
2019-10-29 21:46:25 -04:00
Dylan DPC
eb6276c772
Merge pull request #1514 from rharriso/pattern-arg-suggestion
Pattern arg suggestion
2019-07-04 15:33:53 +02:00
Dylan DPC
7ea767ad39
Merge pull request #1509 from jeremystucki/refactoring
Minor Refactoring
2019-07-02 09:28:41 +02:00
Ross Harrison
8d953cab08 feat(Errors): Add Pattern suggestion to Unknown Arg Error Message 2019-07-01 11:01:11 -05:00
Tyler Ruckinger
a5e3e62bef test in mkeymap does not need #[should_panic] 2019-06-25 19:51:12 -04:00
Tyler Ruckinger
83b0ab5064 Fixup tests 2019-06-25 19:02:53 -04:00
Jeremy Stucki
0f6ffe3612
Remove needless lifetimes 2019-06-21 09:06:58 +02:00
Erick Tryzelaar
cacc23473c Remove v2 depecated features.
This patch:

* Removes the `ArgSettings::Global` variant, and replaces all
  users of it to `Arg::global(...)`. The variant itself is lifted up
  into a field on Arg. This was deprecated in clap 2.32.0.
* Removes AppFlags::PropagateGlobalValuesDown. This was deprecated in
  clap 2.27.0.
* Removes `Arg::empty_values`. This was deprecated in clap 2.30.0.
* Removes `ArgMatches::usage`. This was deprecated in clap 2.32.0.
2019-06-19 17:04:29 -07:00
Erick Tryzelaar
4a20c6aaef Fix compiling with "--features yaml" 2019-06-19 16:32:52 -07:00
Erick Tryzelaar
2664703587 Fix most warnings
This patch:

* Removes unused `App::contains_long`
* Removes `std::ascii::AsciiExt` (deprecated in 1.26)
* Replaces `trim_left_matches` with `trim_start_matches` (added in 1.30)
* Adds `dyn` (added in 1.27)
* Removes unused `mkeymap::KeyType::{is_short,is_long}`
* Cleans up unused imports
2019-06-19 15:47:50 -07:00
Kevin K
fcbae1574a
style: rustfmt run 2019-04-05 20:21:33 -04:00
Kevin K
4cc85990fd
refactor: removed strings as an internal ID for arguments, groups, and
subcommands

This commit changes the internal ID to a u64 which will allow for
greater optimizations down the road. In addition, it lays the ground
work for allowing users to use things like enum variants as argument
keys instead of strings.

The only downside is each key needs to be hashed (the implementation
used is an FNV hasher for performance). However, the performance gains
in faster iteration, comparison, etc. should easily outweigh the single
hash of each argument.

Another benefit of if this commit is the removal of several lifetime
parameters, as it stands Arg and App now only have a single lifetime
parameter, and ArgMatches and ArgGroup have no lifetime parameter.
2019-04-05 20:21:22 -04:00
Kevin K
2a480451d3 refactor: clippy run 2018-11-14 14:01:48 -05:00
Kevin K
20c72525d2 style: cargo fmt run 2018-11-14 12:05:06 -05:00
Kevin K
0de9e07412
Merge branch 'v3-master' into map 2018-11-13 22:07:16 -05:00
Kevin K
3550066c88 refactor: cleans out deprecated code in prep for final beta.1 push 2018-11-08 20:34:13 -05:00
Kevin K
471376fdc7 imp: no longer automatically forces user to handle help just by overriding help arg 2018-10-20 22:27:31 -04:00
Kevin K
20126e1f62 refactor: fixes test failures from removing deprecations 2018-10-20 21:54:29 -04:00
Kevin K
a7e87d619c fix(env tests): fixes the env tests to allow multi-threaded test runs 2018-10-19 23:31:38 -04:00
Kevin K
03333800fe refactor: remove code going to other crates and deprecations 2018-10-19 23:31:06 -04:00
Kevin K
99bd101ea7
tests: fixes did_you_mean tests 2018-08-27 21:44:09 -04:00
Kevin K
69bdbd07f1
tests: fixes intermitent failures using env vars 2018-08-27 20:55:17 -04:00
Kevin K
400fafade2
tests: fixes help tests 2018-08-27 20:25:37 -04:00
Alena Yuryeva
a5346484e8 WIP 2018-08-19 17:46:59 +03:00
Alena Yuryeva
deb9fc91f6 Fixed opts & version tests 2018-08-11 21:11:11 +03:00
Kevin K
eaa0700e7e
style: rustfmt run 2018-08-01 23:13:51 -04:00
Kevin K
53a7d72523
chore: removes warnings and commented out code 2018-08-01 23:13:32 -04:00
Kevin K
49defad11b
fix: fixes help output tests 2018-08-01 22:09:09 -04:00
Kevin K
a2cd63cc9e
fix: fixes group tests on v3-master 2018-08-01 21:43:55 -04:00
Kevin K
5a06a8270a
fix(Requirements): fixing requirements and conflicts for issue 1158
Fixes requirements and conflicts on the v3 branch

Closes #1158
2018-07-31 23:32:11 -04:00
Kevin K
a9cbf3e5b9
depr(ArgMatches::usage): deprecates ArgMatches::usage in favor of App::generage_usage 2018-07-24 16:46:50 -04:00
Kevin K
94872e00a5
refactor(Arg): changes Arg::short to accept a char instead of &str
Closes #1303
2018-07-23 15:10:12 -04:00
Kevin K
3d3d4b1e9a feat(Completions): adds completion support for Elvish. 2018-06-26 21:15:48 -04:00
Alan K
eb68480b3b tests(yaml): Added future test for 2 space yaml 2018-06-22 13:50:44 +02:00
Kevin K
24d5fb3202 test: Added regression tests for Issue 897 2018-06-12 10:01:42 -04:00
Corentin Henry
4f602b7e86 replace Arg::from_usage by Arg::from 2018-04-21 11:59:19 -07:00
Alex Burka
c5d79d854e test validator with custom return type 2018-04-04 20:45:22 -04:00
Kevin K
8973f229b0
feat(Help): adds the ability for custom help sections
Args can now be added to custom help sections. This breaks up the builder pattern a little by adding help section declarations inline, but it's the most intuitive method and doesn't require strange nesting that feels awkward.

```rust
app::new("foo")
    .arg(Arg::with_name("arg1")) // under normal headers
    .help_heading("SPECIAL")
    .arg(Arg::with_name("arg2")) // under SPECIAL: heading
```

Closes #805
2018-04-03 23:32:59 -04:00
Christian Legnitto
36815fec59 imp(macros): Support shorthand syntax for ArgGroups
Fixes https://github.com/kbknapp/clap-rs/issues/1231.
2018-04-03 23:03:21 -04:00
Kevin K
41e29417b5 fix: fixes hiding args from short or long help in v3 context
Fixes the implementation of the hiding of arguments form the short or long help on v3
2018-04-03 23:01:45 -04:00
Kevin K
82e8a47f24 api(Arg): adds abilit to hide an arg from the short or long help message
Add logic to filter based on hidden long/short.

There is still an issue with the logic in parser.rs use_long_help. This
causes invalid evaluation of whether to show/hide based on long or short help
Complete check for use_long_help, add tests
2018-04-03 20:00:36 -04:00
Kevin K
8f1c0cfbbd
tests: fixes failing tests from new API additions 2018-03-21 19:41:58 -04:00
Aleksey Kladov
dfbae74e6d fix(Suggestions): disables suggestions when AllowExternalSubcommand is set 2018-03-21 00:01:23 -04:00
Kevin K
f65e2e4bf5
fix(Indices): fixes Indices to work on v3 2018-03-20 23:03:09 -04:00
Kevin K
89b74d5b31 fixup! tests: adds tests for querying indices 2018-03-20 22:25:58 -04:00
Kevin K
ed8bcc7632 tests: adds tests for querying indices 2018-03-20 22:25:10 -04:00
Kevin K
7b544e00d9 tests(AllowMissingPositional): adds tests for new 'skipping to last positional' with '--' 2018-03-20 20:57:14 -04:00
Kevin K
91e275c609
Use short help as tooltip in PowerShell completion
Also fixed some small issues with subcommand detection.
2018-03-19 17:12:10 -04:00
Kevin K
bd5143d1f8
fish: Fix completion of >1 options 2018-03-19 17:12:06 -04:00
Will Murphy
742aec292c Print ARGS after usage in help
For version 3, we want the args section to immediately follow
the usage section in the default help message.

One change that I am unhappy with is needing to make "write_arg"
in app/help.rs accept an extra param that makes it suppress the
extra line. This is to prevent an extra blank line from appearing
between args and options in the default help, and seems necessary,
but there might be a better way.
2018-03-11 20:33:13 -04:00
Will Murphy
3401e6a3ec clean up whitespace 2018-03-01 06:55:24 -05:00
Will Murphy
5ea7eab427 Port 1161 fix to v3
Copy the fix from https://github.com/kbknapp/clap-rs/pull/1162 into
the v3 parser, and add a test to protect against regressions in the
expected behavior of example 22.
2018-03-01 06:52:30 -05:00
Kevin K
cdfdbfffb5
tests(Bash Completions): updates the bash completions to the new file completion fallback 2018-02-13 15:42:48 -05:00
Kevin K
08dfdc877b
style: changes values->possible values in help messages as well as errors 2018-02-12 14:52:29 -05:00
etopiei
973022184e
Tests pass now 2018-02-12 14:39:55 -05:00
Kevin K
dc098e19a2
tests(AllArgsOverrideSelf): adds tests for AllArgsOverrideSelf 2018-02-10 15:43:39 -05:00
Kevin K
237c2bdff4
tests(Self Overrides): adds tests for args that override themselves 2018-02-09 23:35:14 -05:00
Kevin K
97fd3f1328
tests: partially updates tests to new arg.setting calls 2018-02-03 15:06:58 -05:00
Kevin K
4c54c2a696
tests: silence some warnings 2018-01-25 23:03:13 -05:00
Kevin K
1fa4afa45d
tests: continues to update tests to take advantage of new internals 2018-01-25 22:54:05 -05:00
Kevin K
90c0698aff
tests(Bash Completions): fixes the order of several completion commands 2018-01-25 22:36:20 -05:00
Kevin K
78090e5529
tests: removes some instances of println in the tests 2018-01-25 22:36:20 -05:00
Kevin K
712333be98
tests: splits tests into single duties 2018-01-25 15:08:57 -05:00
Kevin K
1ab10275e4
style: rustfmt run 2018-01-25 12:21:17 -05:00
Kevin K
efb3b28ae8
tests: updates the tests that were using clap internals 2018-01-25 12:20:56 -05:00
Will Murphy
c759d2027b clean up comments in tests; add error case test 2018-01-18 20:41:23 -05:00
Will Murphy
74976a0df9 Implement required_unless for flag
Flags were incorrectly reporting that they never had required_unless args.
2018-01-18 20:34:22 -05:00
Will Murphy
c6c9d9b33f Merge branch 'master' into issue-1135 2018-01-18 20:32:44 -05:00
Segev Finer
f3b0afd2be feat(completions/zsh.rs): Implement postional argument possible values completion 2018-01-16 01:52:44 +02:00
Segev Finer
a652260795 fix(completions/zsh.rs): Add missing autoload for is-at-least 2018-01-15 20:41:08 +02:00
Kevin K
e077e0c930
Merge branch 'master' into zsh-completion-improvements 2018-01-15 11:53:25 -05:00
Segev Finer
16b4f143ff fix(completions/zsh.rs): Don't pass -S to _arguments if Zsh is too old
If you do pass it than _arguments considers -C as a possible option in
the completions.
2018-01-14 07:13:27 +02:00
Segev Finer
1146f0da15 fix(completions/zsh.rs): Maybe fix completions with mixed positionals and subcommands
Optional positionals mixed with subcommands will still break this, since
I can't see how to tell which element of $line is the command than.
Mixing optional positionals with subcommands is a bit weird and awkward
though...
2018-01-14 07:13:23 +02:00
Segev Finer
e39aeab848 feat(completions/zsh.rs): Complete positional arguments properly
This changes the way we complete positionals to complete them using
_arguments, as should be done, instead of completing their uppercase name
as a string.

Currently I made it offer _files completion for all positional arguments.
This can be improved to complete actual possible values of the arguments
and only complete files if the argument truly takes them. But this will
require further changes in clap to actually have the required
functionality to get this information.
2018-01-14 07:12:14 +02:00
Segev Finer
0e185b922e fix(completions/zsh.zsh): Remove redundant code from output
Fixes #1142
2018-01-10 20:29:01 +02:00
William Murphy
1ab5c2d316
Merge branch 'master' into issue-1135 2018-01-10 06:28:58 -05:00
Kevin K
7ac5a5af9f tests: cleans up certain test cases litle by little 2018-01-09 10:53:20 -05:00
Kevin K
eac4ca7898
Merge branch 'master' into zsh-long-options-completion-fix 2018-01-09 10:50:40 -05:00
Segev Finer
46365cf8be fix(completions/zsh.rs): Fix completion of long option values
Long options take their argument either in the next word or after an
equals sign, but the Zsh completion specified that they take it either
in the same word with no separator or in the next word. See the
documentation of the Zsh _arguments function for more information.
2018-01-06 14:43:15 +02:00
Will Murphy
63cc4bc6a7 Test for Issue 1135
It looks like required_unless_one has incorrect behavior if the
argument it applies to also has a short form.
2017-12-26 11:16:18 -05:00
Alex Helfet
ba7f1d18eb fix(bash completion): Change the bash completion script code generation to support hyphens. 2017-12-16 12:44:57 +00:00
Alex Helfet
b446a561ce tests(auto-completion): Update build_app_special_commands to include a sub-command with a hypen.
The tests pass but the bash completion script won't work yet.
2017-12-16 12:44:44 +00:00
Alex Helfet
09d1d4a568 tests(auto-completion): Normalise names in tests/completions.rs
From            -> To
===========================================
with_underscore -> (with_)?special_commands
WUS             -> SPECIAL_CMDS
special         -> special_help
SPECIAL         -> SPECIAL_HELP
2017-12-16 12:44:12 +00:00
Eduardo Pinho
dde7fcf1ca Support trailing comma in arg_enum! fields 2017-12-07 00:53:55 +00:00
Kevin K
ebc35bdc91
tests: adds tests for both showing and hiding the values inside ENV vars 2017-12-02 15:09:22 -05:00
Kevin K
8c0cc5c386
style: rustfmt run 2017-11-28 08:57:04 -05:00
Kevin K
612ccaf14e
tests: adds tests for using possible_values with Arg::case_insensitive 2017-11-28 08:57:04 -05:00
Kevin K
80993357e1
api: Adds Arg::case_insensitive(bool) which allows matching Arg::possible_values without worrying about ASCII case
When used with `Arg::possible_values` it allows the argument value to pass validation even if
the case differs from that of the specified `possible_value`.

```rust
let m = App::new("pv")
    .arg(Arg::with_name("option")
        .long("--option")
        .takes_value(true)
        .possible_value("test123")
        .case_insensitive(true))
    .get_matches_from(vec![
        "pv", "--option", "TeSt123",
    ]);

assert!(m.value_of("option").unwrap().eq_ignore_ascii_case("test123"));
```

This setting also works when multiple values can be defined:

```rust
let m = App::new("pv")
    .arg(Arg::with_name("option")
        .short("-o")
        .long("--option")
        .takes_value(true)
        .possible_value("test123")
        .possible_value("test321")
        .multiple(true)
        .case_insensitive(true))
    .get_matches_from(vec![
        "pv", "--option", "TeSt123", "teST123", "tESt321"
    ]);

let matched_vals = m.values_of("option").unwrap().collect::<Vec<_>>();
assert_eq!(&*matched_vals, &["TeSt123", "teST123", "tESt321"]);
```

Closes #1118
2017-11-28 08:57:04 -05:00
Kevin K
89c0ed0328
tests: adds tests to guard against --help and -h being overridable 2017-11-22 04:11:28 -05:00
Kevin K
17a4d8a860 tests: adds tests to guard aginst issue 1105 and empty values in options 2017-11-13 17:05:28 -05:00
Kevin K
e78bb757a3 imp: adds '[SUBCOMMAND]' to usage strings with only AppSettings::AllowExternalSubcommands is used with no other subcommands
Closes #1093
2017-11-06 20:15:07 -05:00
Kevin K
fb08bb5dd5 refactor: removes unused imports on nightly via cfg directive
If one is using a nightly Rust compiler they should compile clap
with the `nightly` feature.

```toml
[dependencies]
clap = { version = "2.27", features = ["nightly"] }
```

This isn't required for compilation to succeed, only to take
advantage of any nightly features used by clap.

If one is compiling with `#[deny(warnings)]` this commit will cause
compilation to fail if one *does not* compile with the `nightly`
since `std::ascii::AsciiExt` is no longer required in in multiple
files as of the latest Rust nightly (Nov 6th, 2017).

Closes #1095
2017-11-06 20:11:19 -05:00
Kevin K
2558083fe9
tests: adds tests to guard against allowing invalid args accidentally 2017-10-24 15:21:52 -07:00
Kevin K
9435b2a589
tests: adds tests to make sure args are preferred over matching subcommands when values are possible 2017-10-24 14:59:31 -07:00
Kevin K
b399ee2604
tests: adds tests to ensure number_of_values and default_value can be used together 2017-10-24 12:57:04 -07:00
Kevin K
f7a6955238
tests: adds tests to make sure args with default values can have conflicts 2017-10-24 12:23:29 -07:00
Kevin K
2c3f7f6054
tests: adds tests to protect against panics when using globals and calling App::get_matches_from_safe_borrow multiple times 2017-10-24 10:46:00 -04:00
Kevin K
48e0529bcd
chore: clippy run 2017-10-23 23:03:40 -04:00
Kevin K
8fd59e0b7b
tests: updates tests new global values being propagated up and down 2017-10-23 22:14:16 -04:00
Kevin K
cbd09c7fec
tests: refactors the tests for propagating global values and flags as well as adds some tests for default values and flags 2017-10-23 21:27:29 -04:00
Kevin K
0d6cd6e7d9
chore: fixes some spelling mistakes 2017-10-23 21:26:45 -04:00
Kevin K
8a2e1dbdcd
wip: implement 1061 2017-10-21 15:55:31 -04:00
Will Murphy
15437bf3a7 use global setting in test 2017-10-18 07:42:17 -04:00
Will Murphy
3bedc69bff explanatory test comments 2017-10-18 07:42:17 -04:00
Will Murphy
1948de9c6b remove outdated comment 2017-10-18 07:42:17 -04:00
Will Murphy
a22e20191b rename inner sub command 2017-10-18 07:42:17 -04:00
Will Murphy
6c014f31b3 remove old copy paste test code 2017-10-18 07:42:17 -04:00
Will Murphy
af28b2ace2 clean up tests and make them ore thorough 2017-10-18 07:42:17 -04:00
Will Murphy
f4c3a21a8f Change tests to reduce duplication
This change lets us test multiple orderings of the global
argument and subcommand issue with less duplicated code.
2017-10-18 07:42:17 -04:00
Will Murphy
12a7310233 Replicate diesel's issue with failing nested subcommand 2017-10-18 07:42:17 -04:00
Will Murphy
6f3b454573 Add failing test for globals to subcommands
Issue 978 mentions that subcommands cannot see the value
of globals that get passed, even if ArgSettings::PropagateGlobalsDown
is true.

This change commits a failing test that reproduces this error.
2017-10-18 07:42:17 -04:00
Kevin K
3e645ae9fc
tests: adds tests for required delimiters appearing in the help and usage strings 2017-10-12 15:11:51 -07:00
Benjamin Fry
1401faa486 add validation tests 2017-10-05 11:36:50 -07:00
Benjamin Fry
5fccd1fef8 add additional tests 2017-10-05 10:47:53 -07:00
Benjamin Fry
ec46b55fb3 add documentation and examples 2017-10-05 10:47:53 -07:00
Benjamin Fry
bad5d19edb add env key for help msg 2017-10-05 10:47:53 -07:00
Benjamin Fry
f254807c73 WIP: add from_env option 2017-10-05 10:46:55 -07:00
Martin Geisler
e67a061bcf docs: add html_root_url attribute
This doc attribute is used by rustdoc when generating documentation
for other crates that depend on this crate. With the html_root_url,
rustdoc will be able to generate correct links into this crate.

See C-HTML-ROOT in the Rust API Guidelines for more information:
https://rust-lang-nursery.github.io/api-guidelines/documentation.html#crate-sets-html_root_url-attribute-c-html-root

A version-sync check was added to ensure that the URL is kept up to
date when the crate version changes.
2017-09-23 12:50:21 +02:00
Martin Geisler
e09c248fc1 tests: ensure README version numbers are in sync 2017-09-23 12:45:50 +02:00
Kevin K
8567f0a46e
tests: adds tests to guard against subcommand section of help message showing unnecessarily 2017-09-14 10:38:01 -07:00
Kevin K
e1319fa198
tests: adds tests to guard against options with default values and zero or more values 2017-09-14 10:37:45 -07:00
Kevin K
150a0433ce
tests: adds tests for using requires_equals and min_values together 2017-09-13 12:27:19 -07:00
Kevin K
0136e991c4
tests: adds tests for App::long_about 2017-09-13 11:41:49 -07:00
Kevin K
2094c28d15 Merge pull request #1039 from siiptuo/fix-completion-special-characters
Escape special characters in zsh and fish completions
2017-09-13 10:58:33 -07:00
Tuomas Siipola
87e019fc84
fix: escape special characters in zsh and fish completions 2017-09-12 18:27:29 +03:00
Fraser Hutchison
b3eadb0de5 fix: avoid panic generating default help msg if term width set to 0 due to bug in textwrap 0.7.0
upgrade textwrap to 0.8.0 and add regression test
2017-09-07 00:19:08 +01:00
William Bain
434ea5ba71 fix(Suggestions): output for flag after subcommand 2017-08-05 12:46:50 -04:00
Corentin Henry
e8518cf07d tests(Suggestions): update tests for subcommand suggestions 2017-06-12 08:03:39 -07:00
Martin Geisler
b93870c10a feat: use textwrap crate for wrapping help texts
The textwrap crate uses a simpler linear-time algorithm for wrapping
the text. The current algorithm in wrap_help uses several O(n) calls
to String::insert and String::remove, which makes it potentially
quadratic in complexity.

Comparing the 05_ripgrep benchmark at commits textwrap~2 and textwrap
gives this result on my machine:

 name              before ns/iter  after ns/iter  diff ns/iter   diff %
 build_app_long    22,101          21,099               -1,002   -4.53%
 build_app_short   22,138          21,205                 -933   -4.21%
 build_help_long   514,265         284,467            -229,798  -44.68%
 build_help_short  85,720          85,693                  -27   -0.03%
 parse_clean       23,471          22,859                 -612   -2.61%
 parse_complex     29,535          28,919                 -616   -2.09%
 parse_lots        422,815         414,577              -8,238   -1.95%

As part of this commit, the wrapping_newline_chars test was updated.
The old algorithm had a subtle bug where it would break lines too
early. That is, it wrapped the text like

    ARGS:
        <mode>    x, max, maximum   20 characters, contains
                  symbols.
                  l, long           Copy-friendly,
                  14 characters, contains symbols.
                  m, med, medium    Copy-friendly, 8
                  characters, contains symbols.";

when it should really have wrapped it like

    ARGS:
        <mode>    x, max, maximum   20 characters, contains
                  symbols.
                  l, long           Copy-friendly, 14
                  characters, contains symbols.
                  m, med, medium    Copy-friendly, 8
                  characters, contains symbols.";

Notice how the word "14" was incorrectly moved to the next line. There
is clearly room for the word on the line with the "l, long" option
since there is room for "contains" just above it.

I'm not sure why this is, but the algorithm in textwrap handles this
case correctly.
2017-05-29 17:02:57 -04:00
Martin Geisler
13653042c2 tests: add wrap_help test with significant whitepace
This adds a test for the issue #617 about keeping whitespace intact in
manually aligned text.
2017-05-29 17:02:57 -04:00
Kevin K
17c97ee8c5 tests: adds a test where a non-existing arg is added to a group to ensure a failed debug assertion 2017-05-16 07:23:22 -04:00
Kevin K
5209b61192 tests: adds tests for using double hyphen -- as a value 2017-05-16 07:23:22 -04:00
golem131
60cc838a42 Fix tests 2017-05-11 20:45:15 -04:00
Kevin K
54c16836de fix: fixes a bug where positional argument help text is misaligned 2017-05-10 20:29:54 -04:00
Kevin K
3223f21a90 tests: adds tests to last(true) args are printed in the usage even when required 2017-05-07 10:46:03 -04:00
Kevin K
3ed0f70c6e tests: adds tests to ensure positional values value name are used in usage strings instead of names when defined 2017-05-07 10:46:03 -04:00
Kevin K
fedb46b5b1 fix: fixes a bug where flags were parsed as flags AND positional values when specific combinations of settings were used
This commit fixes a bug where using `AppSettings::AllowHyphenValues`
would cause flags with longs be *also* parsed as positional values.

Closes #946
2017-05-07 10:46:03 -04:00
Kevin K
4048072021 tests: adds tests to ensure flags not incorrectly parsed as positionals 2017-05-07 10:46:03 -04:00
Nuew
d5ef895541
api(Arg): add default_value_os
Also add related tests, and reframe `default_value` in terms of
`defualt_value_os`.
2017-04-24 15:49:59 -04:00
Kevin K
6aa4ba8114 fix: fixes a missing newline character in the autogenerated help and version messages in some instances 2017-04-05 10:59:55 -04:00
Kevin K
c83a559df1 tests(clap_app!): adds tests for ("config-file") style positonal args 2017-04-05 00:57:40 -04:00
Kevin K
92cc30577d tests: adds tests to verify help and version can be properly overridden 2017-04-04 19:56:34 -04:00
Kevin K
0e4fd96d74 fix(Custom Usage Strings): fixes the usage string regression when using help templates 2017-03-30 13:30:23 -04:00
Kevin K
1a97f4fb95 tests: adds regression tests for custom usage strings 2017-03-24 11:27:23 -04:00
Richard Janis Goldschmidt
d49e8292b0
api(App::name): adds the ability to change the name of the App instance after creation
Closes #908
2017-03-22 20:27:20 -04:00
CrazyMerlyn
6b491c1161
tests(Help): adds tests for per argument hiding of default value 2017-03-22 20:27:20 -04:00
CrazyMerlyn
6bf5bf5bee
fix(yaml): adds support for loading author info from yaml
fix(yaml): adds support for loading author info from yaml
2017-03-22 20:23:55 -04:00
Pierre-Eric Pelloux-Prayer
f8f68cf825 imp: add fish subcommand help support 2017-03-17 17:46:24 +01:00
Kevin K
c84416f48d
tests: adds tests for reqire_equals(true) errors and help 2017-03-16 21:45:45 -04:00
Kevin K
ef037eaf22
tests: adds tests to check precedence of ArgRequiredElseHelp 2017-03-12 12:53:40 -04:00
Kevin K
b049cecccc
tests: adds tests for passing assertions with new Arg::last setting 2017-03-12 12:45:59 -04:00
Kevin K
3a10353f4b
tests: adds tests for .last(true) args 2017-03-11 12:14:54 -05:00
Kevin K
d2b4c2c61b
fix: fixes false positive clean parse when the suggestions feature is disabled and InferSubcommands is enabled 2017-03-10 08:24:30 -05:00
Kevin K
5c76350f77
tests: fixes failing hidden args test 2017-03-10 08:24:30 -05:00
Kevin K
642db9b042
tests: adds tests for new dual usage strings with certain subcommand settings 2017-03-10 08:24:29 -05:00
Kevin K
c8ab24bafa
imp: when AppSettings::SubcommandsNegateReqs and ArgsNegateSubcommands are used, a new more accurate double line usage string is shown
Closes #871
2017-03-10 08:24:29 -05:00
Kevin K
150756b989
setting(InferSubcommands): adds a setting to allow one to infer shortened subcommands or aliases (i.e. for subcommmand "test", "t", "te", or "tes" would be allowed assuming no other ambiguities)
Closes #863
2017-03-10 08:22:31 -05:00
Joost Yervante Damad
8adf353e0b
fix(help): don't show ARGS when there are only hidden positional args
Also no need to check for Hidden inside for that already is filtered
on !Hidden.

Closes #882
2017-03-10 08:22:31 -05:00
Caleb Jones
c5dac3fa43 Support loading help_message and version_message from the YAML 2017-03-10 01:54:50 -05:00
Caleb Jones
389c413b70 Allow customizing the --version and --help messages 2017-03-10 01:01:56 -05:00
Kevin K
677f323bce
tests: adds tests to ensure borrowed args don't break 2017-02-28 08:30:14 -05:00
Kevin K
0efa411963
perf: refactor to remove unneeded vectors and allocations and checks for significant performance increases
Building an `App` struct with a fair number of args/flags/switches, etc. (used ripgrep as test case)
went from taking ~21,000 ns to ~13,000ns.
2017-02-28 08:30:13 -05:00
Kevin K
a01812fed8
tests: adds tests for requiring the equals syntax in options 2017-02-20 20:24:28 -05:00
Kevin K
fb7057cc7a
refactor(Arg): removes duplicate and uses Base, Switched, and Valued internally now 2017-02-20 19:06:36 -05:00
Kevin K
92919f5f67 Call this PR "Raid" cause it's squashin bugs! (#843)
* 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
2017-02-03 17:43:49 -05:00
Martin Geisler
564c5f0f17 fix: allow final word to be wrapped in wrap_help
Before, inserting a newline did not move the prev_space index forward.
This meant that the next word was measured incorrectly since the
length was measured back to the word before the newly inserted
linebreak.

Fixes #828.
2017-01-30 18:33:48 +01:00
Martin Geisler
563a539a8e tests: show how final word is not always wrapped
This is #828.
2017-01-30 18:33:48 +01:00
Martin Geisler
aff4ba18da fix: include final character in line lenght
Before, wrapping the help text at, say, 80 characters really meant
that every line could be at most 79 characters wide.

Lines can now be up to and including avail_chars columns wide.

If needed, a desired margin or padding can be subtracted from the
avail_chars argument at a later point.
2017-01-30 18:33:48 +01:00
Martin Geisler
d6743bb70d Fix compilation warnings (#825)
* tests: remove unnecessary mut

When building the projec, I was told

    warning: variable does not need to be mutable, #[warn(unused_mut)]
    on by default
      --> tests/macros.rs:39:9
       |
    39 |     let mut app = clap_app!(("app name with spaces-and-hyphens") =>
       |         ^^^^^^^

* examples: remove unused variable

The inner Some value is not used in the match arm:

    warning: unused variable: `local_matches`,
    #[warn(unused_variables)] on by default
       --> examples/20_subcommands.rs:128:32
        |
    128 |                 ("local", Some(local_matches)) =>{
        |                                ^^^^^^^^^^^^^
2017-01-29 18:13:49 -08:00
Kevin K
e80fd4d671
tests: adds tests for AppSettings::AllowMissingPositional 2017-01-04 00:02:26 -05:00
Kevin K
2fc5acaff7
fixup! tests: adds tests for propogating values down 2017-01-02 23:10:46 -05:00
Kevin K
f967235a90
tests: massively rehauls tests for better debugging and vastly improved error messages/deduplication 2017-01-02 23:05:50 -05:00
Kevin K
c142fb544d
tests: adds tests for propogating values down 2017-01-02 23:05:50 -05:00
Kevin K
fc3800b830
tests: adds tests for wrapping meta help items 2017-01-02 16:44:40 -05:00
Kevin K
aa26a50d5c
tests: adds tests to guard against low index multiples with allow_hyphen_values failing 2017-01-02 14:34:25 -05:00
Kevin K
9d9683feb0
tests(Arg::value_terminator): adds tests for Arg::value_termintaor 2017-01-02 12:23:03 -05:00
Kevin K
12026f63d9
tests: adds tests for 2016-12-30 23:22:09 -05:00
Kevin K
25cbca4e41
tests: adds tests for 2016-12-30 22:40:28 -05:00
Kevin K
01caf84b87
tests(DisableHelpSubcommand): adds tests for AppSettings::DisableHelpSubcommand 2016-12-30 21:53:58 -05:00
Kevin K
327c514d7a
test(Options): adds a test against issue 665 2016-12-30 16:25:48 -05:00
Kevin K
3055e77ea7
tests(YAML): adds some of the new APIs to the YAML tests 2016-12-28 23:56:33 -05:00
Kevin K
60e1a3a02b
tests(Conditionally Required): adds tests for conditionally required args 2016-12-28 23:30:52 -05:00
Kevin K
eca609159a
test(Conditional Requirements): adds teste for conditional requirements 2016-12-28 23:21:40 -05:00
Kevin K
b03eff6df5
tests(Default Values If): adds tests for the new defualt_value_if[s] methods 2016-12-28 23:21:40 -05:00
Arnavion
f41ec962c2 feat(clap_app!): Support --("some-arg-name") syntax for defining long arg names
Used for arg names that aren't idents.

Ref #321
2016-12-12 22:42:11 -08:00
Arnavion
9895b671cf feat(clap_app!): Support ("some app name") syntax for defining app names
Used for setting names that aren't Rust idents.

Fixes #759
2016-12-12 22:42:11 -08:00
Arnavion
79bbf57815 tests(clap_app!): Added test for clap_app! macro. 2016-12-12 22:42:11 -08:00
Kevin K
56bd25ab38 Merge branch 'master' into issue-threedots 2016-12-01 23:54:22 -05:00
Daniel Luz
b1b16d56d8 imp(Completions): adds fallbacks to Bash completions
With these options, in case the completion function cannot provide
suggestions, Bash will perform its default completions, based on e.g.
files, directories, and variable names. This is particularly useful for
argument values.
2016-12-01 23:27:35 -02:00
Kevin K
29e362cc19
tests: adds tests against issue 760 help message alignment 2016-12-01 18:47:20 -05:00
Kevin K
d20331b6f7
fix(Required Unless): fixes a bug where having required_unless set doesn't work when conflicts are also set
Closes #753
2016-11-20 12:10:14 -05:00
Kevin K
cf9d6ce5cd
refactor: refactors the internals a bit
Flags, Opts, and Positionals now store their internals using compartmented Base, Valued, and
Switched structs to keep the code duplication down and make it easier to maintain.

Iniside the src/app/parser.rs there have been several changes to make reasoning about the code
easier. Primarily moving related sections out of the large get_matches_with into their own
functions.
2016-11-20 14:47:03 -05:00
Kevin K
908d78eb82
tests: adds tests against issue-725 part 2 2016-11-01 23:32:26 -04:00
Kevin K
74360184fa
tests(Multiple Values): renames some tests to reduce redundancy 2016-11-01 16:25:54 -04:00
Kevin K
ac49e7bc04
tests: adds tests for low index positionals with multiple(true) set 2016-11-01 16:25:54 -04:00
Kevin K
44f6b1edbf
tests: updates conflict tests to new more precise output 2016-10-31 00:35:13 -04:00
Wim Looman
f5b577c4fe tests: Add tests related to #706
Try and stress the combinations of DeriveDisplayOrder and UnifiedHelpMessage
along with propagating them to subcommands and explicitly setting a display
order.

The new tests

  derive_order_subcommand_propagate
  unified_help_and_derive_order_subcommand_propagate
  unified_help_and_derive_order_subcommand_propagate_with_explicit_display_order

are currently failing because of bug #706.
2016-10-26 20:47:19 +02:00
Kevin K
b94f897daf
tests(Help Message): adds tests to guard aginst multiple values throwing off alignment 2016-10-24 05:56:21 -04:00
Kevin K
e443f2d6c1
tests(AllowNegativeNumbers): adds some new tests for AllowNegativeNumbers and AllowLeadingHyphen 2016-10-21 09:42:25 -04:00
Kevin K
637d25dde3
tests: adds tests to guard against issue-688 2016-10-20 19:39:21 -04:00
Kevin K
440a21cfdc
tests: updates tests to new space counts in help messages 2016-10-20 19:39:21 -04:00
Kevin K
468baadb83
fix: fixes a bug that made determining when to auto-wrap long help messages inconsistent
Closes #688
2016-10-20 19:39:21 -04:00
tormol
996fc38176 docs: fix tests that fail when the "suggestions" feature is disabled 2016-10-16 11:31:12 +02:00
tormol
5778871951 style: remove the .ok() in result.ok().expect("...")
clippy doesn't check doc-tests and `include!()`d files,
so there might bee more un-reported lint.
2016-10-05 23:16:22 +02:00
tormol
215677bfa7 style: remove #[allow("warning that apparently doesn't exist")]
I say "apparently" because it's listed on https://manishearth.github.io/rust-clippy/master/
and not as deprecated.
2016-10-05 23:15:53 +02:00
Hideyuki Tanaka
8cd120c230 Fix the behavior of require_delimiter 2016-10-04 18:40:03 -04:00
nabijaczleweli
7b7aa87ddf
tests(correctness): No longer use App::get_matches() in some places
Use App::get_matches_from(vec![""]) instead not to fail when flags are
passed to the test binary

Closes #676
2016-10-04 23:22:43 +02:00
Salim Afiune
905d3b9777 Fix linting errors from rustc 1.14.0
The new version of rustc 1.14.0-nightly (144af3e97 2016-10-02) has new
linting warnings/errors. This commit fixes them.

Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
40d6dac973 feat(flag_aliases): Ability to alias flags
Added same alias funtionality for flags, now you can do:
```
Arg::with_name("flg")
    .long("flag")
    .short("f")
    .alias("not_visible_flag")
    .visible_alias("awesome_v_flag")
```

Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
e5d9760bea Added Arg::(visible_)alias(es) docs
Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
33b5f6ef2c feat(arg_aliases): Ability to alias arguments
There are some cases where you need to have an argument to have an
alias, an example could be when you depricate one option in favor of
another one.

Now you are going to be able to alias arguments as follows:
```
Arg::with_name("opt")
    .long("opt")
    .short("o")
    .takes_value(true)
    .alias("invisible")
    .visible_alias("visible")
```

Closes #669
2016-10-04 12:26:51 -04:00
Kevin K
d12649fd7b
tests: adds tests for value delimiters 2016-09-18 16:01:26 -04:00
Kevin K
5c29448d54
tests(AllowLeadingHyphen): adds test issue 588 AllowLeadingHyphen not recognizing valid args 2016-09-12 23:26:49 -04:00
Kevin K
1ea9bef20d
test(Help Wrapping): adds tests for the old newline characters 2016-09-12 23:20:40 -04:00
Kevin K
4c8ae08e4c
tests(Help): adds tests for per argument hiding of possible values 2016-09-10 23:11:43 -04:00
Kevin K
9881a4a23a tests(Value Delimiters): updates tests to new value delimiter rules 2016-09-10 18:18:43 -04:00
Kevin K
2e99e22630 Merge branch 'master' into issue-617 2016-09-07 10:45:27 -04:00
Kevin K
934094d7c5 tests: updates tests for new help wrapping rules 2016-09-07 08:42:42 -04:00
Aluísio Augusto Silva Gonçalves
b9b55a39df
imp(YAML): supports setting Arg::require_delimiter from YAML 2016-09-06 13:30:31 -03:00
Kevin K
60de29a7ef tests: updates test to new help improvements 2016-09-05 20:46:18 -04:00
Kevin K
3617a1d493 test: updates app_settings tests for new bug fixes 2016-09-05 17:16:40 -04:00