@@ -15,6 +15,7 @@ use std::fs::File;
15
15
use std:: io:: Read ;
16
16
use std:: io:: Write ;
17
17
use std:: path:: Path ;
18
+ use std:: path:: PathBuf ;
18
19
use std:: process;
19
20
20
21
#[ derive( Serialize , Deserialize , Debug ) ]
@@ -349,23 +350,42 @@ fn main() {
349
350
}
350
351
Some ( ( "open" , sub_matches) ) => {
351
352
let url = sub_matches. value_of ( "REMOTE" ) . expect ( "required" ) ;
353
+ let mut found: Vec < PathBuf > = vec ! [ ] ;
352
354
353
355
for gpm_root in rc. root {
354
- let dest_dir = git:: url_to_path ( & gpm_root, url) . unwrap ( ) ;
355
-
356
- if dest_dir. exists ( ) && dest_dir. is_dir ( ) {
357
- println ! (
358
- "Found the repository '{}'" ,
359
- dest_dir. as_os_str( ) . to_str( ) . unwrap( )
360
- ) ;
361
- file_explorer:: open ( & dest_dir) ;
362
- return ;
356
+ let repo_dir = git:: url_to_path ( & gpm_root, url) . unwrap ( ) ;
357
+
358
+ if repo_dir. exists ( ) && repo_dir. is_dir ( ) {
359
+ found. push ( repo_dir. to_path_buf ( ) ) ;
363
360
}
364
361
}
365
362
366
- println ! ( "Did not found the cloned repository '{}'" , url) ;
363
+ if found. is_empty ( ) {
364
+ println ! ( "Did not found the cloned repository '{}'" , url) ;
365
+ process:: exit ( 0x1 ) ;
366
+ }
367
367
368
- process:: exit ( 0x1 ) ;
368
+ if found. len ( ) == 1 {
369
+ println ! (
370
+ "Found the repository '{}'" ,
371
+ found[ 0 ] . as_os_str( ) . to_str( ) . unwrap( )
372
+ ) ;
373
+ file_explorer:: open ( & found[ 0 ] ) ;
374
+ process:: exit ( 0x0 ) ;
375
+ }
376
+
377
+ let options: Vec < & str > = found
378
+ . iter ( )
379
+ . map ( |s| s. as_os_str ( ) . to_str ( ) . unwrap ( ) )
380
+ . collect ( ) ;
381
+
382
+ let ans: Result < & str , InquireError > =
383
+ Select :: new ( "Select a repository to open:" , options) . prompt ( ) ;
384
+
385
+ match ans {
386
+ Ok ( choice) => file_explorer:: open ( Path :: new ( choice) ) ,
387
+ Err ( _) => process:: exit ( 0x0 ) ,
388
+ }
369
389
}
370
390
Some ( ( ext, sub_matches) ) => {
371
391
let args = sub_matches
0 commit comments