@@ -4,85 +4,88 @@ use log::LevelFilter;
4
4
5
5
#[ derive( Debug ) ]
6
6
pub enum SupportedLanguage {
7
- Rust ,
8
- Node ,
9
- Shell
7
+ Rust ,
8
+ Node ,
9
+ Shell ,
10
10
}
11
11
12
12
impl std:: fmt:: Display for SupportedLanguage {
13
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
14
- match self {
15
- SupportedLanguage :: Rust => write ! ( f, "rust" ) ,
16
- SupportedLanguage :: Node => write ! ( f, "node" ) ,
17
- SupportedLanguage :: Shell => write ! ( f, "shell" )
13
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
14
+ match self {
15
+ SupportedLanguage :: Rust => write ! ( f, "rust" ) ,
16
+ SupportedLanguage :: Node => write ! ( f, "node" ) ,
17
+ SupportedLanguage :: Shell => write ! ( f, "shell" ) ,
18
+ }
18
19
}
19
- }
20
20
}
21
21
22
22
#[ derive( Debug ) ]
23
23
pub struct Cli {
24
- pub watch_patterns : Vec < String > , // file patterns to watch
25
- pub project_language : SupportedLanguage ,
26
- pub exec_commands : Vec < String > , // list of commands to run
24
+ pub watch_patterns : Vec < String > , // file patterns to watch
25
+ pub project_language : SupportedLanguage ,
26
+ pub exec_commands : Vec < String > , // list of commands to run
27
27
}
28
28
29
29
impl Cli {
30
- pub fn new ( ) -> Self {
31
- let yaml = load_yaml ! ( "cli.yaml" ) ;
32
- let matches: ArgMatches = App :: from_yaml ( yaml) . get_matches ( ) ;
33
-
34
- if matches. is_present ( "verbose" ) {
35
- Builder :: new ( ) . filter_level ( LevelFilter :: Debug ) . init ( ) ;
36
- } else {
37
- Builder :: new ( ) . filter_level ( LevelFilter :: Info ) . init ( ) ;
38
- }
39
-
40
- let mut watch_patterns: Vec < String > = Vec :: new ( ) ;
41
- let project_language: SupportedLanguage ;
42
- let mut exec_commands: Vec < String > = Vec :: new ( ) ;
43
-
44
- match matches. subcommand ( ) {
45
- ( "rust" , Some ( _) ) =>{
46
- debug ! ( "Configuring for rust mode..." ) ;
47
- project_language = SupportedLanguage :: Rust ;
48
- watch_patterns. push ( "*.rs" . to_string ( ) ) ;
49
- watch_patterns. push ( "Cargo.toml" . to_string ( ) ) ;
50
- exec_commands. push ( "cargo build" . to_string ( ) ) ;
51
- exec_commands. push ( "cargo run" . to_string ( ) ) ;
52
- } ,
53
- ( "node" , Some ( _) ) =>{
54
- debug ! ( "Configuring for node mode..." ) ;
55
- project_language = SupportedLanguage :: Node ;
56
- watch_patterns. push ( "*.js" . to_string ( ) ) ;
57
- watch_patterns. push ( "*.jsx" . to_string ( ) ) ;
58
- exec_commands. push ( "npm start" . to_string ( ) ) ;
59
- } ,
60
- ( "python" , Some ( _) ) =>{
61
- error ! ( "Argument configuration not yet supported!" ) ;
62
- std:: process:: exit ( 1 ) ;
63
- } ,
64
- ( "shell" , Some ( sub_matcher) ) => {
65
- debug ! ( "Configuring for shell mode..." ) ;
66
- project_language = SupportedLanguage :: Shell ;
67
- debug ! ( "Script Path = {:?}" , sub_matcher. value_of( "script" ) ) ;
68
- debug ! ( "Watch Pattern = {:?}" , sub_matcher. value_of( "watch" ) ) ;
69
- let split = sub_matcher. value_of ( "watch" ) . unwrap ( ) . split ( "," ) ;
70
- for s in split{
71
- watch_patterns. push ( format ! ( "*{}" , s. to_string( ) ) ) ;
30
+ pub fn new ( ) -> Self {
31
+ let yaml = load_yaml ! ( "cli.yaml" ) ;
32
+ let matches: ArgMatches = App :: from_yaml ( yaml) . get_matches ( ) ;
33
+
34
+ if matches. is_present ( "verbose" ) {
35
+ Builder :: new ( ) . filter_level ( LevelFilter :: Debug ) . init ( ) ;
36
+ } else {
37
+ Builder :: new ( ) . filter_level ( LevelFilter :: Info ) . init ( ) ;
72
38
}
73
- exec_commands. push ( format ! ( "bash {}" , sub_matcher. value_of( "script" ) . unwrap( ) ) . to_string ( ) ) ;
74
- debug ! ( "{:?}" , exec_commands) ;
75
- } ,
76
- _ => {
77
- error ! ( "Argument configuration not yet supported!" ) ;
78
- std:: process:: exit ( 1 ) ;
79
- }
80
39
81
- }
82
-
83
- let ret = Cli { watch_patterns, project_language, exec_commands } ;
84
- debug ! ( "Parsed params = {:?}" , ret) ;
40
+ let mut watch_patterns: Vec < String > = Vec :: new ( ) ;
41
+ let project_language: SupportedLanguage ;
42
+ let mut exec_commands: Vec < String > = Vec :: new ( ) ;
85
43
86
- ret
87
- }
44
+ match matches. subcommand ( ) {
45
+ ( "rust" , Some ( _) ) => {
46
+ debug ! ( "Configuring for rust mode..." ) ;
47
+ project_language = SupportedLanguage :: Rust ;
48
+ watch_patterns. push ( "*.rs" . to_string ( ) ) ;
49
+ watch_patterns. push ( "Cargo.toml" . to_string ( ) ) ;
50
+ exec_commands. push ( "cargo build" . to_string ( ) ) ;
51
+ exec_commands. push ( "cargo run" . to_string ( ) ) ;
52
+ }
53
+ ( "node" , Some ( _) ) => {
54
+ debug ! ( "Configuring for node mode..." ) ;
55
+ project_language = SupportedLanguage :: Node ;
56
+ watch_patterns. push ( "*.js" . to_string ( ) ) ;
57
+ watch_patterns. push ( "*.jsx" . to_string ( ) ) ;
58
+ exec_commands. push ( "npm start" . to_string ( ) ) ;
59
+ }
60
+ ( "python" , Some ( _) ) => {
61
+ error ! ( "Argument configuration not yet supported!" ) ;
62
+ std:: process:: exit ( 1 ) ;
63
+ }
64
+ ( "shell" , Some ( sub_matcher) ) => {
65
+ debug ! ( "Configuring for shell mode..." ) ;
66
+ project_language = SupportedLanguage :: Shell ;
67
+ debug ! ( "Script Path = {:?}" , sub_matcher. value_of( "script" ) ) ;
68
+ debug ! ( "Watch Pattern = {:?}" , sub_matcher. value_of( "watch" ) ) ;
69
+ let split = sub_matcher. value_of ( "watch" ) . unwrap ( ) . split ( ',' ) ;
70
+ for s in split {
71
+ watch_patterns. push ( format ! ( "*{}" , s. to_string( ) ) ) ;
72
+ }
73
+ exec_commands. push ( format ! ( "bash {}" , sub_matcher. value_of( "script" ) . unwrap( ) ) ) ;
74
+ debug ! ( "{:?}" , exec_commands) ;
75
+ }
76
+ _ => {
77
+ error ! ( "Argument configuration not yet supported!" ) ;
78
+ std:: process:: exit ( 1 ) ;
79
+ }
80
+ }
81
+
82
+ let ret = Cli {
83
+ watch_patterns,
84
+ project_language,
85
+ exec_commands,
86
+ } ;
87
+ debug ! ( "Parsed params = {:?}" , ret) ;
88
+
89
+ ret
90
+ }
88
91
}
0 commit comments