1
1
use crate :: formatter:: { format_header_line, format_line} ;
2
2
use anyhow:: { anyhow, Result } ;
3
- use std:: collections:: HashMap ;
4
- use std:: ffi:: OsString ;
5
- use std:: process;
3
+ use std:: { collections:: HashMap , ffi:: OsString , process} ;
6
4
7
5
pub fn possible_forc_commands ( ) -> Vec < String > {
8
- let mut possible_commands = Vec :: new ( ) ;
9
6
let output = process:: Command :: new ( "forc" )
10
7
. arg ( "--help" )
11
8
. output ( )
@@ -14,18 +11,28 @@ pub fn possible_forc_commands() -> Vec<String> {
14
11
let output_str = String :: from_utf8_lossy ( & output. stdout ) ;
15
12
let lines = output_str. lines ( ) ;
16
13
17
- let mut has_parsed_subcommand_header = false ;
14
+ let mut possible_commands = Vec :: new ( ) ;
15
+ let mut in_commands_section = false ;
18
16
19
17
for line in lines {
20
- if has_parsed_subcommand_header {
21
- let ( command, _) = line. trim ( ) . split_once ( ' ' ) . unwrap_or ( ( "" , "" ) ) ;
22
- possible_commands. push ( command. to_string ( ) ) ;
18
+ if line. trim ( ) == "Commands:" {
19
+ // Start of commands section
20
+ in_commands_section = true ;
21
+ continue ;
23
22
}
24
- if line == "SUBCOMMANDS:" {
25
- has_parsed_subcommand_header = true ;
23
+
24
+ if in_commands_section {
25
+ if line. trim ( ) . is_empty ( ) || line. trim ( ) . starts_with ( "Options:" ) {
26
+ // End of commands section
27
+ break ;
28
+ }
29
+
30
+ // Extract command name (first word of the line)
31
+ if let Some ( command) = line. trim ( ) . split_whitespace ( ) . next ( ) {
32
+ possible_commands. push ( command. to_string ( ) ) ;
33
+ }
26
34
}
27
35
}
28
-
29
36
possible_commands
30
37
}
31
38
0 commit comments