1+ use anyhow:: Result ;
12use clap:: { Parser , Subcommand } ;
3+ use colored:: Colorize ;
24use gasguard_engine:: { ContractScanner , ScanAnalyzer } ;
35use std:: path:: PathBuf ;
4- use anyhow:: Result ;
56
67#[ derive( Parser ) ]
78#[ command( name = "gasguard" ) ]
@@ -45,17 +46,17 @@ async fn main() -> Result<()> {
4546 match cli. command {
4647 Commands :: Scan { file, format } => {
4748 println ! ( "🔍 Scanning file: {:?}" , file) ;
48-
49+
4950 let result = scanner. scan_file ( & file) ?;
50-
51+
5152 match format. as_str ( ) {
5253 "json" => {
5354 println ! ( "{}" , result. to_json( ) ?) ;
5455 }
5556 _ => {
5657 println ! ( "{}" , ScanAnalyzer :: format_violations( & result. violations) ) ;
5758 println ! ( "{}" , ScanAnalyzer :: generate_summary( & result. violations) ) ;
58-
59+
5960 if !result. violations . is_empty ( ) {
6061 let savings = ScanAnalyzer :: calculate_storage_savings ( & result. violations ) ;
6162 println ! ( "\n {}" , savings) ;
@@ -65,16 +66,16 @@ async fn main() -> Result<()> {
6566 }
6667 Commands :: ScanDir { directory, format } => {
6768 println ! ( "🔍 Scanning directory: {:?}" , directory) ;
68-
69+
6970 let results = scanner. scan_directory ( & directory) ?;
70-
71+
7172 if results. is_empty ( ) {
7273 println ! ( "✅ No violations found in any files!" ) ;
7374 return Ok ( ( ) ) ;
7475 }
75-
76+
7677 let total_violations: usize = results. iter ( ) . map ( |r| r. violations . len ( ) ) . sum ( ) ;
77-
78+
7879 match format. as_str ( ) {
7980 "json" => {
8081 println ! ( "{}" , serde_json:: to_string_pretty( & results) ?) ;
@@ -84,49 +85,62 @@ async fn main() -> Result<()> {
8485 println ! ( "\n 📁 File: {}" , result. source) ;
8586 println ! ( "{}" , ScanAnalyzer :: format_violations( & result. violations) ) ;
8687 }
87-
88- println ! ( "\n {}" , format!( "📊 Total violations across {} files: {}" , results. len( ) , total_violations) . bold( ) ) ;
89-
90- let all_violations: Vec < _ > = results. iter ( ) . flat_map ( |r| r. violations . clone ( ) ) . collect ( ) ;
88+
89+ println ! (
90+ "\n {}" ,
91+ format!(
92+ "📊 Total violations across {} files: {}" ,
93+ results. len( ) ,
94+ total_violations
95+ )
96+ . bold( )
97+ ) ;
98+
99+ let all_violations: Vec < _ > =
100+ results. iter ( ) . flat_map ( |r| r. violations . clone ( ) ) . collect ( ) ;
91101 let savings = ScanAnalyzer :: calculate_storage_savings ( & all_violations) ;
92102 println ! ( "\n {}" , savings) ;
93103 }
94104 }
95105 }
96106 Commands :: Analyze { path } => {
97107 println ! ( "📊 Analyzing storage optimization potential: {:?}" , path) ;
98-
108+
99109 let results = if path. is_file ( ) {
100110 vec ! [ scanner. scan_file( & path) ?]
101111 } else {
102112 scanner. scan_directory ( & path) ?
103113 } ;
104-
114+
105115 if results. is_empty ( ) {
106116 println ! ( "✅ No optimization opportunities found!" ) ;
107117 return Ok ( ( ) ) ;
108118 }
109-
110- let all_violations: Vec < _ > = results. iter ( ) . flat_map ( |r| r. violations . clone ( ) ) . collect ( ) ;
119+
120+ let all_violations: Vec < _ > =
121+ results. iter ( ) . flat_map ( |r| r. violations . clone ( ) ) . collect ( ) ;
111122 let savings = ScanAnalyzer :: calculate_storage_savings ( & all_violations) ;
112-
123+
113124 println ! ( "\n 🎯 Storage Analysis Report" ) ;
114125 println ! ( "========================" ) ;
115126 println ! ( "Files analyzed: {}" , results. len( ) ) ;
116127 println ! ( "Total violations: {}" , all_violations. len( ) ) ;
117128 println ! ( "\n {}" , savings) ;
118-
129+
119130 // Group violations by type
120131 let mut unused_vars = 0 ;
121132 for violation in & all_violations {
122133 if violation. rule_name == "unused-state-variables" {
123134 unused_vars += 1 ;
124135 }
125136 }
126-
137+
127138 if unused_vars > 0 {
128139 println ! ( "\n 🔧 Recommendations:" ) ;
129- println ! ( " • Remove {} unused state variables to reduce storage costs" , unused_vars) ;
140+ println ! (
141+ " • Remove {} unused state variables to reduce storage costs" ,
142+ unused_vars
143+ ) ;
130144 println ! ( " • Consider using more efficient data types where possible" ) ;
131145 println ! ( " • Implement lazy loading patterns for rarely accessed data" ) ;
132146 }
0 commit comments