1+ use crate :: table:: * ;
12use clap:: { Parser as ClapParser , Subcommand } ;
3+ use colored:: * ;
4+ use notify:: { Event , EventKind , RecursiveMode , Watcher , recommended_watcher} ;
25use reader:: parser:: Parser ;
3- use notify:: { Watcher , RecursiveMode , Event , EventKind , recommended_watcher} ;
46use std:: sync:: mpsc:: channel;
5- use colored:: * ;
6- use crate :: table:: * ;
7- use serde_json;
87
98mod table;
109
@@ -71,28 +70,28 @@ fn main() {
7170 Commands :: Feature { name, path } => {
7271 let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
7372
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+ }
9695 }
9796 Commands :: Definition { name, path } => {
9897 let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
@@ -109,7 +108,12 @@ fn main() {
109108 Commands :: Watch { path } => {
110109 let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
111110
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+ ) ;
113117 println ! ( "{}" , "Press Ctrl+C to stop watching..." . dimmed( ) ) ;
114118
115119 {
@@ -126,30 +130,42 @@ fn main() {
126130 // Set up file watcher
127131 let ( tx, rx) = channel ( ) ;
128132 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 ( ) ;
130136
131137 loop {
132138 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 ) ;
150165 }
151- }
152- Err ( e) => println ! ( "Watch error: {:?}" , e) ,
166+ _ => { }
167+ } ,
168+ Err ( e) => println ! ( "Watch error: {e:?}" ) ,
153169 }
154170 }
155171 }
@@ -159,7 +175,12 @@ fn main() {
159175fn search_and_display_definitions ( search_name : & str , parser : & Parser ) {
160176 let mut found_any = false ;
161177 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+ ) ;
163184 println ! ( "{}" , "─" . repeat( 60 ) . dimmed( ) ) ;
164185
165186 for feature in & parser. features {
@@ -217,7 +238,11 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
217238 let mut index = 0 ;
218239 for line in json. lines ( ) {
219240 index += 1 ;
220- println ! ( "{} {}" , format!( "{}:" , index) . bright_blue( ) , line. bright_green( ) ) ;
241+ println ! (
242+ "{} {}" ,
243+ format!( "{index}:" ) . bright_blue( ) ,
244+ line. bright_green( )
245+ ) ;
221246 }
222247 }
223248 Err ( _) => println ! ( "{}" , "Error serializing RuntimeFunction" . red( ) ) ,
@@ -227,9 +252,17 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
227252 }
228253
229254 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+ ) ;
231261 } else {
232262 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+ ) ;
234267 }
235268}
0 commit comments