Skip to content

Commit 0d5ebd2

Browse files
author
rzmk
committed
refactor: consolidate debug print statements to a single function
1 parent c48139e commit 0d5ebd2

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/main.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use inquire::{Confirm, Select};
22
use std::{env, process::Command};
33

4+
fn print_debug_info(output: std::process::Output) {
5+
println!("Debug info:");
6+
println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout));
7+
println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr));
8+
println!("Exit status:\n{}", output.status);
9+
}
10+
411
fn main() {
512
// Check if -a flag is passed to run git add -A before commit
613
let args: Vec<String> = env::args().collect();
@@ -69,10 +76,7 @@ fn main() {
6976
.expect("failed to execute process");
7077

7178
if debug {
72-
println!("Debug info:");
73-
println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout));
74-
println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr));
75-
println!("Exit status:\n{}", output.status);
79+
print_debug_info(output);
7680
}
7781
}
7882
}
@@ -85,10 +89,7 @@ fn main() {
8589
.expect("failed to execute process");
8690

8791
if debug {
88-
println!("Debug info:");
89-
println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout));
90-
println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr));
91-
println!("Exit status:\n{}", output.status);
92+
print_debug_info(output);
9293
}
9394
}
9495

@@ -101,10 +102,7 @@ fn main() {
101102
.expect("failed to execute process");
102103

103104
if debug {
104-
println!("Debug info:");
105-
println!("stdout:\n{}", String::from_utf8_lossy(&output.stdout));
106-
println!("stderr:\n{}", String::from_utf8_lossy(&output.stderr));
107-
println!("Exit status:\n{}", output.status);
105+
print_debug_info(output);
108106
}
109107
}
110108
}

0 commit comments

Comments
 (0)