Commit graph

297 commits

Author SHA1 Message Date
Ed Page
973f30fb22 refactor(docs): Use intra-doc links to avoid breakages 2022-09-30 13:16:13 -05:00
Ed Page
4a1552cc0e perf: Drop use of Into::into for '?'
For binary size, this only dropped 0.2 KiB

For performance, before:
- parse_rustup_with_sc    time:   [7.9866 µs 8.0138 µs 8.0470 µs]
After:
- parse_rustup_with_sc    time:   [7.5387 µs 7.5722 µs 7.6157 µs]

For build-time, before
```console
$ hyperfine --warmup=1 --min-runs=5 "--prepare=cargo clean" "cargo build -F cargo --example cargo-example"
Benchmark 1: cargo build -F cargo --example cargo-example
  Time (mean ± σ):     16.988 s ±  1.190 s    [User: 68.178 s, System: 6.637 s]
  Range (min … max):   15.550 s … 18.277 s    5 runs
```
After:
```console
$ hyperfine --warmup=1 --min-runs=5 "--prepare=cargo clean" "cargo build -F cargo --example cargo-example"
Benchmark 1: cargo build -F cargo --example cargo-example
  Time (mean ± σ):     15.674 s ±  0.222 s    [User: 62.287 s, System: 4.608 s]
  Range (min … max):   15.426 s … 15.993 s    5 runs
```
2022-09-26 12:31:39 -05:00
Ed Page
c4b3a4f491 refactor: Remove use of '?' 2022-09-26 12:19:30 -05:00
Ed Page
a76f622d17 docs: Clarify when quoting is required for arg 2022-09-21 11:49:18 -05:00
Ed Page
bbbaca2ffe perf: Hint to the compiler when once_cell isn't needed 2022-09-16 16:14:32 -05:00
Ed Page
10854cd262 Revert "refactor: Remove once_cell dependency"
This reverts commit c9d883a8c6.
2022-09-16 16:14:32 -05:00
Ed Page
c9eef44213 fix: Make arg!(--flag <value>) optional by default
This was ported over from the usage parser which modeled after docopt.
We just never got around to implementing the rest of the syntax.

However, when considering this as a standalone feature, an
`arg!(--flag <value>)`, outside of other context, should be optional.
This is how the help would display it.

Fixes #4206
2022-09-12 17:10:01 -05:00
Ed Page
b0cac0845e refactor(help): Pull out a StyledStr
This is prep for making it public
2022-08-23 17:05:55 -05:00
Ed Page
276c75cc08 fix: Don't pollute root with str types 2022-08-23 13:12:06 -05:00
Ed Page
c9d883a8c6 refactor: Remove once_cell dependency 2022-08-22 16:07:14 -05:00
Ed Page
96f91ca092 refactor(assert): Make it easier to change id type
Compared to `master` on `06_rustup`:
- build: 5.74us -> 6.21us
- parse: 7.57us -> 7.55us
- parse_sc: 7.60us -> 7.95us
2022-08-12 15:43:22 -05:00
Ed Page
07b6e66eb7 fix: No implicit version/help actions
Documenting the existing behavior is challenging which suggests it can
cause user confusion.  So long as its not too hard to explicitly
specify actions, we should just do it.

Fixes #4057
2022-08-10 21:21:53 -05:00
Ed Page
95207a1e6f fix: Ensure arg! gets help/version correct
Because of our changes from v3, we can't rely on `_build` taking care of
this for us.
2022-08-05 14:12:48 -05:00
Ed Page
6e1ca59ec1 fix!: Make is_takes_value_set private
At this point, it is an implementation detail to help with book keeping
within the builder.
2022-08-04 14:44:14 -05:00
Ed Page
c62d3f0cfd fix!: Replace takes_value with number_of_values 2022-08-04 09:39:25 -05:00
Ed Page
ba15b5f430 fix!: Rename Arg::number_of_values to Arg::num_args 2022-08-03 14:45:47 -05:00
Ed Page
470531b515 fix!: Replace multiple_values with number_of_values
This reduces ambiguity in how the different "multiple" parts of the API
interact and lowrs the amount of API surface area users have to dig
through to use clap.

