Commit graph

480 commits

Author SHA1 Message Date
Pavan Kumar Sunkara
45f0ee8b55 Rename setting DisableHelpFlags => DisableHelpFlag 2020-10-24 16:03:12 +02:00
CastilloDel
88ac1f1803 Add assertions for required and default simultaneously
Add the suggested changes

Fix test issue_1050_num_vals_and_defaults

It used a required which isn't needed for the purpose of the test.

Add tests for the default+required assertions

Add test for positional args with long or short
2020-10-24 12:10:07 +01:00
Jacob Mischka
b3e638ad44
Add option to hide autogenerated env section from help text 2020-10-17 16:48:35 -05:00
David Hewitt
94f6889116 Don't use default value when option is passed 2020-10-14 20:00:40 +01:00
bors[bot]
5a1a209965
Merge #2161
2161: Fix parser skipping options without heading set r=pksunkara a=CertainLach



Co-authored-by: Yaroslav Bolyukin <iam@lach.pw>
2020-10-11 08:55:33 +00:00
Donough Liu
7f627fceee Change MissingArgumentOrSubcommand to DisplayHelpOnMissingArgumentOrSubcommand and don't use stderr 2020-10-11 15:42:47 +08:00
bors[bot]
4f90f3e4bb
Merge #2166
2166: Sort options base on option's short and long representation r=ldm0 a=ldm0



