Commit graph

7443 commits

Author SHA1 Message Date
Ed Page
e1aafce431 test(tutorial): Ensure we actually test code
Biggest problem identified is that we are incorrectly setting the help
usage in `04_04_custom`
2022-08-08 14:05:08 -05:00
Ed Page
179faa6bb2
Merge pull request #4032 from epage/flag
fix!: Make ArgAction::Set the default
2022-08-05 19:22:50 -05:00
Ed Page
69ad5cfd84 test(derive): Highlight current behavior for version/help 2022-08-05 14:22:09 -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
0105b65e4e fix: Limit defaulting multiple values to Append 2022-08-05 13:38:11 -05:00
Ed Page
c801e4e56e fix!: Make ArgAction::Set the default
This removes the need for `TakesValue` bookkeeping for when we knew we
took values but didn't know how many we should take.

Fixes #2687
2022-08-05 13:31:33 -05:00
Ed Page
8ed35b4d9f fix: Provide convenient access for common cases 2022-08-05 12:06:54 -05:00
Ed Page
c1468d78b1 refactor: Renamge ValuesRange to ValueRange
Naming is hard.  I found I was writing new code without the `s` so that
suggests the name was wrong.  But we renamed `number_of_values` to
`num_args`, so should this be `ArgRange`?
2022-08-05 12:00:33 -05:00
Ed Page
58b0529d13
Merge pull request #4031 from epage/multiple
refactor: We don't need MultipleValues for bookkeeping afterall
2022-08-04 17:51:45 -05:00
Ed Page
e3153e3039 refactor: We don't need MultipleValues for bookkeeping afterall
TakesValue helps because it provides a way for a lot of settings to say
a value is needed without specifying how many.  Multiple values didn't
have enough call sites to make this worthwhile.

This is a part of #2688
2022-08-04 16:11:03 -05:00
Ed Page
fcbcafcd74
Merge pull request #4030 from epage/take
fix!: Remove bookkeeping getters from API
2022-08-04 16:02:47 -05:00
Ed Page
32f308d4ef fix!: Make is_multiple_values private
multiple_values is now just book keeping for the builder, instead people
should look to actions and `num_args`.

The meaning for it was a little weird anyways.
2022-08-04 15:21:10 -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
52ec1f92e9 fix: Clarify that get_num_args is safe to call
The only time it won't be initialized is before `_build`.  This is possible because
of #4027

I wish I could just put the `expect` inside the call but I'm worried
about allowing people to build stuff on top of clap.
2022-08-04 14:21:53 -05:00
Ed Page
91b10554f4
Merge pull request #4028 from epage/value
fix!: Replace takes_value with number_of_values
2022-08-04 09:53:23 -05:00
Ed Page
c62d3f0cfd fix!: Replace takes_value with number_of_values 2022-08-04 09:39:25 -05:00
Ed Page
29753b6798 fix: Remove references to number_of_values 2022-08-04 09:35:59 -05:00
Ed Page
14c8f333cd
Merge pull request #4027 from epage/name
fix: Always ensure `num_args` is initialized
2022-08-04 09:25:38 -05:00
Ed Page
479ca76491 fix: Always ensure num_args is initialized
As we move people off takes_value/multiple_values, this will provide
something to check.

