Skip to content

Commit 989de7c

Browse files
committed
Use Clap's non-exiting functions
The better to test with.
1 parent 332eb45 commit 989de7c

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/cli/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ error_chain! {
2020
}
2121

2222
foreign_links {
23+
Clap(clap::Error);
2324
Temp(temp::Error);
2425
Io(io::Error);
2526
Term(term::Error);

src/cli/rustup_mode.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ where
5555
pub fn main() -> Result<utils::ExitCode> {
5656
self_update::cleanup_self_updater()?;
5757

58-
let matches = cli().get_matches_from(process().args_os());
58+
let matches = match cli().get_matches_from_safe(process().args_os()) {
59+
Ok(matches) => Ok(matches),
60+
Err(e)
61+
if e.kind == clap::ErrorKind::HelpDisplayed
62+
|| e.kind == clap::ErrorKind::VersionDisplayed =>
63+
{
64+
return Ok(utils::ExitCode(0))
65+
}
66+
Err(e) => Err(e),
67+
}?;
5968
let verbose = matches.is_present("verbose");
6069
let quiet = matches.is_present("quiet");
6170
let cfg = &mut common::set_globals(verbose, quiet)?;

src/cli/setup_mode.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,16 @@ pub fn main() -> Result<utils::ExitCode> {
8787
.help("Don't configure the PATH environment variable"),
8888
);
8989

90-
let matches = cli.get_matches_from(process().args_os());
90+
let matches = match cli.get_matches_from_safe(process().args_os()) {
91+
Ok(matches) => matches,
92+
Err(e)
93+
if e.kind == clap::ErrorKind::HelpDisplayed
94+
|| e.kind == clap::ErrorKind::VersionDisplayed =>
95+
{
96+
return Ok(utils::ExitCode(0))
97+
}
98+
Err(e) => Err(e)?,
99+
};
91100
let no_prompt = matches.is_present("no-prompt");
92101
let verbose = matches.is_present("verbose");
93102
let quiet = matches.is_present("quiet");

tests/mock/clitools.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,16 @@ where
493493
// collected for assertions to be made on it as our tests traverse layers.
494494
// - self update executions cannot run in-process because on windows the
495495
// process replacement dance would replace the test process.
496+
// - any command with --version in it is testing to see something was
497+
// installed properly, so we have to shell out to it to be sure
496498
if name != "rustup" {
497499
return false;
498500
}
499501
let mut is_update = false;
500502
let mut no_self_update = false;
501503
let mut self_cmd = false;
502504
let mut run = false;
505+
let mut version = false;
503506
for arg in args {
504507
if arg.as_ref() == "update" {
505508
is_update = true;
@@ -509,9 +512,11 @@ where
509512
self_cmd = true;
510513
} else if arg.as_ref() == "run" {
511514
run = true;
515+
} else if arg.as_ref() == "--version" {
516+
version = true;
512517
}
513518
}
514-
!(run || self_cmd || (is_update && !no_self_update))
519+
!(run || self_cmd || version || (is_update && !no_self_update))
515520
}
516521

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

0 commit comments

Comments
 (0)