Skip to content

Commit e877753

Browse files
committed
refactor(effects): return exit code instead of exiting
1 parent 725b60f commit e877753

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

src/effects/fix.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use {
33
log::warn,
44
};
55

6-
pub fn run(ctx: Context) -> ! {
6+
pub fn run(ctx: Context) -> i32 {
77
let mut contains_unfixable_issues = false;
88
let mut was_invalid = false;
99

@@ -59,5 +59,9 @@ pub fn run(ctx: Context) -> ! {
5959
ui::util::print_no_issues_found();
6060
}
6161

62-
std::process::exit(if contains_unfixable_issues { 1 } else { 0 });
62+
if contains_unfixable_issues {
63+
1
64+
} else {
65+
0
66+
}
6367
}

src/effects/format.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::{context::Context, effects::ui};
22

3-
pub fn run(ctx: Context) -> ! {
3+
pub fn run(ctx: Context) -> i32 {
44
if ctx.config.cli.check {
55
check_formatting(ctx)
66
} else {
77
fix_formatting(ctx)
88
}
99
}
1010

11-
fn check_formatting(ctx: Context) -> ! {
11+
fn check_formatting(ctx: Context) -> i32 {
1212
let mut is_invalid = false;
1313
ctx
1414
.packages
@@ -25,10 +25,14 @@ fn check_formatting(ctx: Context) -> ! {
2525
if !is_invalid {
2626
ui::util::print_no_issues_found();
2727
}
28-
std::process::exit(if is_invalid { 1 } else { 0 });
28+
if is_invalid {
29+
1
30+
} else {
31+
0
32+
}
2933
}
3034

31-
fn fix_formatting(ctx: Context) -> ! {
35+
fn fix_formatting(ctx: Context) -> i32 {
3236
let mut was_invalid = false;
3337
ctx
3438
.packages
@@ -53,8 +57,10 @@ fn fix_formatting(ctx: Context) -> ! {
5357
package.borrow().write_to_disk(&ctx.config);
5458
});
5559
}
56-
if !was_invalid {
60+
if was_invalid {
61+
1
62+
} else {
5763
ui::util::print_no_issues_found();
64+
0
5865
}
59-
std::process::exit(0);
6066
}

src/effects/lint.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{context::Context, effects::ui};
22

33
/// Run the lint command side effects
4-
pub fn run(ctx: Context) -> ! {
4+
pub fn run(ctx: Context) -> i32 {
55
let mut is_invalid = false;
66

77
ctx.get_version_groups().for_each(|group| {
@@ -28,9 +28,10 @@ pub fn run(ctx: Context) -> ! {
2828
});
2929
});
3030

31-
if !is_invalid {
31+
if is_invalid {
32+
1
33+
} else {
3234
ui::util::print_no_issues_found();
35+
0
3336
}
34-
35-
std::process::exit(if is_invalid { 1 } else { 0 });
3637
}

src/effects/list.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{context::Context, effects::ui};
22

3-
pub fn run(ctx: Context) -> ! {
3+
pub fn run(ctx: Context) -> i32 {
44
let mut is_invalid = false;
55

66
ctx
@@ -25,5 +25,9 @@ pub fn run(ctx: Context) -> ! {
2525
ui::util::print_no_issues_found();
2626
}
2727

28-
std::process::exit(if is_invalid { 1 } else { 0 });
28+
if is_invalid {
29+
1
30+
} else {
31+
0
32+
}
2933
}

src/effects/update.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use {
77
log::{error, warn},
88
};
99

10-
pub fn run(ctx: Context) -> ! {
10+
pub fn run(ctx: Context) -> i32 {
1111
let mut was_outdated = false;
1212

1313
ctx
@@ -58,7 +58,7 @@ pub fn run(ctx: Context) -> ! {
5858
}
5959

6060
if ctx.config.cli.check {
61-
std::process::exit(if was_outdated { 1 } else { 0 });
61+
return if was_outdated { 1 } else { 0 };
6262
}
6363

6464
if !ctx.config.cli.dry_run {
@@ -67,5 +67,5 @@ pub fn run(ctx: Context) -> ! {
6767
});
6868
}
6969

70-
std::process::exit(0);
70+
0
7171
}

src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,33 @@ async fn main() {
6868

6969
let ctx = Context::create(config, packages, None);
7070

71-
match ctx.config.cli.subcommand {
71+
let _exit_code = match ctx.config.cli.subcommand {
7272
Subcommand::Fix => {
7373
let ctx = visit_packages(ctx);
74-
fix::run(ctx);
74+
fix::run(ctx)
7575
}
7676
Subcommand::Format => {
7777
let ctx = visit_formatting(ctx);
78-
format::run(ctx);
78+
format::run(ctx)
7979
}
8080
Subcommand::Lint => {
8181
let ctx = visit_packages(ctx);
82-
lint::run(ctx);
82+
lint::run(ctx)
8383
}
8484
Subcommand::Update => {
8585
let mut ctx = ctx;
8686
ctx.fetch_all_updates().await;
8787
let ctx = visit_packages(ctx);
88-
update::run(ctx);
88+
update::run(ctx)
8989
}
9090
Subcommand::List => {
9191
let ctx = visit_packages(ctx);
92-
list::run(ctx);
92+
list::run(ctx)
9393
}
9494
};
9595

9696
#[cfg(feature = "dhat-heap")]
9797
drop(_profiler);
98+
99+
exit(_exit_code);
98100
}

0 commit comments

Comments
 (0)