For now, this is only a matter of cleaning up the public API.  Cleaning
up the implementation is the next step.
2022-08-01 15:50:23 -05:00
Ed Page
76bff6f34e fix!: Remove rest of deprecated APIs
Fixes #4009
2022-08-01 15:21:33 -05:00
Ed Page
ab8ef46663 fix: arg!(--long [value]) to per occurrence values
Before we did 0..=1 across all occurrences when what we really wanted
was 0..=1 per occurrence.  This makes it compatible with
`ArgAction::Append`.
2022-07-28 16:52:30 -05:00
Ed Page
5f20fe1930 docs: Shift focus from takes_value to actions 2022-07-26 14:50:51 -05:00
Ed Page
0039ef91fa fix: Have arg! collection across flags for positionals 2022-07-22 19:51:23 -05:00
Ed Page
36dcb05d96 fix!: Change arg! to use ArgAction
Fixes #3795
2022-07-22 13:24:40 -05:00
Ed Page
b94d5fcec0 fix!: Remove renamed deprecated functions 2022-07-21 14:57:55 -05:00
Ed Page
d4d21b0f7f fix!: Remove WaitOnError 2022-07-21 13:35:49 -05:00
Ed Page
819c1e061d fix!: Remove deprecated macros 2022-07-21 13:03:21 -05:00
Ed Page
99d92c916c fix!: Remove yaml support 2022-07-21 12:46:47 -05:00
Stiopa Koltsov
464ef3920b refactor: Put once_cell reexport into __macro_refs
When upgrading our company projects from clap 3.1 to clap 3.2 I had
to fix several references to `clap::lazy_init`. People are not
supposed to do that, but that's hard to enforce.

Hope placing `once_cell` reexport into `__macro_refs` prevent at
least some of the such issues in the future.
2022-06-26 04:13:03 +01:00
Ed Page
f9e51952b8 fix(docs): Update deprecations to latest target
Before, I was mixed on doing this as ideally people would upgrade
through the minor releases, going through the release notes.  This also
saves us havin to audit deprecations to make sure they are all pointing
to the latest.

First, this isn't practical for users.  Its annoying to pin your version (at least
its easier now that we pin `clap_derive` for users) and a lot of work to
go through them one step at a time.

On top of that, we've changed our deprecation policy to put the timing
of responding to deprecations into the user's hands with, with us
putting them behind the `deprecated` feature flag.  This means someone
might respond to deprecations every once in a while or might not do it
until right before the 4.0 release.  Our deprecation messages should be
updated to respond to that.

This supersedes #3616
2022-06-22 14:31:15 -05:00
Ed Page
7515bfeb51 fix: Allow people to opt-in to deprecations
This adds a new `Cargo.toml` feature named `deprecated` that opts
controls whether deprecation warnings show up.  This is starting off as
non-default though that may change (see below).

Benefits
- Allows a staged rollout so a smaller subset of users see new
  deprecations and can report their experience with them before everyone
  sees them.  For example, this reduces the number of people who have to
  deal with #3822.
- This allows people to defer responding to each new batch of
  deprecations and instead do it at once.  This means we should
  reconsider #3616.

The one risk is people who don't follow blog posts and guides having a
harder time upgrading to the next breaking release without the warnings
on by default.  For these users, we reserve the right to make the
`deprecated` feature `default`.  This is most likely to happen in a
minor release that is released in conjunction with the next major
release (e.g. when releasing 4.0.0, we release a 3.3.0 that enables
deprecations by default).  By using a feature, users can still disable
this if they want.

