Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Clap's non-exiting functions
The better to test with.
  • Loading branch information
rbtcollins committed Jun 13, 2020
commit 46fd147a95d87dad52a0dbfe2614b75fb1fa6159
1 change: 1 addition & 0 deletions src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ error_chain! {
}

foreign_links {
Clap(clap::Error);
Temp(temp::Error);
Io(io::Error);
Term(term::Error);
Expand Down
11 changes: 10 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ where
pub fn main() -> Result<utils::ExitCode> {
self_update::cleanup_self_updater()?;

let matches = cli().get_matches_from(process().args_os());
let matches = match cli().get_matches_from_safe(process().args_os()) {
Ok(matches) => Ok(matches),
Err(e)
if e.kind == clap::ErrorKind::HelpDisplayed
|| e.kind == clap::ErrorKind::VersionDisplayed =>
{
return Ok(utils::ExitCode(0))
}
Err(e) => Err(e),
}?;
Comment on lines +58 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to have this factored into a function given it's also used in setup_mode.rs and someone fixing something in one might miss the other.

let verbose = matches.is_present("verbose");
let quiet = matches.is_present("quiet");
let cfg = &mut common::set_globals(verbose, quiet)?;
Expand Down
11 changes: 10 additions & 1 deletion src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ pub fn main() -> Result<utils::ExitCode> {
.help("Don't configure the PATH environment variable"),
);

let matches = cli.get_matches_from(process().args_os());
let matches = match cli.get_matches_from_safe(process().args_os()) {
Ok(matches) => matches,
Err(e)
if e.kind == clap::ErrorKind::HelpDisplayed
|| e.kind == clap::ErrorKind::VersionDisplayed =>
{
return Ok(utils::ExitCode(0))
}
Err(e) => Err(e)?,
};
let no_prompt = matches.is_present("no-prompt");
let verbose = matches.is_present("verbose");
let quiet = matches.is_present("quiet");
Expand Down
7 changes: 6 additions & 1 deletion tests/mock/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,16 @@ where
// collected for assertions to be made on it as our tests traverse layers.
// - self update executions cannot run in-process because on windows the
// process replacement dance would replace the test process.
// - any command with --version in it is testing to see something was
// installed properly, so we have to shell out to it to be sure
if name != "rustup" {
return false;
}
let mut is_update = false;
let mut no_self_update = false;
let mut self_cmd = false;
let mut run = false;
let mut version = false;
for arg in args {
if arg.as_ref() == "update" {
is_update = true;
Expand All @@ -509,9 +512,11 @@ where
self_cmd = true;
} else if arg.as_ref() == "run" {
run = true;
} else if arg.as_ref() == "--version" {
version = true;
}
}
!(run || self_cmd || (is_update && !no_self_update))
!(run || self_cmd || version || (is_update && !no_self_update))
}

pub fn run<I, A>(config: &Config, name: &str, args: I, env: &[(&str, &str)]) -> SanitizedOutput
Expand Down