Commit graph

290 commits

Author SHA1 Message Date
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
ff476660ce test: Compile example in README 2021-11-17 21:01:56 -06:00
Ed Page
cebbb5c40e chore: Silence bad clippy lint
While in some cases "branches-sharing-code" might catch bugs, it overall encourages a form
of DRY that leads to bad code.  In this specific case, it is relying on
the implementation detail of the formatting of each branch being the
same.  If the `'` wasn't part of it, I could see it being about a shared
`?` to go with the shared start of the question.
2021-10-23 10:06:38 -05:00
Ed Page
9f12bfec47 fix!: Rename ArgValue to PossibleValue
In considering potential work for #2683, I realized we might need a type to carry data for
each of the `multiple_values`.  `ArgValue` works both for that and for
possible values, so we need to come up with a better name for one or
both.  Changing `ArgValue`s name now would be ideal since its new in
clap3 and by renaming it, we can reduce churn for users.

While thinking about this, I realized I regularly get these mixed
up, so renaming `ArgValue` to `PossibleValue` I think will help clear
things up, regardless of #2683.
2021-10-19 10:10:37 -05:00
Pavan Kumar Sunkara
585e995811 Release 3.0.0-beta.5 2021-10-17 17:01:18 +01:00
Ed Page
a43da7ca61 fix: Ease clap2->clap3 migration with deprecations
- `App::with_defaults` was not included since that has been deprecated
  since 2.14
- `App::args_from_usage` does not have a close enough parallel in the
  new API, as far as I could tell
- `ArgMatches::usage` cannot have a thin wrapper around
  `App::generate_usage`.
- `App::write_*`: getting lazy, didn't seem like high value functions
- Any `Settings` (some things need to be figured out here)

This is a part of #2617
2021-10-15 14:19:16 -05:00
Pavan Kumar Sunkara
efeb02cd34 fix!: Make color settings an enum 2021-10-13 13:54:44 +01:00
Ed Page
35d53d9dcf feat(generate): 'impl ArgEnum for Shell'
These keeps `FromStr` for ease of use with `value_of_t`.

This includes adding test to make sure everything works as expected.
2021-10-11 10:44:48 -05:00
Ed Page
d840d5650e fix(derive)!: Rename Clap to Parser.
Before #2005, `Clap` was a special trait that derived all clap traits it
detected were relevant (including an enum getting both `ArgEnum`,
`Clap`, and `Subcommand`).  Now, we have elevated `Clap`, `Args`,
`Subcommand`, and `ArgEnum` to be user facing but the name `Clap` isn't
very descriptive.

This also helps further clarify the relationships so a crate providing
an item to be `#[clap(flatten)]` or `#[clap(subcommand)]` is more likely
to choose the needed trait to derive.

Also, my proposed fix fo #2785 includes making `App` attributes almost
exclusively for `Clap`.  Clarifying the names/roles will help
communicate this.

For prior discussion, see #2583
2021-10-09 20:12:03 -05:00
Pavan Kumar Sunkara
699a3f76d6 Implement BitOr for settings 2021-09-23 14:57:10 +05:30
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
Pavan Kumar Sunkara
52be134949 Release 3.0.0-beta.4
clap@3.0.0-beta.4
clap_derive@3.0.0-beta.4
clap_generate@3.0.0-beta.4

Generated by cargo-workspaces
2021-08-14 23:40:49 +01:00
Pavan Kumar Sunkara
73b28fb104 Release 3.0.0-beta.3
clap@3.0.0-beta.3
clap_derive@3.0.0-beta.3
clap_generate@3.0.0-beta.3

Generated by cargo-workspaces
2021-08-14 23:01:13 +01:00
Pavan Kumar Sunkara
6994be4f15 Remove doc feature 2021-07-30 22:49:11 +01:00
Ed Page
241d183b9c Bump MSRV to 1.54.0
- This makes it so `doc` compiles on stable

Fixes #2618
2021-07-30 10:19:21 +01:00
Ed Page
7f08773a5a fix(derive)!: Compile-error on nested subcommands
Before, partial command lines would panic at runtime.  Now it'll be a
compile error

For example:
```
pub enum Opt {
  Daemon(DaemonCommand),
}

pub enum DaemonCommand {
  Start,
  Stop,
}
```

