Skip to content

Commit c0af4ce

Browse files
committed
Return std::process::ExitCode instead of exiting with std::process::exit
rust-lang/rust#77553 still exists on nightly-2025-01-30.
1 parent 1b7d3cd commit c0af4ce

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) enum DetachPathDeps {
7070
}
7171

7272
impl Args {
73-
pub(crate) fn parse() -> Result<Self> {
73+
pub(crate) fn parse() -> Result<Option<Self>> {
7474
const SUBCMD: &str = "minimal-versions";
7575

7676
// rustc/cargo args must be valid Unicode
@@ -162,11 +162,11 @@ impl Args {
162162

163163
Short('h') | Long("help") if subcommand.is_none() => {
164164
print!("{USAGE}");
165-
std::process::exit(0);
165+
return Ok(None);
166166
}
167167
Short('V') | Long("version") if subcommand.is_none() => {
168168
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
169-
std::process::exit(0);
169+
return Ok(None);
170170
}
171171

172172
// passthrough
@@ -217,15 +217,15 @@ impl Args {
217217
cargo_args.push(path.clone());
218218
}
219219

220-
Ok(Self {
220+
Ok(Some(Self {
221221
no_private,
222222
direct,
223223
subcommand,
224224
manifest_path,
225225
detach_path_deps,
226226
cargo_args,
227227
rest,
228-
})
228+
}))
229229
}
230230
}
231231

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,28 @@ mod manifest;
1515
mod metadata;
1616
mod restore;
1717

18-
use std::env;
18+
use std::{env, process::ExitCode};
1919

2020
use anyhow::Result;
2121

2222
use crate::{cargo::Workspace, cli::Args};
2323

24-
fn main() {
24+
fn main() -> ExitCode {
2525
term::init_coloring();
2626
if let Err(e) = try_main() {
2727
error!("{e:#}");
2828
}
2929
if term::error()
3030
|| term::warn() && env::var_os("CARGO_MINIMAL_VERSIONS_DENY_WARNINGS").is_some()
3131
{
32-
std::process::exit(1)
32+
ExitCode::FAILURE
33+
} else {
34+
ExitCode::SUCCESS
3335
}
3436
}
3537

3638
fn try_main() -> Result<()> {
37-
let args = Args::parse()?;
39+
let Some(args) = Args::parse()? else { return Ok(()) };
3840
let ws = Workspace::new(args.manifest_path.as_deref(), args.direct)?;
3941

4042
// Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`

0 commit comments

Comments
 (0)