@@ -7,43 +7,64 @@ pub fn list() {
7
7
println ! ( "Installed Commands:" ) ;
8
8
let installed_commands = find ( ) ;
9
9
for command in installed_commands {
10
- println ! ( " {}" , command. bold( ) ) ;
10
+ println ! (
11
+ " {}" ,
12
+ format!(
13
+ "{}{}" ,
14
+ command. name. bold( ) ,
15
+ if command. is_development { " (dev)" } else { "" }
16
+ )
17
+ ) ;
11
18
}
12
19
}
13
20
14
- fn find ( ) -> Vec < String > {
15
- let mut commands = find_command_binaries_in_development_dirs ( ) ;
16
- if commands. is_empty ( ) {
17
- commands = find_command_binaries_in_system_path ( ) ;
18
- }
19
- commands
21
+ #[ derive( Clone , Debug ) ]
22
+ struct CommandInfo {
23
+ name : String ,
24
+ path : PathBuf ,
25
+ is_development : bool ,
26
+ }
27
+
28
+ fn find ( ) -> Vec < CommandInfo > {
29
+ let development_commands = find_command_binaries_in_development_dirs ( ) ;
30
+ let installed_commands = find_command_binaries_in_system_path ( ) ;
31
+
32
+ let mut all_commands = development_commands;
33
+ all_commands. extend ( installed_commands. iter ( ) . cloned ( ) ) ;
34
+ all_commands
20
35
}
21
36
22
- fn find_command_binaries_in_development_dirs ( ) -> Vec < String > {
37
+ fn find_command_binaries_in_development_dirs ( ) -> Vec < CommandInfo > {
23
38
let mut commands = Vec :: new ( ) ;
24
39
let current_exe = match env:: current_exe ( ) {
25
40
Ok ( exe) => exe,
26
41
Err ( _) => return commands,
27
42
} ;
28
- let target_dir_name = if cfg ! ( debug_assertions) {
43
+ let build_type = if cfg ! ( debug_assertions) {
29
44
"debug"
30
45
} else {
31
46
"release"
32
47
} ;
33
- let target_dir = current_exe
48
+
49
+ // Get the location of the binary directory for the build
50
+ let binary_dir = current_exe
34
51
. parent ( )
35
52
. unwrap ( )
36
53
. parent ( )
37
54
. unwrap ( )
38
- . join ( target_dir_name ) ;
55
+ . join ( build_type ) ;
39
56
40
- if let Ok ( entries) = fs:: read_dir ( & target_dir ) {
57
+ if let Ok ( entries) = fs:: read_dir ( & binary_dir ) {
41
58
for entry in entries. filter_map ( Result :: ok) {
42
59
let path = entry. path ( ) ;
43
60
if is_valid_command_binary ( & path) {
44
61
if let Some ( command_name) = path. file_name ( ) . and_then ( |n| n. to_str ( ) ) {
45
62
let stripped = command_name. strip_prefix ( "iox2-" ) . unwrap_or ( command_name) ;
46
- commands. push ( stripped. to_string ( ) ) ;
63
+ commands. push ( CommandInfo {
64
+ name : stripped. to_string ( ) ,
65
+ path,
66
+ is_development : true ,
67
+ } ) ;
47
68
}
48
69
}
49
70
}
@@ -52,7 +73,7 @@ fn find_command_binaries_in_development_dirs() -> Vec<String> {
52
73
commands
53
74
}
54
75
55
- fn find_command_binaries_in_system_path ( ) -> Vec < String > {
76
+ fn find_command_binaries_in_system_path ( ) -> Vec < CommandInfo > {
56
77
let mut commands = Vec :: new ( ) ;
57
78
if let Ok ( path_var) = env:: var ( "PATH" ) {
58
79
for path in env:: split_paths ( & path_var) {
@@ -61,7 +82,11 @@ fn find_command_binaries_in_system_path() -> Vec<String> {
61
82
let path = entry. path ( ) ;
62
83
if is_valid_command_binary ( & path) {
63
84
if let Some ( command_name) = path. file_name ( ) . and_then ( |n| n. to_str ( ) ) {
64
- commands. push ( command_name. to_string ( ) ) ;
85
+ commands. push ( CommandInfo {
86
+ name : command_name. to_string ( ) ,
87
+ path,
88
+ is_development : false ,
89
+ } ) ;
65
90
}
66
91
}
67
92
}
0 commit comments