-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
TypedValueParser
cannot parse/validate an OsStr
with full error context
#4362
Comments
(I think this should be labeled a bug rather than an enhancement, since it's functionality that existed in clap 3, but the "enhancement" issue template was more fitting for what there was to say about it.) |
For anyone else reading this, I would recommend double checking if you need to implement Current alternatives:
|
@kpreid could you expand on your use case? I'm curious in what situations someone needs to parse |
For this issue, there are two core problems
|
In the particular case, I want to validate that A more elaborate case of actual parsing involving
Prior to |
This is a major building block to avoid needing to implement `TypedValueParser` Inspired by clap-rs#4362
I just confirmed that release 4.0.12 solves the problem I had. Thanks! |
Please complete the following tasks
Clap Version
4.0.11 (and also 3.2)
Describe your use case
There seems to be no way to simultaneously:
value_parser = ...
),OsStr
input (non-UTF-8) rather thanstr
, andcontext
information identifying the erroneous value etc.There is an implementation of
TypedValueParser
for functions which adds context for the error but it only accepts&str
input, and if one is writing one's ownimpl TypedValueParser for …
then it is not possible to access theError
operations to add context. The documentation recommendsCommand::error()
, but that takes a mutableCommand
which is not available from within aTypedValueParser
.Describe the solution you'd like
It should be possible to construct a
clap::Error
, while implementing a parser, that has all the usual context.Alternatives, if applicable
A second implementation for functions that take
&OsStr
would work, but does not seem an ideal solution to me since it doesn't allow composingTypedValueParser
s.Additional Context
In previous discussion, epage wrote:
No one filed that issue yet, so I am now. (Another discussion post.)
The text was updated successfully, but these errors were encountered: