Skip to content
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

add command suggestion #3817

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

fbrv
Copy link

@fbrv fbrv commented May 9, 2024

Closes #3812.

@fbrv
Copy link
Author

fbrv commented May 9, 2024

@rami3l that's the overall idea, still not super sure about the suggestion logic. At first I was thinking to pattern matching only for a specific use case but then changed to possibly extend to how many case are necessary by inserting a new entry inside the hashmap, what do you think?

@@ -97,7 +100,11 @@ pub fn main() -> Result<utils::ExitCode> {
write!(process().stdout().lock(), "{e}")?;
return Ok(utils::ExitCode(0));
}
Err(e) => return Err(e.into()),
Err(e) => {
Copy link
Member

@rami3l rami3l May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that's not the right place to add the handling logic for rustup update. Have you actually tested the code that you added?

Please have a look at the rustup update handling logic here, and find out where that error was thrown, catch it, print another message using the info!() macro if that is the expected type of error, and finally re-throw it (you may adjust the ordering of the error message and the new one if that makes the implementation simpler).

After that, please add a regression test in an appropriate spot (like here) to ensure the resolution of the issue.

@@ -125,3 +132,20 @@ pub fn main() -> Result<utils::ExitCode> {

self_update::install(no_prompt, verbose, quiet, opts)
}

fn handle_suggestion() -> Result<()> {
let mut suggestions = HashMap::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO using a HashMap has added no value to the current implementation. There's no need to "plan ahead" in this particular situation. If a HashMap turns out to be required, it can be added in another patch in the future, but not right now.

"note: use `rustup self update` to update rustup itself",
);

let args: Vec<String> = std::env::args().skip(1).collect();
Copy link
Member

@rami3l rami3l May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::env::args() is not appropriate here, see #3817 (comment). Instead, you should extract all necessary info from the m: &ArgMatches parameter.

@@ -1,3 +1,5 @@
use std::collections::HashMap;
Copy link
Member

@rami3l rami3l May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, at Rustup it is recommended to use atomic commits with informative commit messages, please have a look at the examples on the master branch. This means that you'll have to do git rebase -i for quite a bunch of times to get the right commits (and the right messages).

@rami3l rami3l marked this pull request as draft May 10, 2024 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustup update self should suggest rustup self update
2 participants