Commit graph

43 commits

Author SHA1 Message Date
Ed Page
b538a43961 refactor(error): Switch to error::ErrorKind 2022-02-02 15:41:24 -06:00
Ed Page
4538d618a7 refactor: Migrate off of .kind 2022-02-01 11:27:08 -06:00
Ed Page
0d1f34b91d fix: Finish reverting clap_app 2021-12-02 10:45:10 -06:00
Ed Page
045bf99ae0 test: Consolidate builder tests
This is prep for moving the derive tests.  Besides organizing the test
folder for each API, this should reduce link time at the cost of
re-compiling more when a test changes.
2021-11-30 10:07:05 -06:00
Ed Page
263fe30568 feat: Usage parser macro
This is intended to replace the runtime usage parser and is not meant to
be a complete API in of itself, like `clap_app!`.  What is in scope is
everything that visually makes sense as in a usage string (see
[docopt](http://docopt.org/) for inspiration).  General setting of
attributes is out of scope.

This deviates from both `clap_app` and the runtime usage parser
- `clap_app` supported multiple values but has a bug because we made
  `Arg::value_name` non-appending, so we aren't supporting this yet
- We do not yet support optional flags that take a value
- In both, `...` is multiple occurrences and values while its only
  multiple occurrences for us
- We explicitly support optional values for flags
- Unlike `clap_app`, our name is optional
- Unlike runtime usage parser, our name syntax is simpler
- Unlike runtime usage parser, our name syntax does not allow modifiers

Its more limited than I would like.  Hopefully some people better with
macros can expand the feature set and turn more runtime errors into
compile-time errors.

This is to prepare for deprecating the runtime usage parser (#8).
2021-11-22 16:21:09 -06:00
rhysd
012f318c97 feat(doc): Fix many typos in docs, comments and codes found by typos-cli 2021-10-19 10:38:22 +09:00
Ed Page
61c9e6265b fix(help)!: Merge OPTIONS / FLAGS default groups
For those that want the original behavior, you can usxe
`arg.help_heading(Some("FLAGS"))` on your flags.  Limitations:
- This will not give you a special sort order
- This will not get a `[FLAGS]` added to usage

For templates, we removed `{unified}` and `{flags}`.  To help people
catch these, a debug_assert was added.

I'm unsure but I think there might be a change in behavior in calcuating
when to show `[OPTION]` in usage.  The old code only looked at
`required` while flags looked only at arg groups.  We now look at both.

Ideally we'd add these in `_build` and remove special casing for
no-groups except in the sort order of groups.  I feel like thats best
left for later.

This also reduced the scope of `App`s public API.
`get_*_with_no_heading` seemed a bit specialized to be in the public
API.  #2853 looks at splitting it out into its own PR.

BREAKING CHANGE: Multiple
- `UnifiedHelpMessage` removed
- `{flags}` and `{unified}` are removed and will assert when present.
- `get_*_with_no_heading` removed

Fixes #2807
2021-10-13 11:42:10 -05:00
Pavan Kumar Sunkara
efeb02cd34 fix!: Make color settings an enum 2021-10-13 13:54:44 +01:00
Ed Page
0a53fafddf fix: Deprecate Macro API
Fixes #2835
2021-10-11 15:06:38 -05:00
Kevin K
14c8850019
tests: fixes test to new default behavior
This commit corrects tests to not expect the `-V,--version` flag when no
version information has been provided.
2021-10-09 11:12:50 -04:00
Morley, Jonathan
1d3a292d6b assert on leading and trailing whitespace 2021-09-24 12:38:15 -04:00
patrick-gu
a4dc72ed19 Replace "Prints" with "Print" for default help and version commands 2021-07-29 20:23:25 -07: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
ldm0
448ff95fb0 ldm0's patch 2021-03-09 19:06:44 +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
Pavan Kumar Sunkara
e8a06e79cd Rename setting VersionlessSubcommands => DisableVersionForSubcommands 2020-10-24 16:04:49 +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
Constantin Nickel
fbfbf8df99 feat(macros): Add @global_setting $setting to set global settings 2020-07-13 15:13:04 +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
Pavan Kumar Sunkara
dbe6ac01f6 Clean up arg_enum 2020-04-22 14:38:16 +02:00
Pavan Kumar Sunkara
da32adeb0e Allow literals in builder macros 2020-04-12 23:18:39 +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
Pavan Kumar Sunkara
f0a216036b Fix some issues 2020-04-09 19:41:33 +02:00
Alex van de Sandt
1055bbe4aa Remove #[macro_use] from tests 2020-02-03 12:01:36 -05:00
shua
452b80d334 add subcommand expr macro 2019-10-30 00:22:05 -04:00
Kevin K
fcbae1574a
style: rustfmt run 2019-04-05 20:21:33 -04:00
Kevin K
03333800fe refactor: remove code going to other crates and deprecations 2018-10-19 23:31:06 -04:00
Kevin K
eaa0700e7e
style: rustfmt run 2018-08-01 23:13:51 -04:00
Christian Legnitto
36815fec59 imp(macros): Support shorthand syntax for ArgGroups
Fixes https://github.com/kbknapp/clap-rs/issues/1231.
2018-04-03 23:03:21 -04:00
Kevin K
1ab10275e4
style: rustfmt run 2018-01-25 12:21:17 -05:00
Kevin K
efb3b28ae8
tests: updates the tests that were using clap internals 2018-01-25 12:20:56 -05:00
Eduardo Pinho
dde7fcf1ca Support trailing comma in arg_enum! fields 2017-12-07 00:53:55 +00:00
Kevin K
fb08bb5dd5 refactor: removes unused imports on nightly via cfg directive
If one is using a nightly Rust compiler they should compile clap
with the `nightly` feature.

```toml
[dependencies]
clap = { version = "2.27", features = ["nightly"] }
```

This isn't required for compilation to succeed, only to take
advantage of any nightly features used by clap.

If one is compiling with `#[deny(warnings)]` this commit will cause
compilation to fail if one *does not* compile with the `nightly`
since `std::ascii::AsciiExt` is no longer required in in multiple
files as of the latest Rust nightly (Nov 6th, 2017).

Closes #1095
2017-11-06 20:11:19 -05:00
Kevin K
c83a559df1 tests(clap_app!): adds tests for ("config-file") style positonal args 2017-04-05 00:57:40 -04:00
Kevin K
0efa411963
perf: refactor to remove unneeded vectors and allocations and checks for significant performance increases
Building an `App` struct with a fair number of args/flags/switches, etc. (used ripgrep as test case)
went from taking ~21,000 ns to ~13,000ns.
2017-02-28 08:30:13 -05:00
Martin Geisler
d6743bb70d Fix compilation warnings (#825)
* tests: remove unnecessary mut

When building the projec, I was told

    warning: variable does not need to be mutable, #[warn(unused_mut)]
    on by default
      --> tests/macros.rs:39:9
       |
    39 |     let mut app = clap_app!(("app name with spaces-and-hyphens") =>
       |         ^^^^^^^

* examples: remove unused variable

The inner Some value is not used in the match arm:

    warning: unused variable: `local_matches`,
    #[warn(unused_variables)] on by default
       --> examples/20_subcommands.rs:128:32
        |
    128 |                 ("local", Some(local_matches)) =>{
        |                                ^^^^^^^^^^^^^
2017-01-29 18:13:49 -08:00
Kevin K
f967235a90
tests: massively rehauls tests for better debugging and vastly improved error messages/deduplication 2017-01-02 23:05:50 -05:00
Arnavion
f41ec962c2 feat(clap_app!): Support --("some-arg-name") syntax for defining long arg names
Used for arg names that aren't idents.

Ref #321
2016-12-12 22:42:11 -08:00
Arnavion
9895b671cf feat(clap_app!): Support ("some app name") syntax for defining app names
Used for setting names that aren't Rust idents.

Fixes #759
2016-12-12 22:42:11 -08:00
Arnavion
79bbf57815 tests(clap_app!): Added test for clap_app! macro. 2016-12-12 22:42:11 -08:00