Gives:
```
error[E0277]: the trait bound `DaemonCommand: clap::Args` is not satisfied
   --> clap_derive/tests/subcommands.rs:297:16
    |
297 |         Daemon(DaemonCommand),
    |                ^^^^^^^^^^^^^ the trait `clap::Args` is not implemented for `DaemonCommand`
    |
    = note: required by `augment_args`
```

To nest this, you currently need `enum -> struct -> enum`.  A later
change will make it so you can use the `subcommand` attribute within
enums to cover this case.

This is a part of #2005
2021-07-15 11:45:13 -05:00
Tshepang Lekhonkhobe
f5758034f0 fix a bunch of intra-doc links 2021-07-03 23:59:46 +02:00
Pavan Kumar Sunkara
373ded784c Fix clippy lint 2021-06-17 19:19:56 +01:00
Pavan Kumar Sunkara
3c9cc0cf91 Specify dep patch versions 2021-04-11 10:38:13 +01:00
Pavan Kumar Sunkara
1bd902370a Add tests for mut_arg on help and version 2021-02-07 15:54:24 +00:00
Pavan Kumar Sunkara
99b8830d0b Remove unneeded cfg_attr 2020-09-24 13:51:02 +02:00
Pavan Kumar Sunkara
d881a1185b Release 3.0.0-beta.2
clap@3.0.0-beta.2
clap_derive@3.0.0-beta.2
clap_generate@3.0.0-beta.2

Generated by cargo-workspaces
2020-09-18 20:32:41 +02:00
Benjamin Kästner
cde1a2d218 regex: Introduce convenience Cow-wrapper RegexRef
As previously discussed on [GitHub], this commit introduces a Cow-like
wrapper RegexRef to enable both `Regex` as well as `&Regex` as
arguments.

It also introduces a new module in the `build:arg` path to remove
clutter from the main module. For more information see #2073.

 [GitHub]: https://github.com/clap-rs/clap/pull/2073#issuecomment-674442310
2020-08-26 17:54:54 +02:00
CreepySkeleton
fd1ee7872e Make caching in crate_authors! actually work 2020-08-21 08:21:21 +03:00
aspen
96b7fd454b
Forbid all unsafe code. 2020-08-20 18:38:40 -04:00
Pavan Kumar Sunkara
5c0947f160 Add derive traits only if derive feature is enabled 2020-08-11 16:30:02 +02:00
Marti Raudsepp
64ee0f8009 Add hinting of arg value types for zsh/fish completion
Adds new method/attribute `Arg::value_hint`, taking a `ValueHint` enum
as argument. The hint can denote accepted values, for example: paths,
usernames, hostnames, commands, etc.

This initial implementation supports hints for the zsh and fish
completion generators, support for other shells can be added later.
2020-08-06 22:17:31 +03:00
CreepySkeleton
24ed93daae Reexport Indices 2020-06-09 08:39:07 +03:00
bors[bot]
961ed9cfdd
Merge #1931
1931: Allow separate derives, but do not give examples r=CreepySkeleton a=pksunkara



Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-05-16 02:18:48 +00:00
Pavan Kumar Sunkara
aab2e41f8a Consistent From<Yaml> for ArgGroup 2020-05-15 13:59:31 +02:00
Pavan Kumar Sunkara
fe52d77f4e Allow separate derives, but do not give examples 2020-05-15 09:51:42 +02:00
Pavan Kumar Sunkara
cc32c03055 Minor fix for the README 2020-05-11 11:15:59 +02:00
Pavan Kumar Sunkara
a67d1d7a40 Update README for beta release 2020-05-02 22:27:42 +02:00
CreepySkeleton
7a7148d087 Make struct SubCommand private 2020-04-29 21:34:59 +03:00
CreepySkeleton
c6fdd3a7ce Reshape imports 2020-04-27 21:47:08 +03:00
CreepySkeleton
739e7048a5 Make vec_map required dependency - in fact, it already is 2020-04-24 15:33:11 +03:00
Pavan Kumar Sunkara
01c179f527 Added arg_enum support 2020-04-22 14:37:45 +02:00
Stephan Boyer
606d120d18 Update the documentation regarding which features are enabled by default 2020-04-04 13:16:30 -07:00
CreepySkeleton
4fc4a00b8f Remove _some_ of pubs 2020-03-19 10:17:52 +03:00
Pavan Kumar Sunkara
b8851a7d5e Allow replacing input on the fly 2020-02-21 18:15:33 +01:00
CreepySkeleton
ae574df2f9
Extract subcommands into separate trait 2020-02-12 23:15:05 +03:00
bors[bot]
ad5606b5a0
Merge #1678
1678: Refactor clap_generate r=CreepySkeleton a=pksunkara