Thanks @joshtriplett for the idea
2022-06-14 10:50:05 -05:00
Ed Page
cb42df61e4 refactor: Switch to once_cell
Though this is changing an API item we export, we do not consider this a
breaking change because
- This was an implementation detail of the macros and people shouldn't be using it directly
- The `macro_rules` macro is coupled to `clap` because they are in the
  same crate
- The derive macro is coupled to `clap` because `clap` declares a
  `=x.y.z` dependency on `clap_derive

Fixes #3828
2022-06-14 09:10:50 -05:00
Ed Page
14a62e11fd fix(parser): Deprecate multiple_occurrences
Fixes #3772
2022-06-08 09:54:23 -05:00
Ed Page
52f6939044 fix(macros): Add needed call for arg_enum
Fixes #3717
2022-05-10 14:43:04 -05:00
Evgeniy Terekhin
229b44d9bb
fix(macros): Allow dashed values (#3699)
add support for dashed arg names and values in arg! macro
2022-05-06 10:58:00 -05:00
Ed Page
6a9a5d05b0 refactor(help): Make bool's meaning clearer 2022-04-21 16:01:47 -05:00
Samuel Tardieu
ef3c2c73d5 docs: arg! macro uses double quotes for help string 2022-03-25 11:00:47 +01:00
Ed Page
c6d456f608 fix(builder): Tell users cargo feature is needed
This will help in cases like #3530
2022-03-03 12:43:10 -06:00
Ed Page
360c4d6b8a docs: Update to new command! macro 2022-02-15 08:54:59 -06:00
Ed Page
65b9c88b3c fix: Update app_from_crate for App rename
Instead of just renaming it, I reconsidered what the API should look
like.  A custom separator for author does not make sense positionally
but accepting a name, and defaulting it, does fit with what someone
would expect.

I removed the `_from_crate` suffix because it doesn't seem necessary.
We don't have this kind of naming for the derive.  I feel it cleans
things up this way.
2022-02-15 08:39:07 -06:00
Ed Page
e8010e79a9 refactor: Update app variables to cmd 2022-02-14 15:55:56 -06:00
Ed Page
c4144d7d6c docs: Update App references to Command 2022-02-14 15:33:49 -06:00
Ed Page
6c7126b156 docs: Hide items deprecated in 3.0.0
We left them in the docs for a period of time to help people find docs
for code that was still in use.  Balancing that with the need for clean
docs, it seems like 3.1 is an appropriate time to mark them hidden in
the docs.
2022-02-11 18:42:28 -06:00
Ed Page
d3f5d7ce34 fix: Clarify Arg/ArgGroup id's role
This adjusts names.  Adjusting the derive naming (and re-naming) is left
to #2475.

Fixes #3335
2022-02-11 14:11:50 -06:00
Ed Page
47d76742eb feat: Add Arg getters for all settings
This is prep for #2717
2022-02-10 10:18:41 -06:00
Ed Page
8a30b01bc1 refactor(yaml): Freeze FromStr 2021-12-09 09:36:00 -06:00
Ed Page
f16bdcc821 fix!: Limit Setting FromStrs to YAML
These exist pretty much just for YAML (#3087).  If anyone else is
building on these, it has a limited shelf-life anyways because of #2717.

BREAKING CHANGE: `FromStr` for settings requires the `yaml` feature.
2021-12-09 09:03:54 -06:00
Ed Page
9d7becca68 docs: Update deprecation messages
- Some still referenced the clapng issue number
- Some YAML ones were missed in the formatting clean up
- I never updated the usage ones with the formatting clean up
2021-12-09 06:47:37 -06:00
Ed Page
e5997c1001 docs: Clarify deprecations 2021-12-08 11:14:47 -06:00
Ed Page
b2836c07a7 fix: Gracefully handle empty authors 2021-12-06 11:30:26 -06:00
Ed Page
c8254918d6 fix: Add back arg_enum 2021-12-02 16:06:21 -06:00
Ed Page
0d1f34b91d fix: Finish reverting clap_app 2021-12-02 10:45:10 -06:00