This was previously blocked on other issues related to flag handling
(#4023)
2022-08-04 09:11:29 -05:00
Ed Page
dc5ce00162
Merge pull request #4026 from epage/require
fix!: Remove `Arg::rwquire_value_delimiter`
2022-08-04 00:48:19 -05:00
Ed Page
5d1ec08199
Merge pull request #4025 from epage/trailing2
fix(parser)!: Split on value delimiter after validating num_args
2022-08-04 00:29:41 -05:00
Ed Page
6b3a5bde6d fix(parser)!: Split on value delimiter after validating num_args
This will allow `num_args(0..=1).value_delimiter(',')` to work properly.

This hacks in support for `require_value_delimiter` until we can remove
it.

This no longer recognzes value terminators in delimited lists.

It looks like there is a bug with recognizing value terminators in
positionals arguments.  We'll need to dig into that more.
2022-08-04 00:14:41 -05:00
Ed Page
b731b6a826
Merge pull request #4024 from epage/cleanup
refactor(parser): Prep for more #2688 work
2022-08-04 00:10:57 -05:00
Ed Page
53836f583c fixup! refactor(parser): Clarify where escaping is relevant 2022-08-03 23:53:33 -05:00
Ed Page
012de8daa2
Merge pull request #4023 from epage/num_args
fix!: num_args controls user args rather than parsed values
2022-08-03 23:49:44 -05:00
Ed Page
85ad452c9b fix!: Remove Arg::rwquire_value_delimiter
In clap v3, `require_value_delimiter` activated an alternative parse
mode where
- `multiple_values` meant "multiple values within a single arg"
- `number_of_values` having no parse impact, only validation impact
- `value_names` being delimited values

For unbounded `number_of_values`, this is exactly what `value_delimiter`
provides.  The only value is if someone wanted `value_name` to be
`<file1>,<file2>,...` which can be useful and we might look into adding
back in.

Alternatively, this could be used for cases like key-value pairs but
that has issues like not allowing the delimiter in the value which might
be ok in some cases but not others.  We already instead document that
people should instead use `ValueParser` for this case.

In removing this, we remove points of confusion at how the different
multiple values and delimited value calls interact with each other.  I
know I would set `require_value_delimiter(true).multiple_values(true)`
when it turns out all I needed was `value_delimiter(',')`.

This also reduces the API surface area which makes it easier to discover
what features we do provide.

While this isn't big, this is also yet another small step towards
reducing binary size and compile times.
2022-08-03 21:26:36 -05:00
Ed Page
69c4628b16 refactor(parser): Remove redundant code 2022-08-03 18:10:45 -05:00
Ed Page
deba6bdda5 refactor(parser): Clarify where escaping is relevant 2022-08-03 17:42:11 -05:00
Ed Page
e6577b284e fix(assert)!: Prevent require equal when it won't work 2022-08-03 17:41:47 -05:00
Ed Page
1352be3d88 fix(parser): Further limit num_args to user values 2022-08-03 17:41:47 -05:00
Ed Page
03f747ba8b fix(parser)!: Only apply num_args to user values 2022-08-03 17:41:42 -05:00
Ed Page
6dddf119ce fix!: num_args controls user args rather than parsed values
This mostly impacts use of delimiters.
2022-08-03 14:45:52 -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
3bcde19b18
Merge pull request #4022 from epage/delim
fix!: Remove Arg::use_value_delimiter in favor of Arg::value_delimiter
2022-08-03 14:38:19 -05:00
Ed Page
0664c6db37 fix!: Remove Arg::use_value_delimiter in favor of Arg::value_delimiter 2022-08-03 11:15:29 -05:00
Ed Page
fafb2d5763
Merge pull request #4020 from epage/mult
fix!: Replace multiple_values with number_of_values
2022-08-03 10:54:03 -05:00
Ed Page
f40447bc26
Merge pull request #4017 from dtolnay-contrib/delete
Delete seemingly stray cargo_example_derive file
2022-08-01 21:19:37 -05:00
David Tolnay
10137fbd33
chore: Delete seemingly stray cargo_example_derive file 2022-08-01 16:54:37 -07: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
8f6231010a
Merge pull request #4015 from epage/arg_enum
fix!: Remove rest of deprecated APIs
2022-08-01 15:34:41 -05:00
Ed Page
76bff6f34e fix!: Remove rest of deprecated APIs
Fixes #4009
2022-08-01 15:21:33 -05:00
Ed Page
686d174e28
Merge pull request #4014 from nt591/patch-1
[Documentation] fix typo in arg.rs
2022-08-01 11:57:25 -05:00
Nikhil Thomas
823e5664cd
[Documentation] fix typo in arg.rs 2022-08-01 12:55:04 -04:00
Ed Page
3ac2afd824
Merge pull request #4011 from clap-rs/dependabot/cargo/proc-macro2-1.0.42
chore(deps): bump proc-macro2 from 1.0.40 to 1.0.42
2022-08-01 09:23:56 -05:00
Ed Page
3d65d5701e
Merge pull request #4010 from clap-rs/dependabot/cargo/terminal_size-0.2.1
chore(deps): bump terminal_size from 0.1.17 to 0.2.1
2022-08-01 09:23:45 -05:00
dependabot[bot]
44350b376e
chore(deps): bump proc-macro2 from 1.0.40 to 1.0.42
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.40 to 1.0.42.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.40...1.0.42)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-01 07:04:51 +00:00
dependabot[bot]
0bf1627e05
chore(deps): bump terminal_size from 0.1.17 to 0.2.1
Bumps [terminal_size](https://github.com/eminence/terminal-size) from 0.1.17 to 0.2.1.
- [Release notes](https://github.com/eminence/terminal-size/releases)
- [Commits](https://github.com/eminence/terminal-size/compare/v0.1.17...v0.2.1)

---
updated-dependencies:
- dependency-name: terminal_size
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-01 07:04:43 +00:00
Ed Page
9037e93c72 docs: Update changelog 2022-07-29 20:55:02 -05:00
Ed Page
957709fe8a
Merge pull request #4005 from epage/error
fix(parser): Include required argument in message
2022-07-29 20:21:05 -05:00
Ed Page
40a9061c26 fix(parser): Include required argument in message
When suggesting required arguments, we wanted to avoid an argument
showing up in both a group and by itself but we didn't correctly
calculate that, causing no required arguments to show up at times.

Now, we all use the same pool of information for doing the calculations.

This was the type of cleanup that I expected it to drop our binary size
but this added 1k to our .text.  Strange.

Fixes #4004
2022-07-29 19:54:32 -05:00