I have copied the code from [clap_generate]( https://github.com/clap-rs/clap_generate) and refactored the structure a bit.

This new structure will allow people to write their own generators using our `Generator` trait which will contain some helpers (Still working on polishing them).

Co-authored-by: Ole Martin Ruud <barskern@outlook.com>
Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-02-08 15:00:50 +00:00
Pavan Kumar Sunkara
33f47acc67 Refactor clap_generate 2020-02-07 07:52:04 +01:00
Pavan Kumar Sunkara
5b3a0dff9c Remove extern & macro_use where possible 2020-02-07 07:34:01 +01:00
CreepySkeleton
cf11d46373 Default value for default_value (yeah, sounds awkward) 2020-02-04 11:40:01 +03:00
Dylan DPC
922a531fa6
Update lib.rs 2020-02-02 02:02:10 +01:00
Pavan Kumar Sunkara
c799e8d0ca chore: Updated contributing instructions and justfile 2020-01-31 18:37:56 +01: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
dylan_DPC
1c79bb5b28 fix subcommand is private bug 2020-01-01 23:28:06 +05:30
Dylan DPC
335f34bee2 fix broken CI 2019-11-11 14:28:30 +01:00
Dylan DPC
dd6c8e08ad use 2018 edition and minor refactors 2019-11-11 12:54:55 +01:00
Za Wilcox
14bfbd6ef4
add missing 'the' 2019-10-29 21:47:42 -04:00
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
Kevin K
958437661a
chore: clippy fixes 2019-04-05 20:21:34 -04:00
Kevin K
fcbae1574a
style: rustfmt run 2019-04-05 20:21:33 -04:00
Kevin K
573b0a9e88
chore: upgrades to 2018 edition of Rust 2019-04-05 20:21:30 -04:00
Kevin K
4cc85990fd
refactor: removed strings as an internal ID for arguments, groups, and
subcommands

This commit changes the internal ID to a u64 which will allow for
greater optimizations down the road. In addition, it lays the ground
work for allowing users to use things like enum variants as argument
keys instead of strings.

The only downside is each key needs to be hashed (the implementation
used is an FNV hasher for performance). However, the performance gains
in faster iteration, comparison, etc. should easily outweigh the single
hash of each argument.

Another benefit of if this commit is the removal of several lifetime
parameters, as it stands Arg and App now only have a single lifetime
parameter, and ArgMatches and ArgGroup have no lifetime parameter.
2019-04-05 20:21:22 -04:00
Kevin K
3dffd4908c
Removing the lint features and invoking cargo clippy manually instead 2019-04-04 13:27:08 -04:00
Kevin K
eafee3c5c1 style: cargo fmt run 2018-11-14 14:01:48 -05:00
Kevin K
2a480451d3 refactor: clippy run 2018-11-14 14:01:48 -05:00
Kevin K
0de9e07412
Merge branch 'v3-master' into map 2018-11-13 22:07:16 -05:00
Kevin K
3550066c88 refactor: cleans out deprecated code in prep for final beta.1 push 2018-11-08 20:34:13 -05:00
Kevin K
03333800fe refactor: remove code going to other crates and deprecations 2018-10-19 23:31:06 -04:00
Alena Yuryeva
272170e333
WIP 2018-08-04 18:32:08 -04:00
Alena Yuryeva
f230cfedc3
WIP 2018-08-04 18:26:33 -04:00
Alena Yuryeva
7e5a6935b9
WIP. Big reformat 2018-08-04 18:22:10 -04:00
Alena Yuryeva
3efcf3ae03
WIP changing macros into MKeyMap calls 2018-08-04 18:13:33 -04:00
Kevin K
94872e00a5
refactor(Arg): changes Arg::short to accept a char instead of &str
Closes #1303
2018-07-23 15:10:12 -04:00
Kevin K
53b2ca51f4
refactor(Derives): changes the derive traits for the clap_derive crate 2018-07-13 11:36:53 -04:00
Kevin K
09de35f208 Fix some broken doc links and formatting. 2018-06-30 19:33:34 -04:00
Alan K
4492aa5b96 refactor: Changed the custom derive traits 2018-06-30 18:19:29 +02:00
Kevin K
e5def030d3
refactor(Modules): moves the modules around into a more logical order to make contribution easier 2018-06-12 11:44:40 -04:00
Kevin K
b033bb5abc
chore: ordermap to indexmap 2018-06-12 10:22:18 -04:00
andy boot
a4d080370c fix typo 2018-03-19 16:48:01 -04:00
Kevin K
6971624428
imp(Deps): doesnt compile ansi_term on Windows since its not used
Before this commit, ansi_term was compiled anytime the `color` feature
was used. However, on Windows the `color` feature is ignored. Even so
ansi_term was compiled, and just not used. This commit fixes that by
only compiling ansi_term on non-Windows targets. Thanks to @retep998 for
the gudiance.

Closes #1155
2018-02-13 15:43:45 -05:00
Kevin K
300a059f51
chore: updates the version tests 2018-02-03 15:22:56 -05:00
Kevin K
6fc70d825c
depr(Arg.rs): adds deprecations in prep for v3
A full list of deprecations is:

* Arg::last -> ArgSettings::Last
* Arg::required -> ArgSettings::Required
* Arg::require_equals -> ArgSettings::RequireEquals
* Arg::allow_hyphen_values -> ArgSettings::AllowHyphenValues
* Arg::takes_value -> ArgSettings::TakesValue
* Arg::hide_possible_values -> ArgSettings::HidePossibleValues
* Arg::hide_default_value -> ArgSettings::HideDefaultValue
* Arg::multiple -> ArgSettings::Multiple (see Arg::multiple split)
* Arg::multiple -> ArgSettings::MultipleValues (see Arg::multiple split)
* Arg::multiple -> ArgSettings::MultipleOccurrences (see Arg::multiple split)
* Arg::global -> ArgSettings::Global
* Arg::empty_values -> ArgSettings::AllowEmptyValues
* Arg::hidden -> ArgSettings::Hidden
* Arg::case_insensitive -> ArgSettings::IgnoreCase
* Arg::use_delimiter -> ArgSettings::UseDelimiter
* Arg::require_delimiter -> ArgSettings::RequireDelimiter
* Arg::hide_env_values -> ArgSettings::HideEnvValues
* Arg::next_line_help -> ArgSettings::NextLineHelp
* Arg::set -> Arg::unset_setting (consistent naming with App)
* Arg::unset -> Arg::setting (consistent naming with App)

Relates to #1037
2018-02-03 15:00:55 -05:00
Kevin K
1fa4afa45d
tests: continues to update tests to take advantage of new internals 2018-01-25 22:54:05 -05:00
Kevin K
7673dfc085
perf: refactors the POSIX override handling to lazy handling
This commit primarily changes to a lazy handling of POSIX overrides by
relying on github.com/bluss/ordermap instead of the old HashMap impl.
The ordermap allows us to keep track of which arguments arrived first,
and therefore determine which ones should be removed when an override
conflict is found.

This has the added benefit of we no longer have to do the bookkeeping to
keep track and override args as they come in, we can do it once at the
end.

Finally, ordermap allows fast Vec like iteration of the keys, which we
end up doing several times. Benching is still TBD once the v3 prep is
done, but this change should have a meaningful impact.
2018-01-25 15:08:57 -05:00
Kevin K
1ab10275e4
style: rustfmt run 2018-01-25 12:21:17 -05:00
Kevin K
5bb926ebf9 chore: fix html_doc_root 2018-01-18 15:06:23 -05:00
Kevin K
3e97085e58 chore: udpates html doc root 2018-01-09 12:02:35 -05:00
Cameron Dershem
56e734b839 docs: fixes broken links.
Small correction to add a link to the source in the documentation, previously
it was a placeholder.

`rustdoc` does not appear to package assets with the docs, therefore
relative links looking for static files do not work. The links are
consistent enough on github that the static files can be directly linked
to on the master branch.
2017-12-27 00:00:06 -05:00
Kevin K
e962f2cece
chore: increase version 2017-12-02 15:34:02 -05:00
Kevin K
8c0cc5c386
style: rustfmt run 2017-11-28 08:57:04 -05:00
Kevin K
ce6ca492c7
docs: changes the demo version to 2.28 to stay in sync 2017-11-28 04:38:37 -05:00
Kevin K
6f4c341241
api: Adds the traits to be used with the clap-derive crate to be able to use Custom Derive
Currently to use these traits clap must be built with the `unstable` feature. This does not
require a nightly compiler. These traits and APIs may change without warning (hence the `unstable`
feature flag). Once they have been stablelized and the `clap-derive` crate is released the
`unstable` feature flag will no longer be required.
2017-11-27 09:55:52 -05:00
Bastien Orivel
a6593410c1 Update bitflags to 1.0 and bump version 2017-11-21 12:39:12 +01:00
Kevin K
67170a8bd7
chore: increase version 2017-10-26 10:09:48 -04:00
Kevin K
0246960bdc
chore: adds term_size as an optional dep 2017-10-26 09:40:21 -04:00
Kevin K
3a471b72ce
docs: fixes some typo mistakes 2017-10-24 20:30:11 -04:00
Kevin K
48e0529bcd
chore: clippy run 2017-10-23 23:03:40 -04:00
Árpád Goretity
ac97edde90 Reorganize optionally depending on term_width 2017-10-06 13:14:01 +02:00
Kevin K
3224e2e1cd Merge pull request #1051 from malbarbo/master
make vec_map optional
2017-10-03 21:49:01 -04:00
Martin Geisler
e67a061bcf docs: add html_root_url attribute
This doc attribute is used by rustdoc when generating documentation
for other crates that depend on this crate. With the html_root_url,
rustdoc will be able to generate correct links into this crate.

See C-HTML-ROOT in the Rust API Guidelines for more information:
https://rust-lang-nursery.github.io/api-guidelines/documentation.html#crate-sets-html_root_url-attribute-c-html-root

A version-sync check was added to ensure that the URL is kept up to
date when the crate version changes.
2017-09-23 12:50:21 +02:00
Marco A L Barbosa
7b2aacde08 make vec_map optional 2017-09-19 15:21:58 -03:00
Kevin K
a8257ea0ff
fix(Help Message): fixes long_about not being usable
Closes #1043
2017-09-13 11:41:25 -07:00
Corentin Henry
2f0e511ab6 clippy doc_markdown 2017-06-12 07:53:55 -07:00
Martin Geisler
b93870c10a feat: use textwrap crate for wrapping help texts
The textwrap crate uses a simpler linear-time algorithm for wrapping
the text. The current algorithm in wrap_help uses several O(n) calls
to String::insert and String::remove, which makes it potentially
quadratic in complexity.

Comparing the 05_ripgrep benchmark at commits textwrap~2 and textwrap
gives this result on my machine:

 name              before ns/iter  after ns/iter  diff ns/iter   diff %
 build_app_long    22,101          21,099               -1,002   -4.53%
 build_app_short   22,138          21,205                 -933   -4.21%
 build_help_long   514,265         284,467            -229,798  -44.68%
 build_help_short  85,720          85,693                  -27   -0.03%
 parse_clean       23,471          22,859                 -612   -2.61%
 parse_complex     29,535          28,919                 -616   -2.09%
 parse_lots        422,815         414,577              -8,238   -1.95%

As part of this commit, the wrapping_newline_chars test was updated.
The old algorithm had a subtle bug where it would break lines too
early. That is, it wrapped the text like

    ARGS:
        <mode>    x, max, maximum   20 characters, contains
                  symbols.
                  l, long           Copy-friendly,
                  14 characters, contains symbols.
                  m, med, medium    Copy-friendly, 8
                  characters, contains symbols.";

when it should really have wrapped it like

    ARGS:
        <mode>    x, max, maximum   20 characters, contains
                  symbols.
                  l, long           Copy-friendly, 14
                  characters, contains symbols.
                  m, med, medium    Copy-friendly, 8
                  characters, contains symbols.";

Notice how the word "14" was incorrectly moved to the next line. There
is clearly room for the word on the line with the "l, long" option
since there is room for "contains" just above it.

I'm not sure why this is, but the algorithm in textwrap handles this
case correctly.
2017-05-29 17:02:57 -04:00