Commit graph

463 commits

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