1+ use crate :: table:: * ;
12use clap:: { Parser as ClapParser , Subcommand } ;
2- use reader:: parser:: Parser ;
3- use notify:: { Watcher , RecursiveMode , Event , EventKind , recommended_watcher} ;
4- use std:: sync:: mpsc:: channel;
53use colored:: * ;
6- use crate :: table:: * ;
4+ use notify:: { Event , EventKind , RecursiveMode , Watcher , recommended_watcher} ;
5+ use reader:: parser:: Parser ;
76use serde_json;
7+ use std:: sync:: mpsc:: channel;
88
99mod table;
1010
@@ -71,28 +71,28 @@ fn main() {
7171 Commands :: Feature { name, path } => {
7272 let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
7373
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- }
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+ }
9696 }
9797 Commands :: Definition { name, path } => {
9898 let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
@@ -109,7 +109,12 @@ fn main() {
109109 Commands :: Watch { path } => {
110110 let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
111111
112- println ! ( "{}" , format!( "Watching directory: {}" , dir_path) . bright_yellow( ) . bold( ) ) ;
112+ println ! (
113+ "{}" ,
114+ format!( "Watching directory: {}" , dir_path)
115+ . bright_yellow( )
116+ . bold( )
117+ ) ;
113118 println ! ( "{}" , "Press Ctrl+C to stop watching..." . dimmed( ) ) ;
114119
115120 {
@@ -126,29 +131,41 @@ fn main() {
126131 // Set up file watcher
127132 let ( tx, rx) = channel ( ) ;
128133 let mut watcher = recommended_watcher ( tx) . unwrap ( ) ;
129- watcher. watch ( std:: path:: Path :: new ( & dir_path) , RecursiveMode :: Recursive ) . unwrap ( ) ;
134+ watcher
135+ . watch ( std:: path:: Path :: new ( & dir_path) , RecursiveMode :: Recursive )
136+ . unwrap ( ) ;
130137
131138 loop {
132139 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- _ => { }
140+ Ok ( event) => match event {
141+ Ok ( Event {
142+ kind : EventKind :: Create ( _) ,
143+ ..
144+ } )
145+ | Ok ( Event {
146+ kind : EventKind :: Modify ( _) ,
147+ ..
148+ } )
149+ | Ok ( Event {
150+ kind : EventKind :: Remove ( _) ,
151+ ..
152+ } ) => {
153+ println ! (
154+ "\n {}" ,
155+ "Change detected! Regenerating report..." . bright_yellow( )
156+ ) ;
157+
158+ let parser = match Parser :: from_path ( dir_path. as_str ( ) ) {
159+ Some ( reader) => reader,
160+ None => {
161+ panic ! ( "Error reading definitions" ) ;
162+ }
163+ } ;
164+
165+ error_table ( & parser. features ) ;
150166 }
151- }
167+ _ => { }
168+ } ,
152169 Err ( e) => println ! ( "Watch error: {:?}" , e) ,
153170 }
154171 }
@@ -159,7 +176,12 @@ fn main() {
159176fn search_and_display_definitions ( search_name : & str , parser : & Parser ) {
160177 let mut found_any = false ;
161178 let mut total_matches = 0 ;
162- println ! ( "{}" , format!( "Searching for definitions matching: '{}'" , search_name) . bright_yellow( ) . bold( ) ) ;
179+ println ! (
180+ "{}" ,
181+ format!( "Searching for definitions matching: '{}'" , search_name)
182+ . bright_yellow( )
183+ . bold( )
184+ ) ;
163185 println ! ( "{}" , "─" . repeat( 60 ) . dimmed( ) ) ;
164186
165187 for feature in & parser. features {
@@ -217,7 +239,11 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
217239 let mut index = 0 ;
218240 for line in json. lines ( ) {
219241 index += 1 ;
220- println ! ( "{} {}" , format!( "{}:" , index) . bright_blue( ) , line. bright_green( ) ) ;
242+ println ! (
243+ "{} {}" ,
244+ format!( "{}:" , index) . bright_blue( ) ,
245+ line. bright_green( )
246+ ) ;
221247 }
222248 }
223249 Err ( _) => println ! ( "{}" , "Error serializing RuntimeFunction" . red( ) ) ,
@@ -227,9 +253,17 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
227253 }
228254
229255 if !found_any {
230- println ! ( "\n {}" , format!( "No definitions found matching '{}'" , search_name) . red( ) . bold( ) ) ;
256+ println ! (
257+ "\n {}" ,
258+ format!( "No definitions found matching '{}'" , search_name)
259+ . red( )
260+ . bold( )
261+ ) ;
231262 } else {
232263 println ! ( "\n {}" , "─" . repeat( 60 ) . dimmed( ) ) ;
233- println ! ( "{}" , format!( "Found {} matching definition(s)" , total_matches) . bright_yellow( ) ) ;
264+ println ! (
265+ "{}" ,
266+ format!( "Found {} matching definition(s)" , total_matches) . bright_yellow( )
267+ ) ;
234268 }
235269}
0 commit comments