Replies: 1 comment 3 replies
-
First, if your type implements Second, you can pass a But we should also support people writing their own value parsers and this is a bug hole for it. Can you create an issue? The reason |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In order to parse a string as a CSS selector, I implemented the
builder::TypedValueParser
forSelectorParser
. This trait's methodparse_ref
receives a read-only reference to theCommand
.A thing I'd like to achieve is to error gracefully when a CSS selector parsed from the argument list is not valid.
To do it I cannot resort to some interesting Error factory methods that are internal to the clap crate like
invalid_value
; and the publicwith_description
method is deprecated in favor ofCommand::error
The problem I'm having is that
Command::Error
receives a mutable reference to the command, while the signature ofTypedValueParser::parse_ref
receives an immutable reference. So I cannot simply map the error like this:What would be a better way to implement a value parser that performs validation of a string as a CSS selector and reports potential parsing errors back to the user?
Thank you so much for your attention.
PS: |
I'm using clap
3.2.17
I found a related issue, but I still find this question pertinent: #4133
Beta Was this translation helpful? Give feedback.
All reactions