1
+ use crate :: table:: * ;
1
2
use clap:: { Parser as ClapParser , Subcommand } ;
3
+ use colored:: * ;
4
+ use notify:: { Event , EventKind , RecursiveMode , Watcher , recommended_watcher} ;
2
5
use reader:: parser:: Parser ;
3
- use notify:: { Watcher , RecursiveMode , Event , EventKind , recommended_watcher} ;
4
6
use std:: sync:: mpsc:: channel;
5
- use colored:: * ;
6
- use crate :: table:: * ;
7
- use serde_json;
8
7
9
8
mod table;
10
9
@@ -71,28 +70,28 @@ fn main() {
71
70
Commands :: Feature { name, path } => {
72
71
let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
73
72
74
- let parser = match Parser :: from_path ( dir_path. as_str ( ) ) {
75
- Some ( reader) => reader,
76
- None => {
77
- panic ! ( "Error reading definitions" ) ;
78
- }
79
- } ;
80
-
81
- if let Some ( feature_name) = name {
82
- let mut features_to_report = Vec :: new ( ) ;
83
- for feature in & parser. features {
84
- if feature. name == feature_name {
85
- feature_table ( & feature) ;
86
- features_to_report. push ( feature. clone ( ) ) ;
87
- }
88
- }
89
- summary_table ( & features_to_report) ;
90
- } else {
91
- for feature in & parser. features {
92
- feature_table ( & feature) ;
93
- }
94
- summary_table ( & parser. features ) ;
95
- }
73
+ let parser = match Parser :: from_path ( dir_path. as_str ( ) ) {
74
+ Some ( reader) => reader,
75
+ None => {
76
+ panic ! ( "Error reading definitions" ) ;
77
+ }
78
+ } ;
79
+
80
+ if let Some ( feature_name) = name {
81
+ let mut features_to_report = Vec :: new ( ) ;
82
+ for feature in & parser. features {
83
+ if feature. name == feature_name {
84
+ feature_table ( feature) ;
85
+ features_to_report. push ( feature. clone ( ) ) ;
86
+ }
87
+ }
88
+ summary_table ( & features_to_report) ;
89
+ } else {
90
+ for feature in & parser. features {
91
+ feature_table ( feature) ;
92
+ }
93
+ summary_table ( & parser. features ) ;
94
+ }
96
95
}
97
96
Commands :: Definition { name, path } => {
98
97
let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
@@ -109,7 +108,12 @@ fn main() {
109
108
Commands :: Watch { path } => {
110
109
let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
111
110
112
- println ! ( "{}" , format!( "Watching directory: {}" , dir_path) . bright_yellow( ) . bold( ) ) ;
111
+ println ! (
112
+ "{}" ,
113
+ format!( "Watching directory: {dir_path}" )
114
+ . bright_yellow( )
115
+ . bold( )
116
+ ) ;
113
117
println ! ( "{}" , "Press Ctrl+C to stop watching..." . dimmed( ) ) ;
114
118
115
119
{
@@ -126,30 +130,42 @@ fn main() {
126
130
// Set up file watcher
127
131
let ( tx, rx) = channel ( ) ;
128
132
let mut watcher = recommended_watcher ( tx) . unwrap ( ) ;
129
- watcher. watch ( std:: path:: Path :: new ( & dir_path) , RecursiveMode :: Recursive ) . unwrap ( ) ;
133
+ watcher
134
+ . watch ( std:: path:: Path :: new ( & dir_path) , RecursiveMode :: Recursive )
135
+ . unwrap ( ) ;
130
136
131
137
loop {
132
138
match rx. recv ( ) {
133
- Ok ( event) => {
134
- match event {
135
- Ok ( Event { kind : EventKind :: Create ( _) , .. } ) |
136
- Ok ( Event { kind : EventKind :: Modify ( _) , .. } ) |
137
- Ok ( Event { kind : EventKind :: Remove ( _) , .. } ) => {
138
- println ! ( "\n {}" , "Change detected! Regenerating report..." . bright_yellow( ) ) ;
139
-
140
- let parser = match Parser :: from_path ( dir_path. as_str ( ) ) {
141
- Some ( reader) => reader,
142
- None => {
143
- panic ! ( "Error reading definitions" ) ;
144
- }
145
- } ;
146
-
147
- error_table ( & parser. features ) ;
148
- }
149
- _ => { }
139
+ Ok ( event) => match event {
140
+ Ok ( Event {
141
+ kind : EventKind :: Create ( _) ,
142
+ ..
143
+ } )
144
+ | Ok ( Event {
145
+ kind : EventKind :: Modify ( _) ,
146
+ ..
147
+ } )
148
+ | Ok ( Event {
149
+ kind : EventKind :: Remove ( _) ,
150
+ ..
151
+ } ) => {
152
+ println ! (
153
+ "\n {}" ,
154
+ "Change detected! Regenerating report..." . bright_yellow( )
155
+ ) ;
156
+
157
+ let parser = match Parser :: from_path ( dir_path. as_str ( ) ) {
158
+ Some ( reader) => reader,
159
+ None => {
160
+ panic ! ( "Error reading definitions" ) ;
161
+ }
162
+ } ;
163
+
164
+ error_table ( & parser. features ) ;
150
165
}
151
- }
152
- Err ( e) => println ! ( "Watch error: {:?}" , e) ,
166
+ _ => { }
167
+ } ,
168
+ Err ( e) => println ! ( "Watch error: {e:?}" ) ,
153
169
}
154
170
}
155
171
}
@@ -159,7 +175,12 @@ fn main() {
159
175
fn search_and_display_definitions ( search_name : & str , parser : & Parser ) {
160
176
let mut found_any = false ;
161
177
let mut total_matches = 0 ;
162
- println ! ( "{}" , format!( "Searching for definitions matching: '{}'" , search_name) . bright_yellow( ) . bold( ) ) ;
178
+ println ! (
179
+ "{}" ,
180
+ format!( "Searching for definitions matching: '{search_name}'" )
181
+ . bright_yellow( )
182
+ . bold( )
183
+ ) ;
163
184
println ! ( "{}" , "─" . repeat( 60 ) . dimmed( ) ) ;
164
185
165
186
for feature in & parser. features {
@@ -217,7 +238,11 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
217
238
let mut index = 0 ;
218
239
for line in json. lines ( ) {
219
240
index += 1 ;
220
- println ! ( "{} {}" , format!( "{}:" , index) . bright_blue( ) , line. bright_green( ) ) ;
241
+ println ! (
242
+ "{} {}" ,
243
+ format!( "{index}:" ) . bright_blue( ) ,
244
+ line. bright_green( )
245
+ ) ;
221
246
}
222
247
}
223
248
Err ( _) => println ! ( "{}" , "Error serializing RuntimeFunction" . red( ) ) ,
@@ -227,9 +252,17 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
227
252
}
228
253
229
254
if !found_any {
230
- println ! ( "\n {}" , format!( "No definitions found matching '{}'" , search_name) . red( ) . bold( ) ) ;
255
+ println ! (
256
+ "\n {}" ,
257
+ format!( "No definitions found matching '{search_name}'" )
258
+ . red( )
259
+ . bold( )
260
+ ) ;
231
261
} else {
232
262
println ! ( "\n {}" , "─" . repeat( 60 ) . dimmed( ) ) ;
233
- println ! ( "{}" , format!( "Found {} matching definition(s)" , total_matches) . bright_yellow( ) ) ;
263
+ println ! (
264
+ "{}" ,
265
+ format!( "Found {total_matches} matching definition(s)" ) . bright_yellow( )
266
+ ) ;
234
267
}
235
268
}
0 commit comments