Skip to content

Commit 3bb54c2

Browse files
committed
refactor: Finalize modular file structure
Cleanup main.rs to be minimal and focused: - Simplified imports (removed redundant Command and Error imports) - Reordered functions: main() first, then run_app(), then helpers - Used fully qualified paths in check_gh_cli_installed - Maintained clean 69-line structure Main.rs now serves as clean entry point with: - Module declarations (alphabetical) - Re-exports for cross-module use - Entry point (main, run_app) - Helper utilities (executable_name, check_gh_cli_installed) All 52 tests pass.
1 parent 0093ed0 commit 3bb54c2

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/main.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ffi::OsString;
22
use std::process;
3-
use std::process::Command;
43

54
use colored::*;
6-
use git2::Error;
75

86
mod branch;
97
mod chain;
@@ -21,19 +19,8 @@ pub use branch::Branch;
2119
pub use chain::Chain;
2220
pub use git_chain::GitChain;
2321

24-
pub fn executable_name() -> String {
25-
let name = std::env::current_exe()
26-
.expect("Cannot get the path of current executable.")
27-
.file_name()
28-
.expect("Cannot get the executable name.")
29-
.to_string_lossy()
30-
.into_owned();
31-
if name.starts_with("git-") && name.len() > 4 {
32-
let tmp: Vec<String> = name.split("git-").map(|x| x.to_string()).collect();
33-
let git_cmd = &tmp[1];
34-
return format!("git {}", git_cmd);
35-
}
36-
name
22+
fn main() {
23+
run_app(std::env::args_os());
3724
}
3825

3926
fn run_app<I, T>(arguments: I)
@@ -52,12 +39,23 @@ where
5239
}
5340
}
5441

55-
fn main() {
56-
run_app(std::env::args_os());
42+
pub fn executable_name() -> String {
43+
let name = std::env::current_exe()
44+
.expect("Cannot get the path of current executable.")
45+
.file_name()
46+
.expect("Cannot get the executable name.")
47+
.to_string_lossy()
48+
.into_owned();
49+
if name.starts_with("git-") && name.len() > 4 {
50+
let tmp: Vec<String> = name.split("git-").map(|x| x.to_string()).collect();
51+
let git_cmd = &tmp[1];
52+
return format!("git {}", git_cmd);
53+
}
54+
name
5755
}
5856

59-
pub fn check_gh_cli_installed() -> Result<(), Error> {
60-
let output = Command::new("gh").arg("--version").output();
57+
pub fn check_gh_cli_installed() -> Result<(), git2::Error> {
58+
let output = std::process::Command::new("gh").arg("--version").output();
6159
match output {
6260
Ok(output) if output.status.success() => Ok(()),
6361
_ => {

0 commit comments

Comments
 (0)