@@ -6,6 +6,7 @@ use std::{
6
6
fs,
7
7
io:: { self , Read as _, Write as _} ,
8
8
path:: { Path , PathBuf } ,
9
+ process:: ExitCode ,
9
10
} ;
10
11
11
12
use lexopt:: {
@@ -56,7 +57,7 @@ struct Args {
56
57
}
57
58
58
59
impl Args {
59
- fn parse ( ) -> Result < Self > {
60
+ fn parse ( ) -> Result < Option < Self > > {
60
61
fn format_arg ( arg : & lexopt:: Arg < ' _ > ) -> String {
61
62
match arg {
62
63
Long ( flag) => format ! ( "--{flag}" ) ,
@@ -109,11 +110,11 @@ impl Args {
109
110
Long ( "prefix-format" | "prefix" ) => parse_opt ! ( prefix_format) ,
110
111
Short ( 'h' ) | Long ( "help" ) => {
111
112
print ! ( "{USAGE}" ) ;
112
- std :: process :: exit ( 0 ) ;
113
+ return Ok ( None ) ;
113
114
}
114
115
Short ( 'V' ) | Long ( "version" ) => {
115
116
println ! ( "{} {}" , env!( "CARGO_PKG_NAME" ) , env!( "CARGO_PKG_VERSION" ) ) ;
116
- std :: process :: exit ( 0 ) ;
117
+ return Ok ( None ) ;
117
118
}
118
119
Value ( val) if path. is_none ( ) => path = Some ( val. into ( ) ) ,
119
120
Value ( val) if release. is_none ( ) => release = Some ( val. parse ( ) ?) ,
@@ -126,7 +127,7 @@ impl Args {
126
127
conflicts ( "--title" , "--title-no-link" ) ?;
127
128
}
128
129
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 } ) )
130
131
}
131
132
132
133
fn path_for_msg ( & self ) -> & Path {
@@ -138,15 +139,17 @@ impl Args {
138
139
}
139
140
}
140
141
141
- fn main ( ) {
142
+ fn main ( ) -> ExitCode {
142
143
if let Err ( e) = try_main ( ) {
143
144
eprintln ! ( "error: {e}" ) ;
144
- std:: process:: exit ( 1 )
145
+ ExitCode :: FAILURE
146
+ } else {
147
+ ExitCode :: SUCCESS
145
148
}
146
149
}
147
150
148
151
fn try_main ( ) -> Result < ( ) > {
149
- let args = Args :: parse ( ) ?;
152
+ let Some ( args) = Args :: parse ( ) ? else { return Ok ( ( ) ) } ;
150
153
151
154
let mut parser = Parser :: new ( ) ;
152
155
if let Some ( version_format) = & args. version_format {
0 commit comments