Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builder): Custom parser for arg values #3732

Merged
merged 56 commits into from May 18, 2022
Merged

Commits on May 12, 2022

  1. refactor: Remove dead code

    epage committed May 12, 2022
    Copy the full SHA
    cf0282b View commit details
    Browse the repository at this point in the history
  2. refactor(parser): Track str/OsStr values via Box

    Unfortunately, we can't track using a `ValueParser` inside of `Command`
    because its `PartialEq`.  We'll have to wait until a breaking change to
    relax that.
    
    Compatibility:
    - We now assert on using the wrong method to look up defaults.  This
      shouldn't be a breaking change as it'll assert when getting a real
      value.
    - `values_of`, et al delay panicing on the wrong lookup until the
      iterator is being processed.
    epage committed May 12, 2022
    Copy the full SHA
    dcf69d1 View commit details
    Browse the repository at this point in the history

Commits on May 16, 2022

  1. feat(parser): Add type information to arg values

    To set the type, we offer
    - `ValueParser::<type>` short cuts for natively supported types
    - `TypedValueParser` for fn pointers and custom implementations
    - `value_parser!(T)` for specialized lookup of an implementation
      (inspired by clap-rs#2298)
    
    The main motivation for `value_parser!` is to help with `clap_derive`s
    implementation but it can also be convinient for end-users.
    
    When reading, this replaces nearly all of our current `ArgMatches` getters with:
    - `get_one`: like `value_of_t`
    - `get_many`: like `values_of_t`
    
    It also adds a `get_raw` that allows accessing the `OsStr`s without
    panicing.
    
    The naming is to invoke the idea of a more general container which I
    want to move this to.
    
    The return type is a bit complicated so that
    - Users choose whether to panic on invalid types so they can do their
      own querying, like `get_raw`
    - Users can choose how to handle not present easily (clap-rs#2505)
    
    We had to defer setting the `value_parser` on external subcommands,
    for consistency sake, because `Command` requires `PartialEq` and
    `ValueParser` does not impl that trait.  It'll have to wait until a
    breaking change.
    
    Fixes clap-rs#2505
    epage committed May 16, 2022
    Copy the full SHA
    200f662 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    73fc240 View commit details
    Browse the repository at this point in the history
  3. feat(parser): Expose env-like bool parsers

    Still unsure what should be the default but this at least makes it
    easier for people to choose.
    epage committed May 16, 2022
    Copy the full SHA
    56aaf0b View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    2902f19 View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    ecc5b2f View commit details
    Browse the repository at this point in the history
  6. Copy the full SHA
    9d07b3c View commit details
    Browse the repository at this point in the history
  7. Copy the full SHA
    a798858 View commit details
    Browse the repository at this point in the history
  8. Copy the full SHA
    d52be32 View commit details
    Browse the repository at this point in the history
  9. Copy the full SHA
    a396591 View commit details
    Browse the repository at this point in the history
  10. Copy the full SHA
    50e7308 View commit details
    Browse the repository at this point in the history
  11. refactor(parser): Tweak specialization precedence

    In theory, directly implemented types should have higher precedence than
    inferring from another trait.
    epage committed May 16, 2022
    Copy the full SHA
    352025f View commit details
    Browse the repository at this point in the history
  12. Copy the full SHA
    f9be321 View commit details
    Browse the repository at this point in the history
  13. Copy the full SHA
    ec18648 View commit details
    Browse the repository at this point in the history
  14. Copy the full SHA
    2e57f1f View commit details
    Browse the repository at this point in the history
  15. feat(parser): Track ValueParser's possible values

    This will let us replace `Arg::possible_values` completely by letting
    completions check these.
    epage committed May 16, 2022
    Copy the full SHA
    0088b16 View commit details
    Browse the repository at this point in the history
  16. Copy the full SHA
    f3d8ef2 View commit details
    Browse the repository at this point in the history
  17. Copy the full SHA
    6f2c4af View commit details
    Browse the repository at this point in the history
  18. doc(parser): Expand examples for ValueParser

    This identified a problem with the blanket implementations for
    `TypedValueParser`: it only worked on function pointer types and not unnamed
    function tupes.  The user has to explicitly decay the function type to a
    function pointer to opt-in, so I changed the blanket impl.  The loss of
    the `OsStr` impl shouldn't be too bad.
    epage committed May 16, 2022
    Copy the full SHA
    bdf9d84 View commit details
    Browse the repository at this point in the history
  19. Copy the full SHA
    f16a6fb View commit details
    Browse the repository at this point in the history
  20. refactor(parser): Make AnyValue opaque

    This gives a little more implementation flexibility
    epage committed May 16, 2022
    Copy the full SHA
    8b582c3 View commit details
    Browse the repository at this point in the history
  21. Copy the full SHA
    9920d5b View commit details
    Browse the repository at this point in the history
  22. Copy the full SHA
    bc6da81 View commit details
    Browse the repository at this point in the history
  23. Copy the full SHA
    f296c5c View commit details
    Browse the repository at this point in the history
  24. Copy the full SHA
    8c3f540 View commit details
    Browse the repository at this point in the history
  25. Copy the full SHA
    144cd4c View commit details
    Browse the repository at this point in the history
  26. Copy the full SHA
    c74d3fb View commit details
    Browse the repository at this point in the history
  27. Copy the full SHA
    0e04367 View commit details
    Browse the repository at this point in the history
  28. Copy the full SHA
    772c5e3 View commit details
    Browse the repository at this point in the history
  29. Copy the full SHA
    d538012 View commit details
    Browse the repository at this point in the history
  30. Copy the full SHA
    e6b1468 View commit details
    Browse the repository at this point in the history
  31. Copy the full SHA
    8a58884 View commit details
    Browse the repository at this point in the history
  32. Copy the full SHA
    4845296 View commit details
    Browse the repository at this point in the history
  33. Copy the full SHA
    5532bfc View commit details
    Browse the repository at this point in the history
  34. Copy the full SHA
    0d6be4e View commit details
    Browse the repository at this point in the history
  35. Copy the full SHA
    7cb2a09 View commit details
    Browse the repository at this point in the history
  36. Copy the full SHA
    66570ee View commit details
    Browse the repository at this point in the history
  37. Copy the full SHA
    c331be9 View commit details
    Browse the repository at this point in the history
  38. Copy the full SHA
    3623695 View commit details
    Browse the repository at this point in the history
  39. Copy the full SHA
    c7bd8c8 View commit details
    Browse the repository at this point in the history
  40. fix(parser): Be consistently strict with ArgMatches types

    This gives us more implementation freedom for the future.
    epage committed May 16, 2022
    Copy the full SHA
    792fb54 View commit details
    Browse the repository at this point in the history
  41. feat(parser): Allow removing values from ArgMatches

    This allows reducing the use of `Clone`, especially in `clap_derive`.
    epage committed May 16, 2022
    Copy the full SHA
    d2ca181 View commit details
    Browse the repository at this point in the history
  42. Copy the full SHA
    41f13bd View commit details
    Browse the repository at this point in the history
  43. Copy the full SHA
    72c44a3 View commit details
    Browse the repository at this point in the history
  44. Copy the full SHA
    d826ab9 View commit details
    Browse the repository at this point in the history
  45. Copy the full SHA
    f86d881 View commit details
    Browse the repository at this point in the history
  46. Copy the full SHA
    2ffa38f View commit details
    Browse the repository at this point in the history
  47. feat(parsr): Expose all built-in TypedValueParsers

    This makes life easier for people, whether they want a geneirc
    `NonEmpty<impl TypedValueParser>` or a `PathBufExists(PathBuf)`.
    epage committed May 16, 2022
    Copy the full SHA
    6b0306d View commit details
    Browse the repository at this point in the history

Commits on May 17, 2022

  1. feat(parser): Convenient range value parsers

    There are several approaches with this
    - `value_parser(N..M)`: creates an i64 range
    - `value_parser(value_parser!(u16).range(10..))`: creates an u16 range
      that starts at 10
    - `RangeI64ValueParser`: create whatever range you want
    
    I was hoping to generalize `RangeI64ValueParser` for any source type,
    not just i64, but ran into issues and decided to punt.  I chose `i64` as
    the source type as it seemed the most general and didn't run into
    portability issues like `isize`.
    
    This is a step towards clap-rs#3199.  All that is left is for the derive to use
    this.
    epage committed May 17, 2022
    Copy the full SHA
    63aa236 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    0033bf6 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    675ac68 View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    91fe9ee View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    c9e3b81 View commit details
    Browse the repository at this point in the history
  6. style: Make clippy happy

    epage committed May 17, 2022
    Copy the full SHA
    acdf26a View commit details
    Browse the repository at this point in the history
  7. fix: Bump MSRV to 1.56.0

    This is needed for `Bound::cloned` and fits within official MSRV policy
    (2 versions back) and unofficial (6 months, see clap-rs#3267)
    epage committed May 17, 2022
    Copy the full SHA
    4a733cd View commit details
    Browse the repository at this point in the history