Skip to content

Commit 89796f2

Browse files
committed
refactor: gpm list
1 parent ceda40f commit 89796f2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/main.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ fn main() {
114114

115115
let matches = app.clone().get_matches();
116116

117-
fn get_gpm_root(rc: &Preset) -> &str {
117+
fn check_gpm_root(rc: &Preset) {
118118
if rc.root.is_empty() {
119-
println!("Can not found root folder in the configure for clone.\nTry running the following command to add a default folder:\n\n gpm config add root $HOME/gpm\n\nOr set to a custom folder:\n\n gpm config add root <folder>\n");
119+
println!("Can not found root folder in the configure.\nTry running the following command to add a default folder:\n\n gpm config add root $HOME/gpm\n\nOr set to a custom folder:\n\n gpm config add root <folder>\n");
120120
process::exit(0x1);
121-
} else if rc.root.len() == 1 {
121+
}
122+
}
123+
124+
fn get_gpm_root(rc: &Preset) -> &str {
125+
check_gpm_root(rc);
126+
127+
if rc.root.len() == 1 {
122128
let s = &rc.root[0].as_str();
123129
s
124130
} else {
@@ -340,12 +346,15 @@ fn main() {
340346
fs::write(gpm_rc, serialized).expect("can not write to $HOME/.gpmrc");
341347
}
342348
Some(("list", _)) => {
343-
let gpm_root: &str = get_gpm_root(&rc);
344-
let root = Path::new(gpm_root);
345-
let repositories = walk::walk_root(root).unwrap();
349+
check_gpm_root(&rc);
346350

347-
for v in repositories {
348-
println!("{}", v.as_os_str().to_str().unwrap())
351+
for gpm_root in rc.root {
352+
let root = Path::new(&gpm_root);
353+
let repositories = walk::walk_root(root).unwrap();
354+
355+
for v in repositories {
356+
println!("{}", v.as_os_str().to_str().unwrap())
357+
}
349358
}
350359
}
351360
Some(("open", sub_matches)) => {

0 commit comments

Comments
 (0)