Commit graph

227 commits

Author SHA1 Message Date
Pavan Kumar Sunkara
6ae804d084
Merge pull request #3082 from epage/fixes
Misc fixes from clapng fork review
2021-12-08 04:08:49 +00:00
Ed Page
76828fada8 docs: Guide people to missing_docs lint 2021-12-07 21:22:12 -06:00
Ed Page
8708c54e5a
Merge pull request #3081 from clap-rs/pksunkara-patch-1
docs: Link correct example
2021-12-07 21:11:07 -06:00
Pavan Kumar Sunkara
c98d8aac13
docs: Link correct example 2021-12-08 01:27:18 +00:00
Ed Page
c99adcc6c9 docs: Add key-value derive example
This is carried over from the clap_derive examples.  Looking over the
other examples, I feel like they are covered by other examples or by the
derive reference.  We should call out deny missing docs though.
2021-12-07 19:01:55 -06:00
Ed Page
55186f5aa3 docs: Highlight subxcommand help heading 2021-12-07 17:45:57 -06:00
Ed Page
92750c6aa5 docs: Simplify demo 2021-12-07 17:45:57 -06:00
Ed Page
6da9277522 docs(derive): Note Option Vec behavior 2021-12-07 17:45:57 -06:00
Ed Page
b2836c07a7 fix: Gracefully handle empty authors 2021-12-06 11:30:26 -06:00
Ed Page
f517c0ede1 docs: Remove author fields 2021-12-06 11:24:23 -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
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
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
f890bfa93b docs: Focus top-level README 2021-11-30 09:53:25 -06:00
Ed Page
9c4194a5a1 test: Verify examples based on feature flags 2021-11-23 17:10:01 -06:00
Ed Page
bfa02fd418 test: More thoroughly test examples
This ports our example testing over to [trycmd](https://docs.rs/) so
we can:
- More thoroughly test our examples
- Provide always-up-to-date example usage

The old way of testing automatically picked up examples.  This new way
requires we have a `.md` file that uses the example in some way.

Notes:
- Moved overall example description to the `.md` file
- I added cross-linking between related examples
- `14_groups` had a redundant paragraph (twice talked about "one and
  only one"
2021-11-23 13:13:41 -06:00
Ed Page
4c4a2b86a0 refactor: Port over to arg! 2021-11-23 09:37:14 -06:00
Ed Page
6ce9714e2b fix: Deprecate YAML API
Fixes #9
2021-11-22 16:17:46 -06:00
Ed Page
88fff13e71 Revert rename of from_yaml / from_usage
Since usage parser and yaml are on the way to being deprecated (#8, #9),
doing a rename also seems excessive, so rolling it back.

Past relevant PRs:
- clap-rs/clap#1157
- clap-rs/clap#1257
2021-11-22 16:17:46 -06:00
Ed Page
7e899cd340 Revert "Deprecate Arg::help in favour of Arg::about"
This reverts commits 24cb8b1..d0abb37 from clap-rs/clap#1840

This is part of #16.  clap-rs/clap#1840 wasn't the right call but we
don't have time to make the decision now, so instead of having one
option and changing it in 4.0, this reverts back to clap2 behavior.
2021-11-18 12:25:49 -06:00
Ed Page
bbe32b2667 docs(examples): De-duplicate subcommand examples
Not seeing what this example adds over the other ones.  We've already
shown subcommands and shown that `App` has extra behavior for when
definint subcommands.
2021-11-17 15:23:31 -06:00
Ed Page
2ac2fc6005 docs(examples): Be explicit in multicall for what clap does
This better matches our other examples
2021-11-17 15:23:31 -06:00
Ed Page
3be8bcf756 docs(examples): Move unwrap comments to expect statements
This better models what users should be doing and makes it so all
comments are more clear.  In a prior commit, when a changed an `exit` to
`unwrap`, I disliked the fact that I was mixing an unwrap explanatory
comment in with another comment.  This makes them stand apart.
2021-11-17 15:23:31 -06:00
Ed Page
41d3b8f164 docs(examples): Remove unnecessary error check
Rather not confuse the point for users.
2021-11-17 15:23:31 -06:00
Ed Page
7763a7c52a docs(examples): Focus subcommands on main call
The subcommand examples focus on the various ways of looking up
subcommands except for the main one people should be using.   This has
previously caused confusion, see https://github.com/clap-rs/clap/discussions/3000

To keep the examples focused, I only show `ArgMatches::subcommand`.  I
figure the examples are not exhaustive and that for the cases when
someone wants to do something more specialized, they can pull up the
API reference.
2021-11-17 15:23:31 -06:00
Ed Page
93948cc724 docs(examples): Work around non-commutative conflicts
The comments in these examples say that a `conflicts_with` should
override `required`.  This seems to be true one way but not the other,
causing these examples to error out at runtime.
2021-11-17 15:23:31 -06:00
Ed Page
4eba65bfaf docs(examples): Don't use is_present with subcommands
Apparently, this isn't supported anymore.
2021-11-17 15:23:31 -06:00
Ed Page
1f0d86a407 docs(examples): Highlight possible-values in help
Instead of showing the user how to do things manually, let's make the
contrast in `--help` more obvious by not manually listing the possible
values.
2021-11-17 15:23:31 -06:00
Ed Page
6fc9c7cff4 docs(examples): Be consistent in define and read order
This threw me off because the arguments are so similar, I kept relying
on the order but they were swapped.
2021-11-17 15:23:31 -06:00
Ed Page
cdc5026410 docs(examples): Use correct arg keys 2021-11-17 15:23:31 -06:00
Ed Page
7c24e937f8 docs(examples): Provide visual indication of user choice 2021-11-17 15:23:31 -06:00
Ed Page
74d41b6f52 docs(examples): Don't crash when subcommand isn't provided 2021-11-17 15:23:31 -06:00
Ed Page
0a4a2dd36b docs(examples): Provide app_from_crate! example
This consolidates two `crate_*!` macro examples into a `app_from_crate`
example.

- This is more of what we expect users to use
- We've talked about splitting the `crate_*` macros out into their own
  crate.  This shifts the focus to what clap would be providing long
  term
2021-11-17 15:23:31 -06:00
Ed Page
535d663dfc docs(examples): Align quick_examples
`01b` doesn't require `output`, so updating `01a` to match
2021-11-17 15:23:31 -06:00
Ed Page
2df043655f docs(examples): Remove reference to non-existent example 2021-11-17 15:23:31 -06:00
Ed Page
7a59dc3da4 Revert "Automatically read license field from Cargo.toml"
This reverts commit 6898fbde33.

PR #2144 added the `license` field but no consumer has been added since
the (like Issue #1768).  Since this is not ready yet, I am pulling it
from the 3.0 release.

So far, our main route for pulling a feature from the release has
been to put it behind a `unstable-*` feature flag and to create a
stablization tracking issue.  I chose to instead remove the feature
because a write-only field with no effect does not provide values for
people to use in as an early access and so doesn't outweight the cost of
the extra documentation noise and code noise it creates.  Additionally,
keeping an `unstable-` feature around when it has such an unknown path
(and time table) to stalbization feels like it violates YAGNI.  I'm
uncertain how much of this feature we can implement and not create a
legal trap for users because the crate's license is insufficient for the
final artifact's license.  I feel our stabliazation process sshould be
about iteration and collecting user feedback which this doesn't line up
with.

When someone is ready to tackle #1768, it will be easy to revert this
commit and pick up the work again.

Fixes #3001
2021-11-12 09:55:37 -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
bors[bot]
b835ce9061
Merge #2817
2817: Add support for Multicall executables as subcommands with a Multicall setting r=pksunkara a=fishface60



Co-authored-by: Richard Maw <richard.maw@gmail.com>
2021-10-16 00:32:52 +00:00
Richard Maw
636ecaffa2 fixup! make new tests compile but not run without unstable-multicall 2021-10-15 20:59:33 +01:00
Ed Page
59497629e8 docs: Encourage multiple_occurrences
There were fewer occasions than I expected where the use of
`multiple_values` was superfluous and we could instead use the more
predictable `multiple_occurrences`.

In terms of the remaining `multiple` split work, #1772 will take care of the derive
behavior and #2692 will resolve any remaining issues with values vs
occurrences in positional arguments.

Fixes #2816
2021-10-15 11:41:40 -05:00
Richard Maw
694329b363 fixup! Make hostname a non-derive example and rename via Cargo.toml 2021-10-12 22:38:43 +01:00
Richard Maw
a31d3b288d fixup! Revert: Make hostname a non-derive example and rename via Cargo.toml
tests/examples.rs:examples_are_functional finds examples by stripping
`.rs` off the basename
2021-10-12 20:01:59 +01:00
Richard Maw
1782f9d4ec fixup! Make hostname a non-derive example and rename via Cargo.toml 2021-10-12 19:57:32 +01:00
Richard Maw
971b6b683e fixup! Move explanatory text from examples to docstring 2021-10-11 22:08:51 +01:00
Ed Page
0a53fafddf fix: Deprecate Macro API
Fixes #2835
2021-10-11 15:06:38 -05:00
Richard Maw
1ba4b98b8e fixup! trim hardlink implementation from busybox example 2021-10-11 20:51:33 +01:00
Richard Maw
f14db03eec Add Multicall setting
If the AppSettings::Multicall setting is given
then argv0 is parsed as the first subcommand argument
or parsed as normal with any other name.
2021-10-11 20:00:24 +01:00
Roland Fredenhagen
5580e8c465
ArgValue builder (#2758)
* feat(arg_value): ArgValue can be used for possible_values

Through the ArgValue it is possible:

* `hide` possible_values from showing in completion, help and validation
* add `about` to possible_values in completion

* Resolved a few change-requests by epage

* make clippy happy

* add ArgValue::get_visible_value

* remove verbose destructering

* rename ArgValue::get_hidden to ArgValue::is_hidden

* add test for help output of hidden ArgValues

* Documentation for ArgValue

There is an issue that required to implement From<&ArgValue> for
ArgValue. We should probably find a solution without that.

* fix requested changes by epage

* fix formatting

* add deref in possible_values call to remove From<&&str>

* make clippy happy

* use copied() instad of map(|v|*v)

* Finishing up for merge, hopefully

* changes requested by pksunkara
2021-09-19 10:29:09 +00:00
rami3l
44ae55fa4e docs(example): clarify stop_parsing_with_-- 2021-08-03 13:41:54 +02:00
rami3l
d7c984896d fix(style): remove unnecessary usages of 'static and ref 2021-08-02 23:05:21 +02:00
Ed Page
c27b2e299c fix(example): Use correct type in comment
Fixes #2631
2021-07-28 10:34:48 -05:00
Pavan Kumar Sunkara
3f94d17c71 Removed Arg::multiple 2021-06-16 07:17:11 +01:00
Tshepang Lekhonkhobe
f8a55930b7
Update examples/18_builder_macro.rs
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-06-12 22:27:27 +02:00
Tshepang Lekhonkhobe
7d9d6f3e51
Update examples/08_subcommands.rs
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2021-06-12 22:25:56 +02:00
Tshepang Lekhonkhobe
661024a521 the word "Subcommand" was accidentally removed
Was done in 03333800fe
2021-06-11 22:41:37 +02:00
Pavan Kumar Sunkara
82e42cd07e Ignore extra fields in YAML only when specified 2021-06-01 21:59:44 +01:00
Nick Zana
a637d96d82
Fix minor typos in 10_default_values.rs 2021-04-01 17:41:17 -04:00
ldm0
886b873709 Demangle interlinking flags 2021-03-09 13:45:11 +00:00
Pavan Kumar Sunkara
6634444c3c Remove Arg::settings to be consistent with App 2021-02-12 10:42:38 +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
Robin Moussu
6898fbde33 Automatically read license field from Cargo.toml 2020-12-09 00:16:19 +01:00
Derek Mahar
ee76fbf3c5 Make debug option in example 01a_quick_example follow specification. 2020-09-18 12:02:03 -04:00
Derek Mahar
2b369b2ccd Modify debug option to conform to specification. 2020-09-16 21:37:58 -04:00
Matt Kantor
b41384d320 Make all examples compile & run without failure. 2020-08-23 11:23:43 -07:00
CreepySkeleton
0b2eac4da7 Fix yaml support 2020-08-15 23:42:23 +03:00
CreepySkeleton
e9759a241b Adjust examples and tests 2020-08-05 17:07:13 +03:00
João Marcos
24760bc261 style: replacing yml with yaml for consistency 2020-07-20 20:58:34 -03: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
NickHackman
21436398a2 docs: improved flag subcommand documentation
Improved documentation in flag subcommand example and in
`App::short_flag` and `App::long_flag` method documentation.
2020-07-16 17:48:00 -04:00
NickHackman
8a68f99750 example: more pacman-like and refractor
Removed user facing panics and improved ergonomics to behave more like
pacman behaves.
2020-07-07 21:26:38 -04:00
NickHackman
806d7487c6 example: updated 23 docs & refractor
Improved printing instead of printing out the `Vec` using `{:?}`,
`join(", ")` for improved printing. Improved documentation to b emore
explicit and apply to removal of `FlagSubCommand` -> `App::short_flag`
and `App::long_flag`
2020-06-16 20:01:19 -04:00
NickHackman
458736bee8 imp: Improved Flag Subcommand API
Instead of a `FlagSubCommand` struct the addition of two simple methods
to `App`. `App::long_flag` and `App::short_flag` that cover all the
bases of the many methods that were provided in `FlagSubCommand`. This
API is far simpler to use and more akin to the present `Arg::long` and `Arg::short`.
2020-06-15 21:52:36 -04:00
NickHackman
50829711ef examples: FlagSubCommand pacman
Using `pacman` as an example for `FlagSubCommand` because of #1361
2020-06-13 12:32:17 -04:00
Gonçalo Ribeiro
fb8e0d815d docs: correct some typos 2020-05-30 11:14:47 +01:00
Pavan Kumar Sunkara
7bc282dd4e Rename with_name to new for Arg & ArgGroup 2020-05-14 22:50:56 +02:00
kevinlmadison
195b6cb245 fix typo in example 04_using_matches.rs 2020-05-12 00:30:03 +02:00
CreepySkeleton
56fdfb9edd Eradicate warnings and errors: tests and examples 2020-05-02 23:33:47 +03:00
CreepySkeleton
ec6b6e1e36 Make validator take &str instead of String 2020-05-01 14:21:11 +03:00
creativcoder
92d5920748 Updated test and usage of older help APIs with about 2020-04-27 02:42:07 +05:30
Pavan Kumar Sunkara
dbe6ac01f6 Clean up arg_enum 2020-04-22 14:38:16 +02:00
CreepySkeleton
af95c2b6a4 Replace value_t*! macros with methods 2020-04-13 04:20:09 +03:00
CreepySkeleton
5d9ef1527f Fix warnings in tests & examples 2020-03-05 13:40:25 +03: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
Pavan Kumar Sunkara
5b3a0dff9c Remove extern & macro_use where possible 2020-02-07 07:34:01 +01: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
Alex van de Sandt
050bb7484a Fix formatting 2020-02-03 13:04:07 -05:00
Alex van de Sandt
e068826e62 Remove mention of macro_use in doc comment 2020-02-03 12:01:36 -05:00
Alex van de Sandt
81b8bdd7fc Remove #[macro_use] from examples 2020-02-03 12:01:36 -05:00
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
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
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
fvkramer
4e1da91fb1
examples: Change flag arg to option arg
Comments in 04_using_matches.rs list the config arg
as an optional arg. However, -c --config is currently
a flag arg. This commit sets takes_value to true on
the config arg to make it an "option" argument.
2019-10-29 21:45:58 -04:00
Dylan DPC
ee808f464f
Update 17_yaml.yml 2019-07-25 12:14:05 +02:00
Erick Tryzelaar
4a20c6aaef Fix compiling with "--features yaml" 2019-06-19 16:32:52 -07:00
Kevin K
fcbae1574a
style: rustfmt run 2019-04-05 20:21:33 -04:00
Kevin K
20c72525d2 style: cargo fmt run 2018-11-14 12:05:06 -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
andrewmiller1
78886f917d update yaml example comments 2018-11-04 19:11:48 -06:00