Skip to content

Commit c191036

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 23372d7 commit c191036

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/main.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
fs,
77
io::{self, Read as _, Write as _},
88
path::{Path, PathBuf},
9+
process::ExitCode,
910
};
1011

1112
use lexopt::{
@@ -56,7 +57,7 @@ struct Args {
5657
}
5758

5859
impl Args {
59-
fn parse() -> Result<Self> {
60+
fn parse() -> Result<Option<Self>> {
6061
fn format_arg(arg: &lexopt::Arg<'_>) -> String {
6162
match arg {
6263
Long(flag) => format!("--{flag}"),
@@ -109,11 +110,11 @@ impl Args {
109110
Long("prefix-format" | "prefix") => parse_opt!(prefix_format),
110111
Short('h') | Long("help") => {
111112
print!("{USAGE}");
112-
std::process::exit(0);
113+
return Ok(None);
113114
}
114115
Short('V') | Long("version") => {
115116
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
116-
std::process::exit(0);
117+
return Ok(None);
117118
}
118119
Value(val) if path.is_none() => path = Some(val.into()),
119120
Value(val) if release.is_none() => release = Some(val.parse()?),
@@ -126,7 +127,7 @@ impl Args {
126127
conflicts("--title", "--title-no-link")?;
127128
}
128129

129-
Ok(Self { path, release, title, title_no_link, json, version_format, prefix_format })
130+
Ok(Some(Self { path, release, title, title_no_link, json, version_format, prefix_format }))
130131
}
131132

132133
fn path_for_msg(&self) -> &Path {
@@ -138,15 +139,17 @@ impl Args {
138139
}
139140
}
140141

141-
fn main() {
142+
fn main() -> ExitCode {
142143
if let Err(e) = try_main() {
143144
eprintln!("error: {e}");
144-
std::process::exit(1)
145+
ExitCode::FAILURE
146+
} else {
147+
ExitCode::SUCCESS
145148
}
146149
}
147150

148151
fn try_main() -> Result<()> {
149-
let args = Args::parse()?;
152+
let Some(args) = Args::parse()? else { return Ok(()) };
150153

151154
let mut parser = Parser::new();
152155
if let Some(version_format) = &args.version_format {

0 commit comments

Comments
 (0)