Commit graph

374 commits

Author SHA1 Message Date
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