Co-authored-by: Donough Liu <ldm2993593805@163.com>
2020-10-10 18:54:49 +00:00
Donough Liu
15c77150a9 Sort options base on option's short and long representation 2020-10-11 02:08:10 +08:00
Marti Raudsepp
cda89a2af1 Fix typos and grammar
Some more fixes in addition to 594c535ba2
* Some I noticed manually.
* Some were found by Topy (https://github.com/intgr/topy), either new
  rules from Typo or new code in clap.
* `etc.` and `e.g.` rules were disabled during the last run.
2020-10-10 16:22:05 +03:00
Donough Liu
c9a407aa54 Fix: Don't mention unused subcommands (Partly cherry pick ef92e2b)
Add `\t` for consistency
2020-10-10 03:34:28 +08:00
bors[bot]
4ff4879400
Merge #2154
2154: Fix the error logic and error message for suggesting `--` before a flag r=pksunkara a=ldm0



Co-authored-by: Donough Liu <ldm2993593805@163.com>
2020-10-09 19:05:13 +00:00
Yaroslav Bolyukin
659d688543
test: add failing test for #2022
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
2020-10-09 23:45:07 +05:00
Donough Liu
9766aa11b1 Remove redundant(wrong) error processing
Argument prefixed by `-` will never inferred as a subcommand

Suggest using subcommand when supplied after `--`

Cargo fmt, adding test for wrongly using subcommand after `--`

Fix test

Fix clippy
2020-10-10 00:06:50 +08:00
Donough Liu
5815246fd9 Fix the error logic and error message for suggesting -- before a flag
Fix tests

Add test for issue #1284

Apply nitpicks
2020-10-10 00:04:22 +08:00
bors[bot]
91633741e9
Merge #2143
2143: api(App): Adds help_about method to App. r=pksunkara a=pretzelhammer



Co-authored-by: pretzelhammer <7769424+pretzelhammer@users.noreply.github.com>
2020-09-26 06:55:58 +00:00
pretzelhammer
523729d3fc api(App): Adds version_about method to App.
Version about text is now customizable and propagates to subcommands. Closes #1640.
2020-09-25 09:06:35 -04:00
Felix Van der Jeugt
d5c7c7d8bd
Fix clippy errors 2020-09-25 10:38:35 +02:00
pretzelhammer
33caf49793 api(App): Adds help_about method to App.
Help about text is now customizable and propagates to subcommands. Closes #2080.
2020-09-24 17:53:02 -04:00
Felix Van der Jeugt
a083953d3a
Suggest corrections with double quotes 2020-09-24 17:58:35 +02:00
Felix Van der Jeugt
74cfcb4412
Add test for escaped values in help messages 2020-09-23 10:45:14 +02:00
Pavan Kumar Sunkara
9e381f92a9 Rename required_unless_eq_* to required_unless_present_* 2020-08-29 11:48:35 +02:00
bors[bot]
e4b5407296
Merge #1976 #2073
1976: Refactor r=pksunkara a=CreepySkeleton



2073: Add new "regex" feature r=CreepySkeleton a=bkaestner



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
Co-authored-by: Benjamin Kästner <benjamin.kaestner@gmail.com>
2020-08-28 17:14:31 +00:00
CreepySkeleton
5020333037 Refactor coloring 2020-08-28 19:21:05 +03:00
Benjamin Kästner
8cb9a7d486 Add new "regex" feature
This commit introduces a new feature called `"regex"`. It adds a new
function `validator_regex` to `Arg` and was inspired by the discussion
in #1968. The name `validator_regex` was chosen instead of
`regex_validator` to make sure that the developer keeps in mind that
there may only be a single `Validator` on an `Arg`.

The feature can be used with YAML files, however there is no proper
pattern in `clap_app!` (yet).
2020-08-26 17:54:54 +02:00
bors[bot]
8c47449bb5
Merge #2109
2109: fix: detect if space should be added before spec_vals r=CreepySkeleton a=knidarkness



Co-authored-by: knidarkness <knidarkness@gmail.com>
Co-authored-by: Sergey Dubovyk <knidarkness@gmail.com>
2020-08-25 13:35:22 +00:00
knidarkness
530b179776 fix: detect if space should be added before spec_vals 2020-08-25 10:41:08 +03:00
Matt Kantor
44ee8284c5 Exclude tests/examples.rs while checking coverage. 2020-08-24 10:23:49 -07:00
Matt Kantor
882f553c6a Test that --help works for all examples. 2020-08-23 11:23:43 -07:00
Danil Kondratiev
5b07c8a780
fix spaces in long help tests 2020-08-20 17:28:40 +03:00
Matt Kantor
247d823314 Do not capture args meant for libtest from integration tests.
Using `App::get_matches` from the integration tests meant that any
CLI arguments passed to libtest would also be captured by clap, often
causing the tests to fail.

For example, running `cargo test --test help -- --nocapture` would
result in several failed tests, even though `cargo test --test help`
worked fine. This was very surprising/confusing.

This commit makes the tests no longer implicitly rely on the value of
`env::args_os()`, which means developers can now provide arguments to
libtest without failures.
2020-08-18 11:50:48 -07:00
bors[bot]
025ec3c28b
Merge #2078
2078: Unify naming cheme r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-08-17 20:35:05 +00:00
tomjw64
27771ceeb7 Show arguments in conflict message in reverse order of input 2020-08-16 03:47:19 -05:00
CreepySkeleton
ce3171ace5 Arg::required_unless_all => required_unless_eq_all 2020-08-15 20:38:57 +03:00
CreepySkeleton
b12102c832 Arg::required_unless -> required_unless_present 2020-08-15 20:38:56 +03:00
CreepySkeleton
233af6e7a1 Arg::required_if => required_if_eq 2020-08-15 20:38:55 +03:00
CreepySkeleton
8b85c4ecea Arg::required_ifs => required_if_eq_any 2020-08-15 20:38:12 +03:00
CreepySkeleton
6b6b6035ed Arg::required_unless_one => required_unless_eq_any 2020-08-15 20:38:11 +03:00
tomjw64
826db05319 Add test for three argument conflict output 2020-08-15 04:43:12 -05:00
tomjw64
4372aa0fa6 Enable assertions on conflict_output_with_required 2020-08-15 04:16:23 -05:00
tomjw64
b3e523912f Add new tests for usage including required args 2020-08-15 03:20:48 -05:00
tomjw64
fbb7a0f6e4 Re-enable conflict_output and conflict_output_rev 2020-08-15 03:16:47 -05:00
bors[bot]
26aa746c3a
Merge #2067
2067: Use a template to produce the default help message r=pksunkara a=mkantor



Co-authored-by: Matt Kantor <the.matt.kantor@gmail.com>
2020-08-14 23:42:38 +00:00
Matt Kantor
de6a5af1b2 Add a (failing) test for no args + after help. 2020-08-14 13:58:56 -07:00
Benjamin Kästner
15c441708b Fix YAML null value in fixture
The YAML null value is called `null` in YAML, not `Null`. yaml-rust
handles those values according to spec, so we should use the correct
capitalization.

See https://yaml.org/spec/1.2/spec.html#id2803362 for more
information.
2020-08-14 18:28:43 +02:00
Benjamin Kästner
8a2e9804d7 Provide tests for Arg::default_value_if
While reading the code for the yaml translation, I've noticed that
there is a bug in the macro `yaml_opt_str` as well as a wrong `null`
value in the test fixture.

These tests add the expected behaviour on the given fixture, e.g.

    prog
and
    prog <WRONG>
where `<WRONG>` is **not** `other` should yield `None` for
`"positional2"`, whereas

    prog other
should yield "something" and

    prog --flag ARBITRARY_VALUE
should yield "some". The first two tests

- default_value_if_not_triggered
- default_value_if_not_triggered_by_argument

fail, as the second positional arguments *gets set*, although its
conditions aren't fulfilled.
2020-08-14 18:28:12 +02:00
bors[bot]
2df656c98d
Merge #1998
1998: Relax some restrictions on validators r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-08-12 14:35:39 +00:00
CreepySkeleton
6169bb8e79 Fix buggy tests 2020-08-12 06:12:44 +03:00
CreepySkeleton
32414fbdff Fix and rearrange debug asserts 2020-08-12 06:12:42 +03:00
CreepySkeleton
619658e17a Add test 2020-08-12 02:39:59 +03:00
Matt Kantor
f7e2fbf150 Print an empty line after multi-line argument help.
Fixes #1642.
2020-08-11 15:30:30 -07:00