Commit graph

1535 commits

Author SHA1 Message Date
bors[bot]
93dd22c2f9
Merge #1890
1890: fix(build/app): don't use long help for `print_help() r=kbknapp a=cole-h



Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
2020-05-01 15:57:11 +00:00
Cole Helbling
2bc057eaa5
fix(build/app): don't use long help for print_help()
For long help, there's still `print_long_help()`.
2020-05-01 08:01:26 -07:00
CreepySkeleton
6bdb6d9b2e Marry AllowExternalSubcommands with SubcommandRequiredElse* 2020-05-01 15:33:36 +03:00
CreepySkeleton
ec6b6e1e36 Make validator take &str instead of String 2020-05-01 14:21:11 +03:00
CreepySkeleton
ee463ba834 Make extrernal_subcommand ALMOST work 2020-04-30 20:20:21 +03:00
CreepySkeleton
7a7148d087 Make struct SubCommand private 2020-04-29 21:34:59 +03:00
bors[bot]
5b9dbee5db
Merge #1876
1876: Allow usage of deprecated arg::help in yaml r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-04-28 11:39:05 +00:00
Pavan Kumar Sunkara
20d6b01818 Allow usage of deprecated arg::help in yaml 2020-04-28 12:37:52 +02:00
Pavan Kumar Sunkara
348744ab04 Rename some internal stuff 2020-04-28 11:13:09 +02:00
CreepySkeleton
4812cf2101 Make sure output is always flushed before exiting 2020-04-27 21:47:33 +03:00
CreepySkeleton
c6fdd3a7ce Reshape imports 2020-04-27 21:47:08 +03:00
creativcoder
d0abb378b0 cargo fmt 2020-04-27 20:41:41 +05:30
creativcoder
35fdb45adb Update bench tests with about and add inline to about methods 2020-04-27 20:00:36 +05:30
creativcoder
266dbbe3f4 Code review p2 2020-04-27 19:37:17 +05:30
creativcoder
92d5920748 Updated test and usage of older help APIs with about 2020-04-27 02:42:07 +05:30
creativcoder
75f5a9ab62 Code review p1 2020-04-27 02:42:07 +05:30
creativcoder
24cb8b13c5 Deprecate Arg::help in favour of Arg::about 2020-04-27 02:42:07 +05:30
CreepySkeleton
312432a5db Fix a bug we didn't know about 2020-04-26 21:16:14 +03:00
CreepySkeleton
c9e03e7e67 Default values trigger conflicts no more (#1605) 2020-04-26 21:16:09 +03:00
CreepySkeleton
02fac2315f Add hide_default_values to yaml 2020-04-26 13:47:53 +03:00
CreepySkeleton
3e865e565f A little cleanup 2020-04-25 15:57:12 +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
756e95388f Remove _StrExt 2020-04-24 22:47:55 +03:00
CreepySkeleton
f69ec92a83 Improve panics 2020-04-24 22:34:23 +03:00
CreepySkeleton
1bbcfe2261 Do not print hash in debug builds 2020-04-24 19:19:36 +03:00
CreepySkeleton
739e7048a5 Make vec_map required dependency - in fact, it already is 2020-04-24 15:33:11 +03:00
CreepySkeleton
61a12e4296 Fix positional args in groups (#1794) 2020-04-24 13:05:46 +03:00
CreepySkeleton
2e959d6c71 Update tests 2020-04-24 11:15:55 +03:00
dylni
d12827076f Give ArgStr module a better name 2020-04-23 09:03:21 -04:00
dylni
e7b19aea58 Fix beta errors 2020-04-23 09:03:21 -04:00
dylni
9ef18519b1 Fix index calculation 2020-04-23 09:03:21 -04:00
dylni
c2246cf03f imp(src/util/osstringext.rs): Remove the last unsafe block 2020-04-23 09:02:10 -04:00
bors[bot]
0293fd7c4a
Merge #1851
1851: Allow debug logs to work with clap tests themselves r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-04-22 20:01:24 +00:00
Pavan Kumar Sunkara
f0074752b9 Improve debug logs 2020-04-22 20:56:35 +02: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
Pavan Kumar Sunkara
01c179f527 Added arg_enum support 2020-04-22 14:37:45 +02:00
bors[bot]
3de8af46a2
Merge #1850
1850: Bugfixes r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-04-22 08:59:39 +00:00
CreepySkeleton
0e7ff777da Make sure that command line OVERRIDES env, not prepends (fix #1835) 2020-04-22 11:35:20 +03:00
CreepySkeleton
dd1505fdfd The self convention is not wrong here 2020-04-22 11:05:31 +03:00
Pavan Kumar Sunkara
4911c35869
Merge pull request #1834 from davidMcneil/arg_value_precedence_over_subcommand
Add ArgPrecedenceOverSubcommand app setting
2020-04-21 19:05:30 +02:00
David McNeil
746d9a4707 Fix SubcommandPrecedenceOverArg example indention
Signed-off-by: David McNeil <mcneil.david2@gmail.com>
2020-04-21 09:02:09 -05:00
David McNeil
709f20d713 Improve SubcommandPrecedenceOverArg description
Signed-off-by: David McNeil <mcneil.david2@gmail.com>
2020-04-21 08:31:49 -05:00
CreepySkeleton
66f85d07a0 Some extra debugging 2020-04-21 14:17:18 +03:00
David McNeil
ada5df3229 Use AppSettings::SubcommandPrecedenceOverArg
Signed-off-by: David McNeil <mcneil.david2@gmail.com>
2020-04-20 15:57:06 -05:00
bors[bot]
0a3921f554
Merge #1844
1844: Fix a couple of very minor bugs r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-04-20 16:27:34 +00:00
CreepySkeleton
3b3d2b23fd cargo clippy 2020-04-20 18:32:35 +03:00
bors[bot]
286c3e5d25
Merge #1841 #1842
1841: One less giant macro (-0.5 kB) r=pksunkara a=CreepySkeleton



1842: Allow rustc inline small functions across crates (-5.5 kB) r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-04-20 15:27:55 +00:00
CreepySkeleton
4ce2a02f78 Corectly handle --foo==a (value is =a) 2020-04-20 17:54:56 +03:00
CreepySkeleton
4d3760a0b3 Correctly handle -磨FOO 2020-04-20 15:15:28 +03:00
CreepySkeleton
32ffdfe855 Correctly handle -f==a (value is =a) 2020-04-20 13:41:37 +03:00
CreepySkeleton
f149f35da4 Allow rustc inline small functions across crates 2020-04-19 19:02:55 +03:00
CreepySkeleton
fae89db4a0 One less giant macro (-0.5 kB) 2020-04-19 15:42:08 +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
David McNeil
247231d1c6 Add ArgPrecedenceOverSubcommand app setting
Signed-off-by: David McNeil <mcneil.david2@gmail.com>
2020-04-16 09:08:39 -05:00
Pavan Kumar Sunkara
070bd50b28 Finished color refactor 2020-04-16 12:51:26 +02:00
bors[bot]
90e5eb6d1a
Merge #1831
1831: Handle publicity properly r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-04-16 06:36:39 +00:00
CreepySkeleton
823332e919 Handle publicity properly 2020-04-16 08:29:16 +03:00
CreepySkeleton
8d01bce5df Use ref instead of move 2020-04-16 04:52:02 +03:00
CreepySkeleton
f931c3d1e4 Suppress unused_valiables lint in non-debug builds 2020-04-16 04:32:17 +03:00
CreepySkeleton
00f2a82c3e Make debug output much more useful 2020-04-14 07:21:27 +03:00
CreepySkeleton
fdaf927384 Remove almost all #[doc(hidden)] 2020-04-14 04:26:12 +03:00
bors[bot]
500f34a8f6
Merge #1811
1811: Replace value_t*! macros with methods r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-04-13 07:49:00 +00:00
CreepySkeleton
ecd60b69a3 Fix tests 2020-04-13 04:44:13 +03:00
CreepySkeleton
af95c2b6a4 Replace value_t*! macros with methods 2020-04-13 04:20:09 +03:00
Pavan Kumar Sunkara
da32adeb0e Allow literals in builder macros 2020-04-12 23:18:39 +02:00
Pavan Kumar Sunkara
3bb8389c73 Enable ansi support for windows before refactoring 2020-04-12 10:20:08 +02: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
Stephan Boyer
606d120d18 Update the documentation regarding which features are enabled by default 2020-04-04 13:16:30 -07:00
AimainaHito
06b9b32d66 Added full-stop 2020-04-04 11:30:30 +02:00
AimainaHito
f472393b14 Updated value_t documentation 2020-04-03 20:32:36 +02:00
Patrick Marks
4321cba5ba set the default disp_ord of App to 999. Required for display_order and DeriveDisplay to work properly 2020-04-01 12:49:40 -07:00
Mátyás Mustoha
8687794986 style: fix comma placement for valid values when using arg_enum 2020-04-01 00:01:51 +02:00
Matthias Krüger
428a075e41 remove redundant imports and clone (found by clippy) 2020-03-25 13:43:01 +01:00
bors[bot]
2aa38e81a9
Merge #1739
1739: Remove _some_ of pubs r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-03-19 23:53:18 +00:00
CreepySkeleton
a46ab1639a Turn some integration tests into unit tests 2020-03-19 10:49:49 +03:00
CreepySkeleton
4fc4a00b8f Remove _some_ of pubs 2020-03-19 10:17:52 +03:00
CreepySkeleton
b61a807728 Fix clippy and bump MSRV 2020-03-13 22:41:40 +03:00
CreepySkeleton
3e1f6ed514 Use proper cfg 2020-03-09 23:42:14 +03:00
CreepySkeleton
329bfa9895 Get rid of extra scopes 2020-03-09 21:08:15 +03:00
Julian Laubstein
c34a0fdae9 Added tests and fixed display of conflicted flags 2020-03-08 17:11:12 +01:00
Julian Laubstein
444bce2471
Fixed #1622 2020-03-08 16:39:14 +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
Donough Liu
79cec6a298 Fix misplaced subcommand matching failure emitter.
Only positional args follow `--`.
2020-03-05 18:38:55 +08:00
Donough Liu
bd1b73d7c8 Another Typo 2020-03-05 17:56:24 +08:00
Donough Liu
c86ac603f1 Typo 2020-03-05 17:17:07 +08:00
Pavan Kumar Sunkara
eaae1202cb Basic github action for benchmarking 2020-03-05 09:21:39 +01: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
Pavan Kumar Sunkara
47782cfac6 Make cargo feature additive 2020-03-01 22:55:57 +01:00
Ivan Tham
908b7aeb44 Ambiguous suggetions for InferSubcommands
Closes #1655
2020-03-01 19:36:05 +08:00
Emily
d36277b644
Fix Clap::try_parse_from documentation 2020-02-25 16:50:47 +00: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
bors[bot]
28c46b5965
Merge #1697
1697: Allow replacing input on the fly r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-02-21 19:13:59 +00:00
Pavan Kumar Sunkara
b8851a7d5e Allow replacing input on the fly 2020-02-21 18:15:33 +01:00
Cecile Tonglet
35b918bd72 Allow missing docs on arg_enum 2020-02-21 11:39:44 +01:00
bors[bot]
cc79c432a4
Merge #1701
1701: Remove unneeded file r=pksunkara a=CreepySkeleton



Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-21 09:51:56 +00:00
CreepySkeleton
4fcff089ef Remove unneeded file 2020-02-21 03:28:25 +03:00
CreepySkeleton
4f13f3155c Fix warnings on nightly 2020-02-21 01:55:19 +03:00
CreepySkeleton
43acfa00f4
Implement derive traits for Box<T> 2020-02-13 18:21:01 +03: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]
12df8cb078
Merge #1681
1681: WIP: Extract subcommands into separate trait r=pksunkara a=CreepySkeleton

Not-yet-working-but-almost-there "multiple traits" approach. More or less done, what's left is to catch some bugs and adapt tests/examples.

For the record: it took so long because of RL stuff (who would have thought?) and because [there was a detailed description of the experience I've had here, but it was deleted because it contained a lot of profanity and emotional notes]. 

As the only person alive that understands how the derive works (if you won't blow your own horn, nobody will do it for you, yeah), I'd like to made a statement: we Do need the refactoring.

Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-12 20:42:32 +00:00
CreepySkeleton
ae574df2f9
Extract subcommands into separate trait 2020-02-12 23:15:05 +03:00
bors[bot]
0660e81231
Merge #1683
1683: Added HelpRequired AppSetting r=pksunkara a=thomasfermi

Closes #1683 

There are likely some problems with my solution to this issue. I would be thankful for a review!

Co-authored-by: thomasfermi <mario.theers@gmail.com>
2020-02-10 17:47:40 +00:00
thomasfermi
f7b63c7be6 Implemented minor review findings. 2020-02-10 17:57:32 +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
thomasfermi
91f37f9358 Deleted unnecessary code in doc comments. 2020-02-09 21:37:19 +01:00
thomasfermi
48eb6a4530 Added HelpRequired AppSetting 2020-02-09 21:05:01 +01:00
bors[bot]
ad5606b5a0
Merge #1678
1678: Refactor clap_generate r=CreepySkeleton a=pksunkara

I have copied the code from [clap_generate]( https://github.com/clap-rs/clap_generate) and refactored the structure a bit.

This new structure will allow people to write their own generators using our `Generator` trait which will contain some helpers (Still working on polishing them).

Co-authored-by: Ole Martin Ruud <barskern@outlook.com>
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-02-08 15:00:50 +00:00
Pavan Kumar Sunkara
33f47acc67 Refactor clap_generate 2020-02-07 07:52:04 +01:00
Pavan Kumar Sunkara
5b3a0dff9c Remove extern & macro_use where possible 2020-02-07 07:34:01 +01:00
thomasfermi
582e2d39f3 Fixed typo 2020-02-05 17:24:40 +01:00
bors[bot]
509ac33a20
Merge #1664
1664: Import structopt r=pksunkara a=CreepySkeleton

OK, here is about 50% of what's left to import.

`impl StructOpt for Box<impl StructOpt>` is not imported because layouts of `StructOpt` and `Clap` are too different. I'll work it out after the import is done.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/clap-rs/clap/1664)
<!-- Reviewable:end -->


Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
Co-authored-by: David McNeil <mcneil.david2@gmail.com>
2020-02-05 08:43:57 +00:00
bors[bot]
e7d3600128
Merge #1670
1670: Minor refactoring r=pksunkara a=CreepySkeleton

Some minor improvements. Also gets some bugs fixed

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/clap-rs/clap/1670)
<!-- Reviewable:end -->


Co-authored-by: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-05 08:23:28 +00:00
CreepySkeleton
ffad57c776
Update src/macros.rs
Co-Authored-By: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-02-05 10:44:20 +03:00
CreepySkeleton
28605ba326 Fix macro 2020-02-05 10:17:11 +03:00
CreepySkeleton
afac737f69 Minor refactoring 2020-02-04 19:02:29 +03: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
rleungx
4082d1e85c exactly match a subcommand when using the infersubcommands 2020-02-04 09:41:05 +01:00
CreepySkeleton
cf11d46373 Default value for default_value (yeah, sounds awkward) 2020-02-04 11:40:01 +03:00
Alex van de Sandt
050bb7484a Fix formatting 2020-02-03 13:04:07 -05:00
Alex van de Sandt
47031213a2 Remove needless fn main from doc tests 2020-02-03 12:31:24 -05:00
Alex van de Sandt
928ded9d42 Revert "Remove #[macro_use] from src"
This reverts commit 7dcdfc8b231b41a46d4d7ab7ec2664d32804b4a3.

That commit caused doc tests to break, as well as issues with importing
macros in other modules. Note that the yaml example in `src/lib.rs` at
line 184 is broken and should probably be fixed.
2020-02-03 12:04:13 -05:00
Alex van de Sandt
fd6b32ff55 Remove #[macro_use] from src 2020-02-03 12:04:13 -05:00
Pavan Kumar Sunkara
c5eb08431a Apply suggestions from code review 2020-02-03 12:37:37 +01:00
Dylan DPC
a2ff3fa91b Revert " imp: Add exitcode::USAGE exit code as suggested in #1327" 2020-02-03 12:37:37 +01:00
Toothless204
ebdc0453eb
Update src/build/arg/mod.rs
make error message more descriptive

Co-Authored-By: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-02 12:19:55 +00:00
Toothless204
8b2a9928e8 added check for - 2020-02-02 11:48:35 +00:00
Dylan DPC
922a531fa6
Update lib.rs 2020-02-02 02:02:10 +01:00
Pavan Kumar Sunkara
2a6005657e Apply suggestions from code review
Co-Authored-By: CreepySkeleton <creepy-skeleton@yandex.ru>
2020-02-01 06:55:47 +01:00
Pavan Kumar Sunkara
dd75cee72c fix: Clippy should pass 2020-02-01 06:48:50 +01:00
Daniel Eades
d23df44e84 refactor: remove deprecated 'Error::description' method 2020-01-31 18:37:56 +01:00
Pavan Kumar Sunkara
8e4a189ab0 fmt: Use standardized rustfmt rules 2020-01-31 18:37:56 +01:00
Pavan Kumar Sunkara
c799e8d0ca chore: Updated contributing instructions and justfile 2020-01-31 18:37:56 +01:00
Daniel Gray
a1445b0f3b imp: Add exitcode::USAGE exit code as suggested in #1327
The reason to do this is described well in issue #1327. It is also a
recommendation of the Rust book itself:
https://rust-cli.github.io/book/in-depth/exit-code.html
2020-01-17 11:20:45 -04:00
Luca Bruno
f3683a9792 output: get rid of an unsafe block (#1636)
* parse: fix build in debug mode

This fixes a build failure in debug mode, as the value to be printed
does not implement Display.

* output: get rid of an unsafe block

This get rid of an unsafe block which is not necessary, and only used
when building in debug mode.
2020-01-17 19:05:18 +05:30
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
Jeremy Stucki
2e1acb648c Refactor mkeymap (#1618)
* refactor(mkeymap): Use iterators

* refactor(mkeymap): Implement contains method

* refactor(mkeymap): Deprecate methods

Co-authored-by: Dylan DPC <dylan.dpc@gmail.com>
2020-01-09 23:00:22 +05:30
Gregor Pfeifer
8b5ecf92e4 fix: Typos in Arg::conflicts_with_everything` (#1625)
Related to https://github.com/clap-rs/clap/pull/1624
2020-01-06 00:50:15 +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
xidaxmb
f402f7a113 imp(usage_parser.rs): add default value support (#1522)
Co-authored-by: Dylan DPC <dylan.dpc@gmail.com>
2020-01-03 17:18:09 +05:30
dylan_DPC
1c79bb5b28 fix subcommand is private bug 2020-01-01 23:28:06 +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
Dylan DPC
335f34bee2 fix broken CI 2019-11-11 14:28:30 +01:00
Dylan DPC
dd6c8e08ad use 2018 edition and minor refactors 2019-11-11 12:54:55 +01:00
Kevin K
750796b9ca
Merge branch 'master' into one-less-unsafe 2019-11-03 14:21:56 -05:00
Stéphane Campinas
4d69942db7
fix(Error): remove Copy trait bound by formatting both plain and colored error cause at the same time 2019-11-02 21:36:16 +01:00
Stéphane Campinas
991b839069
refactor(Error): add cause field to group_conflict error 2019-11-02 21:36:16 +01:00
Stéphane Campinas
15ad5954b0
feat(Error): add a cause field to the Error struct
The cause field is the actual error described in the message field,
however without extra information like usage.

Close #861
2019-11-02 21:36:11 +01:00
Sergey "Shnatsel" Davidoff
0a010a4371 Add comment on performance 2019-11-02 21:03:35 +01:00
Sergey "Shnatsel" Davidoff
925956d594 Do not leak a new string on every invocation of crate_authors! 2019-11-02 20:18:57 +01:00
Sergey "Shnatsel" Davidoff
0085bb7ee2 Make code actually work 2019-11-02 19:48:16 +01:00
Sergey "Shnatsel" Davidoff
63829a2a9f Drop unnecessary unsafe 2019-11-02 18:33:17 +01:00
Kevin K
269a5d2bb6
Merge pull request #1523 from shua/master
imp(macros): add subcommand expr macro
2019-10-30 20:29:52 -04:00
Luca BRUNO
d74e0646d2
app: quote field names in errors
This quotes all field names in errors. It makes easier for humans to
disambiguate common network-related cases which currently end up in
messages like "address is already in use".
2019-10-30 08:30:10 +00:00
shua
452b80d334 add subcommand expr macro 2019-10-30 00:22:05 -04:00
Brian Foley
56d182d98b
Qualify all names in bodies of exported macros with $crate::
The lack of qualification caused odd errors such as:

```
use clap;
let foo = clap::value_t!(matches.value_of("foo"),i u32).unwrap(); # OK
lot bar = clap::value_t!(matches, "bar", u32).unwrap(); # Compile fail
```

but

```
use clap::value_t;
let foo = value_t!(matches.value_of("foo"),i u32).unwrap(); # OK
lot bar = value_t!(matches, "bar", u32).unwrap(); # OK
```
2019-10-29 21:48:49 -04:00
Thiago Arrais
c3b7c01f54
Provide default_values mimicking default_value 2019-10-29 21:48:10 -04:00
Za Wilcox
fed3a8fc29
where -> were 2019-10-29 21:47:51 -04:00
Za Wilcox
14bfbd6ef4
add missing 'the' 2019-10-29 21:47:42 -04:00
Kevin K
c91d523d41
cargo clippy & rustfmt 2019-10-29 21:47:32 -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
Tobias Kunze
ed69a688ff
Fix some typos in the docs 2019-10-29 21:45:09 -04:00
demoray
7f835ed24d
use std::sync::Once::new() rather than ONCE_INIT
Updated to v3-master per discussion on #1521
2019-07-23 10:03:07 -04:00
Dylan DPC
180b6b82de
Merge pull request #1520 from nootanghimire/style/add-newline-after-printing-help
style(help): add newline after writing help
2019-07-23 12:35:19 +02:00
Nootan Ghimire
a87284020f
style(help): add newline after writing help 2019-07-17 10:44:14 +10: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
ebfe225af3 refactor(Parser,Errors): refactor(Parser,Errors): Update unknown_argument function to take option
Update unknown_argument function to take option
2019-07-01 11:25:46 -05: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
Roy Ivy III
89f8cc6929 fix: add 'require_equals' support to YAML parsing 2019-06-23 11:37:22 -05:00
Jeremy Stucki
9e10c45505
Use map instead of 'if let' 2019-06-21 09:54:19 +02:00
Jeremy Stucki
c6327bc22f
Use initialization shorthand 2019-06-21 09:06:06 +02:00
Jeremy Stucki
c5c64d48b7
Use map_or instead of match 2019-06-21 09:04:54 +02:00
Jeremy Stucki
5ff2bb4dcf
Use map instead of match on Option 2019-06-21 09:02:33 +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
Erick Tryzelaar
2e2616b59e Fix compiling on windows
This fixes compilation errors when building clap targetting windows with:

```
% rustup run nightly cargo check --target x86_64-pc-windows-msvc
```
2019-06-19 15:47:50 -07:00
Kevin K
46e81ca0b9
perf: only propagates to a single subcommand instead of all subcommands 2019-04-05 20:21:36 -04:00
Kevin K
958437661a
chore: clippy fixes 2019-04-05 20:21:34 -04:00
Kevin K
fcbae1574a
style: rustfmt run 2019-04-05 20:21:33 -04:00
Kevin K
573b0a9e88
chore: upgrades to 2018 edition of Rust 2019-04-05 20:21:30 -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
3dffd4908c
Removing the lint features and invoking cargo clippy manually instead 2019-04-04 13:27:08 -04:00
Erich Gubler
ab65a0200d
Use $crate prepend to make importing the _clap_count_exprs macro unnecessary 2019-04-04 13:21:28 -04:00
Kevin K
9399174416
perf: trims down some macro usage 2018-11-14 21:04:15 -05:00
Kevin K
eafee3c5c1 style: cargo fmt run 2018-11-14 14:01:48 -05: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
441f539ede
Merge pull request #1370 from andrewmiller1/yaml-mismatched-types-char
Yaml mismatched types char
2018-11-08 20:37:44 -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
andrewmiller1
2fcf308792 fix: fixes yaml feature build 2018-11-04 18:44:28 -06: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
03333800fe refactor: remove code going to other crates and deprecations 2018-10-19 23:31:06 -04:00
Alena Yuryeva
1216cddb63 Fixed help benchmark 2018-09-01 20:42:31 +03:00
Kevin K
99bd101ea7
tests: fixes did_you_mean tests 2018-08-27 21:44:09 -04:00
Kevin K
3d662286bc
tests: fixes macro tests 2018-08-27 20:42:07 -04:00
Kevin K
400fafade2
tests: fixes help tests 2018-08-27 20:25:37 -04:00
Kevin K
3c433636fd
tests: fixes posix_compatible test 2018-08-20 20:35:57 -04:00
Kevin K
d90186d3bb
tests: fixes mkeymap tests 2018-08-20 20:28:51 -04:00
Kevin K
6c5d4c5896
tests: fixes the app_settings tests 2018-08-20 20:23:52 -04:00
Alena Yuryeva
a5346484e8 WIP 2018-08-19 17:46:59 +03:00
Alena Yuryeva
8993a702fe Fixed help 2018-08-11 21:55:58 +03:00
Alena Yuryeva
632f745578 Fixed positionals tests 2018-08-11 21:48:50 +03:00
Alena Yuryeva
b48ef85ece fixed unique_args tests 2018-08-11 21:32:06 +03:00
Alena Yuryeva
deb9fc91f6 Fixed opts & version tests 2018-08-11 21:11:11 +03:00
Alena Yuryeva
c501773ed3 Tests on flags passing 2018-08-11 20:34:40 +03:00
Kevin K
f4e19a3193
Merge branch 'map' of github.com:clap-rs/clap into map 2018-08-04 19:22:52 -04:00
Kevin K
4ff03096fb
fix: fixes rebase errors 2018-08-04 19:14:13 -04:00
Alena Yuryeva
87c88d6054
Arg-specific API for MKeyMap 2018-08-04 18:37:35 -04:00
Kevin K
a75b67838e
refactor(Suggestions): changes from string slice to owned string for return values
The return value is only used in the error case, and only a single
String allocation, therefore the complexities introduced by using string
slices isn't worth it. clap primarily only needs to be as fast as
possible in the happy path, the error path can afford additional
allocations.
2018-08-04 18:34:54 -04:00
Alena Yuryeva
272170e333
WIP 2018-08-04 18:32:08 -04:00
Alena Yuryeva
f230cfedc3
WIP 2018-08-04 18:26:33 -04:00
Alena Yuryeva
7e5a6935b9
WIP. Big reformat 2018-08-04 18:22:10 -04:00
Alena Yuryeva
7faf6c7721
MkeyMap API changes 2018-08-04 18:13:34 -04:00
Alena Yuryeva
3efcf3ae03
WIP changing macros into MKeyMap calls 2018-08-04 18:13:33 -04: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
a769639f8b
chore: prepares for the move to clap-rs org 2018-08-01 23:06:12 -04:00
Kevin K
9d2d9f7a6c
fix: fixes some suggestions tests 2018-08-01 22:23:36 -04:00
Kevin K
49defad11b
fix: fixes help output tests 2018-08-01 22:09:09 -04:00
Kevin K
e1371ad15c
fix: fixes group conflicts tests 2018-08-01 21:56:03 -04:00
Kevin K
a2cd63cc9e
fix: fixes group tests on v3-master 2018-08-01 21:43:55 -04:00
Alena Yuryeva
eb01627463 Arg-specific API for MKeyMap 2018-08-01 20:33:55 +05: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
be23ec9701
refactor(Suggestions): changes from string slice to owned string for return values
The return value is only used in the error case, and only a single
String allocation, therefore the complexities introduced by using string
slices isn't worth it. clap primarily only needs to be as fast as
possible in the happy path, the error path can afford additional
allocations.
2018-07-29 16:16:45 -04:00
Alena Yuryeva
cc9518b9d4 WIP 2018-07-29 23:20:17 +05:00
Alena Yuryeva
c7131e3ed4 WIP 2018-07-26 20:26:12 +05:00
Alena Yuryeva
e1fb98a0c1 WIP. Big reformat 2018-07-26 20:23:58 +05:00
Alena Yuryeva
7e6d403009 MkeyMap API changes 2018-07-26 20:18:47 +05:00
Alena Yuryeva
98d37c133e WIP changing macros into MKeyMap calls 2018-07-26 20:18:47 +05:00
Kevin K
c22bc3e1fc
depr(SubCommand::with_name): deprecates SubCommand facade to prefer App::new 2018-07-24 16:57:18 -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
8715ac268c
chore: makes some effectively private APIs public for clap_generate to use 2018-07-23 16:27:25 -04:00