Commit graph

779 commits

Author SHA1 Message Date
Pavan Kumar Sunkara
9dd75987df Remove TakesValue restriction for HideEnv* 2021-08-15 19:40:24 +01:00
Pavan Kumar Sunkara
203613d5e3
Merge pull request #2696 from ldm0/override
Make `overrides_with` working when `MultipleValues` is enabled.
2021-08-14 10:41:40 +01:00
liudingming
a85857dfb0 Make overrides_with working when MultipleValues is enabled. 2021-08-14 16:34:26 +08:00
Pavan Kumar Sunkara
441ff68c2d
Merge pull request #2694 from clap-rs/env-feature
Add env feature gate
2021-08-14 03:11:21 +01:00
Pavan Kumar Sunkara
c7985fb73e Add env feature gate 2021-08-14 01:55:05 +01:00
Pavan Kumar Sunkara
61eb921f63 Fix value_names & num_vals interaction 2021-08-14 01:08:44 +01:00
liudingming
a60836d96a Make value_delimiter accept char rather than String 2021-08-14 02:54:56 +08:00
Pavan Kumar Sunkara
476dd190b7
Merge pull request #2682 from clap-rs/checker
Set TakesValue to true for positional args when building
2021-08-12 22:46:15 +01:00
Pavan Kumar Sunkara
b4a662b6c9 Set TakesValue to true for positional args when building 2021-08-12 21:27:42 +01:00
Steven Engler
1bd63feffe Hide help heading when all args are hidden 2021-08-12 00:51:58 +01:00
rami3l
5f781c72a5 feat(parser): accept non-false literals with env vars as true 2021-08-10 12:21:12 +02:00
rami3l
f2f9b665ed feat(parser): accept boolean literal with env vars, take 1 2021-08-10 12:21:02 +02:00
liudingming
e851a82080 Move pos_counter before parsing flags.
Then checking if AllowHyphenValues is set when parsing flag is possible.
2021-08-08 03:38:41 +08:00
rami3l
ac12c30352 fix(style): allow bool_assert_comparison in default_missing_value_flag_value 2021-08-02 23:10:51 +02:00
rami3l
d7c984896d fix(style): remove unnecessary usages of 'static and ref 2021-08-02 23:05:21 +02:00
Pavan Kumar Sunkara
4bec66dd03
Merge pull request #2619 from rami3l/flag-literal
fix(parser): Ban long flags with literals
2021-08-01 12:31:29 +01:00
rami3l
d848c88773 fix(test): fix typo in flag_using_long_with_literals 2021-08-01 12:19:00 +02:00
rami3l
2b3fc4d0b6 test: simplify flag_using_long_with_literals 2021-08-01 11:57:44 +02:00
liudingming
ab119b342a Fix value_of returns None when the first value group is empty 2021-08-01 03:56:23 +08:00
patrick-gu
88dec14775
Fix order of arguments in help message with AllowMissingPositional (#2648)
* Fix small formatting error

I accidentally introduced this in #2642

* Fix order of arguments in help message with AllowMissingPositional
2021-07-31 07:39:23 +01:00
rami3l
87479dfb8c fix: ban all uses of literals with flags 2021-07-30 22:33:56 +02:00
rami3l
2d2db652ef fix: fix #1649, take 1 2021-07-30 22:33:56 +02:00
liudingming
a419f25fdb Fix issue, add tests 2021-07-30 15:39:34 +08:00
patrick-gu
a4dc72ed19 Replace "Prints" with "Print" for default help and version commands 2021-07-29 20:23:25 -07:00
Pavan Kumar Sunkara
5fbd764b06
Merge pull request #2622 from patrick-gu/master
Refactor creation of `App` and `Arg` from YAML
2021-07-27 10:31:55 +01:00
patrick-gu
9b64ac2b45 Refactor creation of App and Arg from YAML
Improved the `impl`s of `From` for `&'help Yaml` to use expects with useful messages instead of unwraps. Also made changes to avoid potentially fetching redundant data from YAML hashes and unwrapping the same data multiple times. Finally, there are tests to ensure the panics are correct.
2021-07-25 15:24:43 -07:00
Pavan Kumar Sunkara
27311139c2
Merge pull request #2610 from ldm0/value_name
Print `value_name` `number_of_values` times with single value_name
2021-07-25 14:23:21 +01:00
liudingming
62fa1e7454 Print value_name number_of_values times with single value_name 2021-07-21 03:38:58 +08:00
liudingming
6094520541 Don't show default_val in smart usage 2021-07-21 02:50:41 +08:00
anatawa12
89d1519f69
Show summary in subcommands list (#2558)
* Show short about in SUBCOMMANDS list

* add tests

* move test

* cargo fmt
2021-06-20 16:28:50 +01:00
Ethan Budd
6a48698fcd
Add a new arg option for the max_occurrences (#2543)
* add a new arg option for the max_occurrences

* check ErrorKind in tests

* Updated grammer in doc comments

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>

* assert is_err() before unwraping

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-06-17 19:54:24 +01:00
Pavan Kumar Sunkara
947523f7f5
Merge pull request #2480 from kolloch/feature/partial-parsing
setting: IgnoreErrors - Allow parsing despite missing option values
2021-06-16 09:09:52 +01:00
Pavan Kumar Sunkara
e5e20b389e Forbid multiple_occurrences for positional args 2021-06-16 08:27:04 +01:00
Pavan Kumar Sunkara
3f94d17c71 Removed Arg::multiple 2021-06-16 07:17:11 +01:00
Peter Kolloch
171dcbe424 setting: IgnoreErrors - Reaction to review comments
https://github.com/clap-rs/clap/pull/2480
2021-06-14 10:26:23 +02:00
Peter Kolloch
c50d338962 setting: IgnoreErrors - Allow parsing despite missing option values
Implemented as AppSetting::Ignore errors as suggested by
@CreepySkeleton in
https://github.com/clap-rs/clap/issues/1880#issuecomment-637779787.

This is not a complete implementation but it works already in
surprisingly many situations.

https://github.com/clap-rs/clap/issues/1880
2021-06-14 10:26:18 +02:00
Terts Diepraam
834f600a6f infer long arguments 2021-06-05 13:18:06 +02:00
Pavan Kumar Sunkara
82e42cd07e Ignore extra fields in YAML only when specified 2021-06-01 21:59:44 +01:00
rami3l
fbd338ce26
fix: flag_subcommands unexpected behavior after long arg (#2501)
* fix(wip): add necessary debugging prints for analysis

* fix(wip): implement the fix, take 1

* docs: add docstring for `Parser::flag_subcmd_at` and `Parser::flag_subcmd_skip`

* test: make `flag_subcommand_short_after_long_arg` test more realistic
2021-05-27 05:14:50 +05:30
Pavan Kumar Sunkara
6a395d3208 ArgMacthes::is_present should not deal with subcommands at all, fixes #2494 2021-05-26 00:40:38 +01:00
Ajeet D'Souza
5809ae6060
feat: Add AppSettings::DisableEnv (#2493)
* Add DisableEnv flag

* Apply formatting

* Add tests
2021-05-21 00:47:47 +05:30
Ajeet D'Souza
460459c771
fix(usage): Move positional args to end of usage string (#2492)
* Move positional args to end of USAGE

* Remove -- from usage string
2021-05-21 00:29:21 +05:30
Pavan Kumar Sunkara
abe2373cca
Merge pull request #2026 from zkat/master
feat(derive): Add support from inheriting global options in subcommands
2021-05-20 13:52:24 +01:00
Felipe Sere
03d4989ef9 Replicate the derive test for from_global 2021-05-18 22:21:18 +01:00
Eldritch Cheese
fa991754d3 imp(validator): Case-insensitive required_if_eq when arg is case-insensitive 2021-05-15 09:45:24 -07:00
Donough Liu
2a921d4cda Fix clippy warnings. 2021-05-07 19:05:18 +00:00
liudingming
a995e5a204 Add yaml multiple_* tests 2021-05-07 14:34:03 +08:00
sharnoff
47aaca1e5d
change 'tests/macros.rs' to not import clap_app!
This should help to guard against future errors where `clap_app!` refers
to itself without the required "$crate::" prefix
2021-04-27 11:21:54 -07:00
Reagan McFarland
b184dc001b setting: SubcommandHelpShowsLongForm implemented
Refactoring and better test cases

Refactored SubcommandHelpShowsLongForm to
UseLongFormatForHelpSubcommand.
Tests and docuemntation examples use about and long_about instead of
(before/after)_help.

Removed commented out tests

Linting: Fix trailing new line

Updated change log, refactored tests and doc str

Reordered items in the Changelog
New test added and old tests removed that were redundant
Doc string for AppSettings::UseLongFormatForHelpSubcommand fixed
2021-04-11 14:31:40 -04:00
Pavan Kumar Sunkara
52814b893c
Merge pull request #2415 from cbzehner/ignore-extra-fields-on-arg
Ignore extra fields in Arg yaml definitions
2021-03-14 14:00:30 +05:30
Chris Zehner
407e629523 Ignore extra fields in Arg yaml definitions 2021-03-13 19:46:38 -06:00
Pavan Kumar Sunkara
f029047c03 Rename NoEmptyValues to ForbidEmptyValues 2021-03-13 12:05:34 +05:30
Pavan Kumar Sunkara
49954c28ad Remove unstable feature flag 2021-03-13 11:40:56 +05:30
ldm0
a1d4bd8488 Allow empty value by default, introduce NoEquals Error 2021-03-10 17:39:50 +00:00
Pavan Kumar Sunkara
30d784ffd1
Merge pull request #2400 from ldm0/unset-default
Support unsetting/removing the default if an option/flag is set
2021-03-10 18:13:52 +05:30
ldm0
448ff95fb0 ldm0's patch 2021-03-09 19:06:44 +00:00
Steven Engler
6626365359 feat(build/arg/mod.rs): default_vals_if supports an Option as the default 2021-03-09 18:15:20 +00:00
ldm0
2b0f0d3e1a Implement NoEquals error 2021-03-09 17:56:57 +00:00
ldm0
886b873709 Demangle interlinking flags 2021-03-09 13:45:11 +00:00
Omar El Halabi
701a4610b3 feat: Implement Arg::required_if_eq_all 2021-02-28 14:52:34 +02:00
Logan SQUIREL
52e74fa305
Fix App::version/long_version test 2021-02-27 16:31:32 +01:00
Logan SQUIREL
3c049b4e22
Fix compatibility with help2man output (see #1432)
Change default help template:
- The new template introduce new lines before and after
author/about sections.
- Add help template placeholders:
    - about-section
    - author-section
- Documentation of new placeholders in clap::App::help_template
- Update all unit tests by incorporating new lines
2021-02-27 16:20:52 +01:00
ldm0
3873b647d1 Add tests for 2229 2021-02-16 03:58:58 +00:00
ldm0
28b58af63b Change to num_vals, min_vals, max_vals interacts with Multi* 2021-02-16 03:45:20 +00:00
Pavan Kumar Sunkara
6634444c3c Remove Arg::settings to be consistent with App 2021-02-12 10:42:38 +00:00
Pavan Kumar Sunkara
2b5a23597a Better help message support for hidden and heading stuff 2021-02-08 05:22:27 +00:00
Pavan Kumar Sunkara
3758bba5e2 Remove help_about in favor of mut_arg 2021-02-07 17:22:56 +00:00
Pavan Kumar Sunkara
423e2dde00 Remove version_about in favor of mut_arg 2021-02-07 16:14:07 +00:00
Pavan Kumar Sunkara
1bd902370a Add tests for mut_arg on help and version 2021-02-07 15:54:24 +00:00
Pavan Kumar Sunkara
93a737a4fa
Merge pull request #2333 from clap-rs/build_help_and_version_at_start
Build help and version args at the beginning
2021-02-07 15:53:45 +00:00
Pavan Kumar Sunkara
c9cb22905c Build help and version args at the beginning 2021-02-07 14:46:38 +00:00
ldm0
560aa536df Change tests prefix 2021-02-07 05:59:29 +00:00
ldm0
fb3033834b Change the way parser do self override 2021-02-07 04:46:56 +00:00
Donough Liu
58b9f35771 Add tests, fix grouped_values_of()
Fix clippy

type complexity fix
2021-02-07 04:46:56 +00:00
ldm0
1000c9fb03 Fix eagerly trimming dash in parse_long_flag 2021-02-06 11:26:20 +00:00
Pavan Kumar Sunkara
8d5a021e1e
Merge pull request #2309 from ldm0/parser0
Dehack, Revert #1856
2021-01-30 14:52:02 +00:00
ldm0
5ee6e07858 Fix usage of positional grouped arguments uses arg name rather than val_name 2021-01-24 19:02:43 +00:00
Donough Liu
0df169bbdc Fix incorrect error message.
Comment out regressed logic

Fix clippy
2021-01-23 14:51:40 +00:00
Donough Liu
9477a5ffdb Correct tests, reveal real problem 2021-01-23 14:51:40 +00:00
Pavan Kumar Sunkara
d7f6748887
Merge pull request #2306 from ldm0/unset_setting
Fix unset_setting()
2021-01-23 13:37:57 +00:00
Bowen Ding
3907e11621
Make @group accept multiple attributes (#2248)
* Make @group accept multiple attributes.

* New syntax: remove parenthese and "=>".

* Fix example

* Make Clippy happy

* Make clippy happy again
2021-01-23 13:12:40 +00:00
ldm0
68a0ef930a Fix copied code 2021-01-23 06:41:11 +00:00
Pavan Kumar Sunkara
c156571f14
Merge pull request #2302 from AriusX7/visible-aliases
Allow visible alias(es) for args from YAML files
2021-01-20 18:07:06 +00:00
Donough Liu
d5e3c6b0b9 Add regression test for issue 2279 2021-01-21 01:09:20 +08:00
AriusX7
448c102f4f fix: allow visible alias(es) in yaml files 2021-01-20 02:17:17 +05:30
Donough Liu
fa9be84b18 Propagate global arg in subcommand to subsubcommand 2020-12-12 22:20:16 +08:00
Donough Liu
5f5474d803 Fix only one arg printed in multiple required_unless missing situation 2020-12-12 12:57:17 +08:00
Donough Liu
d7e2fd6294 Add regression test for issue 1794 2020-12-09 01:13:05 +08:00
Pavan Kumar Sunkara
b89163afb6 Update MSRV to 1.46 2020-11-28 11:58:28 +00:00
arthmis
a97e24630d chore: changing unrequired to non-required 2020-11-27 15:37:26 -05:00
arthmis
4e6a371851 chore: changing awkward grammar for positional argument error message 2020-11-27 15:12:28 -05:00
ldm0
347cd228a0 Add tests
Fix tests
2020-11-08 19:06:32 +00:00
Donough Liu
5e4b4f4196 Remove invalid suggestion on using subcommand after positional argument 2020-11-07 20:32:28 +08:00
Donough Liu
f17b29acbb Make Arg::env() and Arg::env_os() takes_value(false) by default 2020-11-06 21:51:39 +01:00
bors[bot]
97b4fb639f
Merge #2165
2165: Help & Version settings r=pksunkara a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-10-28 06:27:49 +00:00
Pavan Kumar Sunkara
5dd9584119 Improve the logic for help & version building & parsing 2020-10-26 12:13:03 +01:00
Donough Liu
a19bfa1c35 Consistently wrap help and subcommand messages(with refactoring) 2020-10-25 22:43:01 +01:00
Pavan Kumar Sunkara
e8a06e79cd Rename setting VersionlessSubcommands => DisableVersionForSubcommands 2020-10-24 16:04:49 +02:00
Pavan Kumar Sunkara
d6e2246aab Rename setting DisableVersion => DisableVersionFlag 2020-10-24 16:03:12 +02:00
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
Matt Kantor
bf34c04060 Add a test for --help with long argument help. 2020-08-11 15:30:30 -07:00
bors[bot]
da92a32d10
Merge #2048
2048: Change the ret tyte of Argmatches::subcommand r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-08-11 00:20:35 +00:00
Marti Raudsepp
64ee0f8009 Add hinting of arg value types for zsh/fish completion
Adds new method/attribute `Arg::value_hint`, taking a `ValueHint` enum
as argument. The hint can denote accepted values, for example: paths,
usernames, hostnames, commands, etc.

This initial implementation supports hints for the zsh and fish
completion generators, support for other shells can be added later.
2020-08-06 22:17:31 +03:00
CreepySkeleton
e9759a241b Adjust examples and tests 2020-08-05 17:07:13 +03:00
bors[bot]
dda961b715
Merge #2027
2027: style: rename ErrorKind::{VersionDisplayed, HelpDisplayed} to present tense r=CreepySkeleton a=siyopao



Co-authored-by: Craig Pastro <siyopao@gmail.com>
2020-07-26 07:36:52 +00:00
João Marcos
24760bc261 style: replacing yml with yaml for consistency 2020-07-20 20:58:34 -03:00
Craig Pastro
866f2edbed style: rename ErrorKind::{VersionDisplayed, HelpDisplayed} to present tense 2020-07-20 10:27:07 +09:00
Blaxar Waldarax
748aea39f3 feat: Added {before/after}_help_long to App struct, closed #1903 2020-07-19 13:59:53 +02:00
bors[bot]
1dd3fcb954
Merge #2019
2019: tests(validators): Add tests for `clap_app!` macro and `FromStr` trait validator r=pksunkara a=nickelc



Co-authored-by: Constantin Nickel <constantin.nickel@gmail.com>
2020-07-19 10:28:03 +00:00
Marti Raudsepp
594c535ba2 Fix various typos in docs & code
Most errors detected and fixed with Topy (https://github.com/intgr/topy),
all verified by hand.
2020-07-19 03:10:28 +03:00
Constantin Nickel
066d745653 tests(validators): Add tests for clap_app! macro and FromStr trait 2020-07-18 17:47:11 +02:00
bors[bot]
ff6beebd6e
Merge #1974
1974: Flag subcommands r=CreepySkeleton a=NickHackman



Co-authored-by: NickHackman <snickhackman@gmail.com>
Co-authored-by: Nick Hackman <31719071+NickHackman@users.noreply.github.com>
2020-07-18 14:06:50 +00:00
Constantin Nickel
fbfbf8df99 feat(macros): Add @global_setting $setting to set global settings 2020-07-13 15:13:04 +02:00
NickHackman
432be5bc30 tests: conflicts with flag sc and arg aliases
Tests to check for conflicts between flag subcommands long and short and
their aliases and args both long and short and their aliases. Tests to
handle self conflicts, where a flag subcommand short or long with have a
corresponding alias with the same value.
2020-07-11 15:00:40 -04:00
NickHackman
5118cec1b1 fix: long_flag_aliases instead of using alias
Previously long_flag alias checks were against normal aliases instead of
specifically designated long_flag aliases, this is more clear and explicit.
2020-07-10 09:27:14 -04:00
bors[bot]
d8fccdb0ea
Merge #1986
1986: Custom subcommand placeholders r=pksunkara a=kitlith



Co-authored-by: Kitlith <kitlith@kitl.pw>
2020-07-10 12:51:30 +00:00
Nick Hackman
27441329f9
Merge branch 'master' into flag-subcommands 2020-07-09 21:31:13 -04:00
NickHackman
1127ca6e13 feat: Usage displays short, long, and normal scs
Displayed in the form of

pacman {query, --query, -Q} [OPTIONS]
2020-07-08 21:37:56 -04:00
NickHackman
ec35ab8813 feat: long flag subcommand infer
Added tests and feature to infer long flag subcommands similarly to
normal subcommands.
2020-07-08 00:11:28 -04:00
Kitlith
96daa203b9 cargo fmt 2020-07-07 00:23:00 -07:00
Kitlith
5f601b7ecd Manually specify the header for subcommands.
Also fleshed out the documentation for subcommand_placeholder a bit.
2020-07-06 20:08:26 -07:00
CreepySkeleton
51d0b31105 Fix test 2020-07-06 17:26:53 +03:00
Kitlith
6eae5ed560 tests(subcommands): subcommand placeholder in help label 2020-06-27 20:19:57 -07:00
Kitlith
e5c66e58a6 Add test for custom subcommand placeholder text 2020-06-25 18:21:28 -07:00
NickHackman
d785ebc14e fix: Flag Subcommands tests behind debug_asserts
Tests that check conflicts are behind the `debug_assertions` feature
2020-06-17 01:53:53 -04:00
NickHackman
32db427706 fix: duplicate short flags in Flag Subcommand test 2020-06-17 01:14:48 -04:00
NickHackman
f7c5b098b9 fix: duplicate flags in Flag Subcommand test 2020-06-17 00:56:05 -04:00
NickHackman
bf3d947f01 fix: Flag Subcommands conflicts panic
Conflicts with Flag subcommands and Args now panics when
`debug_assertions` is enabled, rather than causing bizarre behavior.
2020-06-16 23:45:21 -04:00
NickHackman
383606e099 tests: short_flag_alias methods
Tests that cover all methods for `short_flag_alias` corresponding methods
2020-06-16 01:11:53 -04:00
NickHackman
458736bee8 imp: Improved Flag Subcommand API
Instead of a `FlagSubCommand` struct the addition of two simple methods
to `App`. `App::long_flag` and `App::short_flag` that cover all the
bases of the many methods that were provided in `FlagSubCommand`. This
API is far simpler to use and more akin to the present `Arg::long` and `Arg::short`.
2020-06-15 21:52:36 -04:00
NickHackman
c89718fa57 tests: FlagSubCommand
Test all methods of `FlagSubCommand` and interactions with aliases
2020-06-13 11:32:24 -04:00
Andreas Steding
49cb37b303 Updated tests. 2020-06-10 15:45:27 +02:00
Artem Vorotnikov
7a6310e26d
Update multiple_custom_help_headers test to cover #1955 2020-06-01 09:04:41 +03:00
CreepySkeleton
41c4d186f1 Fix warnings 2020-05-31 17:53:24 +03:00
Roy Ivy III
fbfe9eedf8 tests ~ add tests for new 'default_missing_value' configuration option 2020-05-21 13:06:45 -05:00
CreepySkeleton
5589276093 Rename App::set_term_width to term_width
None of the other methods that move self have the `set_` prefix
2020-05-18 12:46:14 +03:00
Patrick Marks
4a9e01b0bc ensure that validation failure error message includes a newline. also add a basic test of a failed validation 2020-05-17 08:50:35 -07:00
Patrick Marks
cb425946b7 fix test 2020-05-15 08:25:01 -07:00
Patrick Marks
97e3d8c0ac fix some cases of the 'The following required arguments were not provided' error message 2020-05-15 07:58:57 -07:00
Pavan Kumar Sunkara
7bc282dd4e Rename with_name to new for Arg & ArgGroup 2020-05-14 22:50:56 +02:00
Pavan Kumar Sunkara
51723e7678
Apply suggestions from code review 2020-05-12 15:34:05 +02:00
Pavan Kumar Sunkara
cfb0e95c9e Fix some stuff 2020-05-12 10:39:24 +02:00
Mark Thebridge
8fc099469d fix(parser): Better interaction between AllowExternalSubcommands and SubcommandRequired 2020-05-12 00:57:35 +02:00
Peter Corlett
719161ebba fix(macros): fixes broken pattern which prevented calling multi-argument Arg methods 2020-05-12 00:45:32 +02:00
Windfarer
2b2dbbc506 adding case_insensitive to yaml parsing 2020-05-12 00:36:47 +02:00
bors[bot]
33c63c6e29
Merge #1901
1901: implement Arg::short_alias and Arg::short_aliases r=pksunkara a=connorskees



Co-authored-by: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com>
2020-05-11 16:03:51 +00:00
ConnorSkees
59f3e9414b allow short aliases on Arg
this implements Arg::short_alias, Arg::short_aliases,
Arg::short_visible_alias, and Arg::short_visible_aliases in addition to
adding their associated tests
2020-05-11 11:21:01 -04:00
Jack O'Connor
952309c8d6 add tests for invalid UTF-16 on Windows
These are similar to the tests backported to the 2.x branch in
https://github.com/clap-rs/clap/pull/1907. These are more comprehensive,
because the OsStr splitting methods are more robust now.
2020-05-05 18:18:30 -04:00
CreepySkeleton
56fdfb9edd Eradicate warnings and errors: tests and examples 2020-05-02 23:33:47 +03:00
CreepySkeleton
ec6b6e1e36 Make validator take &str instead of String 2020-05-01 14:21:11 +03:00
creativcoder
d0abb378b0 cargo fmt 2020-04-27 20:41:41 +05:30
creativcoder
970c1fa21a Fix yaml tests 2020-04-27 20:19:26 +05:30
creativcoder
92d5920748 Updated test and usage of older help APIs with about 2020-04-27 02:42:07 +05:30
CreepySkeleton
cdb184b76c Add a test 2020-04-26 21:16:14 +03:00
CreepySkeleton
2403ae796e
Apply suggestions from code review
Co-Authored-By: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-04-24 23:06:13 +03:00
CreepySkeleton
f69ec92a83 Improve panics 2020-04-24 22:34:23 +03:00
CreepySkeleton
7a09195fcb Add a test 2020-04-24 13:05:46 +03:00
CreepySkeleton
61a12e4296 Fix positional args in groups (#1794) 2020-04-24 13:05:46 +03:00
bors[bot]
c1cb0ce359
Merge #1849
1849: Arg enum r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-04-22 17:23:43 +00:00
Pavan Kumar Sunkara
dbe6ac01f6 Clean up arg_enum 2020-04-22 14:38:16 +02:00
CreepySkeleton
0e7ff777da Make sure that command line OVERRIDES env, not prepends (fix #1835) 2020-04-22 11:35:20 +03:00
CreepySkeleton
bec16ae9e0 Add tests 2020-04-20 18:29:45 +03:00
Donnie Adams
0584b57f29 fix: Don't print 'OPTIONS' when all options are hidden for short help 2020-04-16 08:21:41 -07:00
Pavan Kumar Sunkara
070bd50b28 Finished color refactor 2020-04-16 12:51:26 +02:00
Pavan Kumar Sunkara
da32adeb0e Allow literals in builder macros 2020-04-12 23:18:39 +02:00
Ivan Tham
22ed69e857 Add test for suboptimal flag suggestion
Fix #1073
2020-04-12 23:44:48 +08:00
Pavan Kumar Sunkara
333b993481 Remove {n} support 2020-04-12 03:37:21 +02:00
CreepySkeleton
7cff206194 Make all fields of App & Arg pub(crate) 2020-04-11 18:23:20 +03:00
Bence Kalmar
4bf3f97d28 fix(arg_enum!): Invalid expansions of some trailing-comma patterns
In particular, fix macros that take an enum of one of the the following forms:

 - `#[...] enum { ... , }`
 - `pub enum { ... , }`
 - `enum { ... , }`

Previously, these expansions would result in an error message like "error: no
rules expected the token `:`".

Add extensive tests for each pattern.  Only two of the patterns had tests
before, so these errors did not surface automatically.
2020-04-10 09:35:20 +02:00
Ivan Veselov
0f3bdc439e Fix ArgMatcher consuming extra arguments when max_values is set 2020-04-10 09:35:20 +02:00
Pavan Kumar Sunkara
15edb69a0d Address review comments 2020-04-10 00:33:16 +02:00
Pavan Kumar Sunkara
f0a216036b Fix some issues 2020-04-09 19:41:33 +02:00
Pavan Kumar Sunkara
92449a4777 Assert arg groups 2020-04-09 16:51:32 +02:00
Pavan Kumar Sunkara
00a0b9660a Assert for require* on args 2020-04-09 16:51:32 +02:00
Pavan Kumar Sunkara
f632aedc72 Started on arg asserts 2020-04-09 16:51:32 +02:00
Pavan Kumar Sunkara
1c16f73c10 Start cleaning up debug_assertion validations 2020-04-09 16:51:32 +02:00
Patrick Marks
84214887b9 fix formatting 2020-04-02 06:48:01 -07:00
Patrick Marks
bbdbcbf8e1 add unit tests 2020-04-01 21:35:48 -07:00
CreepySkeleton
a46ab1639a Turn some integration tests into unit tests 2020-03-19 10:49:49 +03:00
Julian Laubstein
c34a0fdae9 Added tests and fixed display of conflicted flags 2020-03-08 17:11:12 +01:00
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