Expose inner error context to allow removing pieces of context, for consistency #5288
Open
2 tasks done
Labels
A-help
Area: documentation, including docs.rs, readme, examples, etc...
C-enhancement
Category: Raise on the bar on expectations
Please complete the following tasks
Clap Version
master
Describe your use case
Currently, error messages provided by
clap::Error
rely on numerous private APIs when being constructed, which force you to rely on writing an entirely new Context formatter, instead of being able to access the inner styles directly, as with other similar use cases.A similar proposed enhancement, #5065, already goes into in-depth discussion about possible alternatives and solutions at the moment, suggests making
Error::set_source
accessible, which is incredibly beneficial for solving most of my problems when it comes to making error prints pretty, however, it still doesn't address being able to trim unnecessary help flags from errors, which would either require exposing specific inner methods, or simply exposing a public API to remove from the inner error context, which would be complimentingError::insert
Describe the solution you'd like
Currently, I feel like the most straightforward and flexible solution here would be a public API method exposing
.inner.context.remove()
, akin to the currentError::insert
exposing.inner.context.insert()
, defined here:clap/clap_builder/src/error/mod.rs
Lines 197 to 202 in 2ab48b2
One could imagine how similar this public API would be, and how fitting it would be for the sake of completeness in the library, as it's a very non-roundabout way to go about allowing prettier Error outputs without hardcoding even more public methods to expose, to access the inner styles and help flags.
Alternatives, if applicable
I've already gone over them, including exposing specifically the inner prettier and inner help flag params, this solution is cleaner.
Additional Context
🚀
The text was updated successfully, but these errors were encountered: