Skip to content

Commit 59af32b

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 e23fd89 commit 59af32b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) struct Args {
3030
}
3131

3232
impl Args {
33-
pub(crate) fn parse() -> Result<Self> {
33+
pub(crate) fn parse() -> Result<Option<Self>> {
3434
const SUBCMD: &str = "no-dev-deps";
3535

3636
// rustc/cargo args must be valid Unicode
@@ -99,11 +99,11 @@ impl Args {
9999

100100
Short('h') | Long("help") if subcommand.is_none() => {
101101
print!("{USAGE}");
102-
std::process::exit(0);
102+
return Ok(None);
103103
}
104104
Short('V') | Long("version") if subcommand.is_none() => {
105105
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
106-
std::process::exit(0);
106+
return Ok(None);
107107
}
108108

109109
// passthrough
@@ -152,7 +152,7 @@ impl Args {
152152
cargo_args.push(path.clone());
153153
}
154154

155-
Ok(Self { no_private, manifest_path, cargo_args, rest })
155+
Ok(Some(Self { no_private, manifest_path, cargo_args, rest }))
156156
}
157157
}
158158

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,26 @@ 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() || term::warn() && env::var_os("CARGO_NO_DEV_DEPS_DENY_WARNINGS").is_some() {
30-
std::process::exit(1)
30+
ExitCode::FAILURE
31+
} else {
32+
ExitCode::SUCCESS
3133
}
3234
}
3335

3436
fn try_main() -> Result<()> {
35-
let args = Args::parse()?;
37+
let Some(args) = Args::parse()? else { return Ok(()) };
3638
let ws = Workspace::new(args.manifest_path.as_deref())?;
3739

3840
let no_dev_deps = true;

0 commit comments

Comments
 (0)