-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Mutable app functions are confusing to users and awkward to work with #2911
Comments
Same issue as |
What are your thoughts on the proposal for solving the
At least in my initial search, I found #540 which didn't have any useful conversation on the subject. |
It would be a good approach to explore definitely. Will have to evaluate it properly when we are finalising the design though. |
Heh, weird. Couldn't find the discussion now. Maybe it was on something else that was related? 🤷 |
|
#950 needs us to rename the |
`Command::_build_all` started as an internal function for `clap_complete` as a stopgap until clap-rs#2911. Overtime, we've been finding more cases where this function needs to be called, so now we're going to fully embrace it until clap-rs#2911 so people aren't scrared off by the hidden implementation from using it. This was inspired by clap-rs#3602
`Command::_build_all` started as an internal function for `clap_complete` as a stopgap until clap-rs#2911. Overtime, we've been finding more cases where this function needs to be called, so now we're going to fully embrace it until clap-rs#2911 so people aren't scrared off by the hidden implementation from using it. This was inspired by clap-rs#3602 Comptibility: Though this adds a deprecation which we general reserve for minor or major versions, this is enough of a corner case that I'm fine doing this in a patch release.
A simple way we can handle this is if we add the type pub struct Built<T>(T);
impl Built<Command> {
pub fn get_arguments(&self) -> impl Iterator<Item=Built<Arg>>;
pub fn get_subcommands(&self) -> impl Iterator<Item=Built<Command>>;
}
impl Built<&'_ Command> {
pub fn get_arguments(&self) -> impl Iterator<Item=Built<Arg>>;
pub fn get_subcommands(&self) -> impl Iterator<Item=Built<Command>>;
}
impl<T> AsRef<T> for Built<T>{
#[inline]
fn as_ref(&self) -> &T{
&self.0
}
}
impl<T> Borrow<T> for Built<T>{
#[inline]
fn borrow(&self) -> &T{
&self.0
}
}
impl<T> :Deref for Built<T> {
type Target = T;
#[inline]
fn deref(&self) -> &T{
&self.0
}
} We would also remove the This still leaves trying to re-work the parser so it can work off of |
Please complete the following tasks
Rust Version
rustc 1.55.0 (c8dfcfe04 2021-09-06)
Clap Version
master
Minimal reproducible code
Steps to reproduce the bug with the above code
Program with the
&mut
APIActual Behaviour
Its awkward and exposing of implementation details. I've seen user confusion akin to "Why does rendering need to modify the app?"
Other uses of this API, like
clap_generate
, need to use the hidden_build
Expected Behaviour
The types are clean and understandable for a user without ambiguous "modify after build"
Additional Context
I propose we add a
struct AppParser
that derefs toApp
.get_matches
will consumeApp
and use_build
(only build what is needed for parsing)App::build(self) -> AppParser
will call_build_all
&mut
functions, but without themut
We can implement the additions without breaking behavior; we just add deprecations. Then on the next breaking release, we remove the deprecated behavior.
Debug Output
No response
The text was updated successfully, but these errors were encountered: