aj-bagwell / clio

A rust library for parsing command line file name arguements
13 stars 8 forks source link

Doesn't play nicely with clap 3.1's derive API #1

Closed kwigley closed 2 years ago

kwigley commented 2 years ago

I tried this our with a newer version of clap (3.1), but was unable to compile with with errors like the following

error[E0277]: `OsString` doesn't implement `std::fmt::Display`
   --> examples/cat.rs:8:36
    |
8   |     #[clap(parse(try_from_os_str = Input::try_from_os_str), default_value="-")]
    |                                    ^^^^^ `OsString` cannot be formatted with the default formatter
    |
   ::: /Users/kwigley/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/macros.rs:111:39
    |
111 |         let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
    |                                       ---------------------------------------- in this macro invocation
    |
    = help: the trait `std::fmt::Display` is not implemented for `OsString`
    = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
    = note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

This might be an issue with clap, sorry about that if that is the case! Here is an example where clap tests the same functionality: https://github.com/clap-rs/clap/blob/976f3d500ab890216e5d9929fcfc31bc7b4d16b4/tests/derive/custom_string_parsers.rs#L121

kwigley commented 2 years ago

Here is the issue reproduced with the example in the repo: https://github.com/kwigley/clio/tree/kwigley/using-clap

aj-bagwell commented 2 years ago

This is fixed in version 0.2.0. The correct derive annotation for clap is now:

#[clap(parse(try_from_os_str = TryFrom::try_from))]