Replies: 1 comment
-
Sorry I had somehow overlooked this. #4140 is a similar discussion. I would first ask if you need a custom
These will take your existing error and wrap it in all of the clap error features. If what you are wanting is even more control over the error, than yes, that would required a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
I have an already existing parsing function defined in a separate crate which I want to use to implement a
TypedValueParser
.The main reason for this is to be able to emit clap errors to have a consistent style for CLI errors. I'd really like clap to emit sth. akin to
error: "source" isn't a valid value for '--sth <VALUE>'
(which is nicely integrated e.g. by being colored).Unfortunately, I am facing difficulties with passing along the error info and the context.
When I construct a raw error with
Error::raw(kind, message)
, the error isn't colored and there is no context / info (I mean thefor '--sth <VALUE>'
part).Error::raw
recommends usingCommand::error
(to pass along that metadata), however it takes a&mut Command
while I only have access to a&Command
insideTypedValueParser::parse{,_ref}
.There is no way for me to set the error info / context.
I've checked the implementations of
StringValueParser
andBoolValueParser
to try to learn how one is supposed to do it.Alas they through and through rely on private functionality like
Error::{invalid_value, set_info}
.Is the API still in development or is there a concise way to integrate nicely with clap's error system?
Beta Was this translation helpful? Give feedback.
All reactions