Commit graph

4642 commits

Author SHA1 Message Date
Pavan Kumar Sunkara
cc2dddba8e Add DisableColoredHelp setting to improve flexibility (clap-rs/clap#2956)
Until we have a modular help generator that can be configured and/or
authored by the users themselves as part of #2914, we will provide the
flexibility of turning off colored help messages but still wanting
colored error messages.

This flexibility was available before #2845 and @dbrgn immediately
noticed it and requested it back to which I agree. This was also
suggested by Josh in
[here](https://github.com/clap-rs/clap/issues/2806#issuecomment-933877438)
2021-12-04 12:00:46 -06:00
Ed Page
f6635b0baa
Merge pull request #58 from epage/migrate
Help Users Migrate to clap3
2021-12-04 07:38:48 -06:00
Ed Page
951d1fc5c8 doc: Call out release highlights 2021-12-03 20:44:50 -06:00
Ed Page
d2af931c3d doc: Write up migration guide 2021-12-03 20:44:37 -06:00
Ed Page
0cd16c34fc feat: App::debug_assert test helper
This will especially be important for users migrating from clap2 so they
can catch problems earlier in the process.
2021-12-03 14:12:03 -06:00
Ed Page
f99f1fb2c7
Merge pull request #56 from epage/structopt
fix(derive): Smooth out transition for structopt
2021-12-02 21:19:03 -06:00
Ed Page
888c27048d docs: Update changelog 2021-12-02 20:26:21 -06:00
Ed Page
500def4904 fix(derive): Smooth out transition for structopt
Adding in a `StructOpt` derive with `structopt` attributes, with
deprecation notices.  Unofrtunately, not as many deprecation warnings as
I would like.  Apparently, you can't do them for a `use` of a derive?  I
also wanted to inject code that would trigger a deprecation notice for
attributes but that would require enough of a refactor that I didn't
consider it worth it.  We are at least providing a transition window
even if it means we'll have to remvoe it next major release without a
deprecation warning.
2021-12-02 20:18:33 -06:00
Ed Page
64d052f8b8 fix: Remove untested IntoApp derive 2021-12-02 20:01:00 -06:00
Ed Page
aeb295897d
Merge pull request #53 from epage/migrate
docs: Clean up 3.0 changelog
2021-12-02 18:10:32 -06:00
Ed Page
e751d5e372
Merge pull request #54 from epage/ui
test: Fix ui tests
2021-12-02 16:37:28 -06:00
Ed Page
75d417851b docs: Clean up 3.0 changelog 2021-12-02 16:07:43 -06:00
Ed Page
3f9da04744 fix: Revert as much yaml policy to v2 as possible 2021-12-02 16:06:21 -06:00
Ed Page
0294fd0170 revert: Bring back ArgSettings::Global
This is a partial revert of cacc23473.  It appears that the deprecation
of `ArgSettings::Global` was never followed through on.
2021-12-02 16:06:21 -06:00
Ed Page
c93809271c fix: Deprecate, rather than obsolete, some App functions 2021-12-02 16:06:21 -06:00
Ed Page
c8254918d6 fix: Add back arg_enum 2021-12-02 16:06:21 -06:00
Ed Page
e065d1dd79 fix: Fix deprecated function name 2021-12-02 16:06:21 -06:00
Ed Page
d876f306eb fix: Add back in write_version 2021-12-02 16:06:21 -06:00
Ed Page
216837d688 test: Fix ui tests 2021-12-02 15:58:42 -06:00
Ed Page
0d1f34b91d fix: Finish reverting clap_app 2021-12-02 10:45:10 -06:00
Ed Page
83abb24002 fix: Remove EmptyValues
The intention had been to that people setting this would now set
nothing.  Unfortunately, clap2 had `EmptyValues` as the default, so
people were more likely to unset it, making this not work out.
2021-12-02 09:59:41 -06:00
Ed Page
4e9e9514e1
Merge pull request #50 from epage/derive
docs: Add Derive API reference
2021-12-02 07:26:12 -06:00
Ed Page
27acb95cd9 docs: Add Derive API reference
I took more inspiration for organization from `serde.rs` than `docs.rs/structopt`.
2021-12-01 21:23:06 -06:00
Ed Page
7f8b1990bb docs: Iterate on examples from writing ref docs 2021-12-01 14:30:51 -06:00
Ed Page
e3c8050545
Merge pull request #49 from epage/fixes
Misc minor improvements
2021-12-01 07:31:12 -06:00
Ed Page
8bcca687ea chore: Remove redundant CI step 2021-12-01 07:17:12 -06:00
Ed Page
bbc1d6aff2 docs: Add more crates 2021-12-01 07:15:51 -06:00
Ed Page
204ea4781d
Merge pull request #48 from epage/examples
docs: Re-work examples
2021-12-01 07:07:31 -06:00
Ed Page
befee6667b docs: Re-work examples
This creates distinct tutorial examples from complex feature examples
(more how-tos).  Both sets are getting builder / derive versions (at
least the critical ones).
2021-11-30 21:33:52 -06:00
Ed Page
b5c66c2f99
Merge pull request #47 from epage/sep
fix: Change `app_from_crate` default separator
2021-11-30 15:11:23 -06:00
Ed Page
c59598479e Revert "docs(examples): De-duplicate subcommand examples"
This reverts commit bbe32b2667.
2021-11-30 14:56:32 -06:00
Ed Page
267de95bee fix: Change app_from_crate default separator
`":"` isn't ideal, so let's make it at least `"," `.

BREAKING CHANGE: Changed `app_from_crate!()` to use `", "` separator for
authors.
2021-11-30 14:56:17 -06:00
Ed Page
d45ed909f6
Merge pull request #46 from epage/test
tests: Consolidate clap tests
2021-11-30 12:21:56 -06:00
Ed Page
181eff5541 docs: Fix stale examples
These were broken in #17 and #38 when renaming `hidden` to `hide`.  These
weren't caught because we test with `--all-targets` which is mutually
exclusive with `--doc`.
2021-11-30 12:05:30 -06:00
Ed Page
b7d6ec67d9
Merge pull request #45 from epage/docs
docs: Focus top-level README
2021-11-30 10:07:45 -06:00
Ed Page
b190a6a817 test: Consolidate clap tests
This reduces the need for us to have `clap` as a dependency in
`clap_derive`, preparing the way to fix #15.
2021-11-30 10:07:08 -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
2288f55cc1 test: Rely on release process for version sync
When we switch to `cargo-release`, it will validate that the auto-update
was performed.  No reason to have an extra dependency during
development.
2021-11-30 09:59:59 -06:00
Ed Page
f890bfa93b docs: Focus top-level README 2021-11-30 09:53:25 -06:00
Ed Page
ea73ec521b
Merge pull request #44 from epage/examples
docs: Prefer `global_setting`
2021-11-29 16:40:20 -06:00
Ed Page
96da9cacb1
Merge pull request #43 from epage/placeholder
fix: Consistent help between Args and Subcommands
2021-11-29 16:27:58 -06:00
Ed Page
30f5872a71 fix: Consistent help between Args and Subcommands
`App::subcommand_placeholder` encompassed
- `Arg::value_name`
- `Arg::help_heading`

Split it and renamed it to make it more consistent.
2021-11-29 16:17:02 -06:00
Ed Page
54228ef7d7 docs: Prefer global_setting
I've been finding I've been setting `AppSettings` without it which is
likely leading to bugs.  This tries to raise the visibility by using it
based on the setting being used and not whether the application needs
it.
2021-11-29 16:10:54 -06:00
Ed Page
e1db873e2c
Merge pull request #41 from epage/utf8
fix: Detect when AllowInvalidUtf8 is needed
2021-11-29 15:53:26 -06:00
Ed Page
b8c34c3b57 fix: Detect when AllowInvalidUtf8 is needed
Fixes #36
2021-11-29 15:37:44 -06:00
Ed Page
c5f5c49766 refactor(parser): Use modern '?' 2021-11-29 14:20:25 -06:00
Ed Page
8a1099f921 refactor(parser): More context when creating a MatchedArg 2021-11-29 14:01:08 -06:00
Ed Page
211d36efad refactor(parser): Be consistent on terms 2021-11-29 14:01:02 -06:00
Ed Page
c7aa471deb
Merge pull request #40 from epage/derive_vec
fix(derive): Define multiple policy for Special Types
2021-11-29 13:33:05 -06:00
Ed Page
1cdb2250e8 fix(derive): Define multiple policy for Special Types
Before:
- `bool`: a flag
- `Option<_>`: not required
- `Option<Option<_>>` is not required and when it is present, the value
  is not required
- `Vec<_>`: multiple values, optional
- `Option<Vec<_>>`: multiple values, min values of 0, optional

After:
- `bool`: a flag
- `Option<_>`: not required
- `Option<Option<_>>` is not required and when it is present, the value
  is not required
- `Vec<_>`: multiple occurrences, optional
  - optional: `Vec` implies 0 or more, so should not imply required
- `Option<Vec<_>>`: multiple occurrences, optional
  - optional: Use over `Vec` to detect when no option being present when
    using multiple values

Motivations:

My priorities were:
1. Are we getting in the users way?
2. Does the API make sense?
3. Does the API encourage best practices?

I was originally concerned about the lack of composability with
`Option<Option<_>>` and `Option<Vec<_>>` (and eventually `Vec<Vec<_>>`).
It prescribes special meaning to each type depending on where it shows
up, rather than providing a single meaning for a type generally.  You
then can't do things like have `Option<_>` mean "required argument with
optional value" without hand constructing it.  However, in practice the
outer type correlates with the argument occurrence and the inner type
with the value.   It is rare to want the value behavior without also the
occurrence behavior.  So I figure it is probably fine as long as people
can set the flags to manually get the behavior they want.

`Vec<_>` implies multiple occurrences, rather than multiple values.
Anecdotally, whenever I've used the old `Arg::multiple`, I thought I was
getting `Arg::multiple_occurrences` only.  `Arg::multiple_values`,
without any bounds or delimiter requirement, can lead to a confusing
user experience and isn't a good default for these.  On top of that, if
someone does have an unbounded or a delimiter multiple values, they are
probably also using multiple occurrences.

`Vec<_>` is optional because a `Vec` implies 0 or more, so we stick to
the meaning of the rust type.  At least for me, I also rarely need a
required with multiple occurrences argument but more often need optional
with multiple occurrences.

`Option<Vec<_>>` ends up matching `Vec<_>` which can raise the question
of why have it.  Some users might prefer the type.  Otherwise, this is
so users can detect whether the argument is present or not when using
`min_values(0)`.  Rather than defining an entire policy around this and
having users customize it, or setting `min_values(0)` without the rest
of a default policy, this gives people a blank slate to work from.

Another design option would have been to not infer any special-type
settings if someone sets a handful of settings manually, which would
have avoided the confusion in Issue clap-rs/clap 2599 but I see that
being confusing (for someone who knows the default, they will be
expecting it to be additive; which flags disable inferred settings?) and
brittle (as flags are added or changed, how do we ensure we keep this
up?).

Tests were added to ensure we support people customizing the behavior to
match their needs.

This is not solving:
- `Vec<Vec<_>>`, see clap-rs/clap 2924
- `(T1, T2)`, `Vec<(T1, T2)>`, etc, see clap-rs/clap 1717
- `Vec<Option<_>>` and many other potential combinations

Fixes clap-rs/clap 1772
Fixes clap-rs/clap 2599
See also clap-rs/clap 2195
2021-11-29 13:16:12 -06:00