@@ -32,7 +32,7 @@ pub struct CliArgs {
3232}
3333
3434/// Supported SQL dialect types
35- #[ derive( Debug , Clone , PartialEq ) ]
35+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
3636pub enum SqlDialectType {
3737 PostgreSql ,
3838 MySql ,
@@ -43,10 +43,10 @@ pub enum SqlDialectType {
4343impl std:: fmt:: Display for SqlDialectType {
4444 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
4545 match self {
46- SqlDialectType :: PostgreSql => write ! ( f, "postgresql" ) ,
47- SqlDialectType :: MySql => write ! ( f, "mysql" ) ,
48- SqlDialectType :: Sqlite => write ! ( f, "sqlite" ) ,
49- SqlDialectType :: DuckDb => write ! ( f, "duckdb" ) ,
46+ Self :: PostgreSql => write ! ( f, "postgresql" ) ,
47+ Self :: MySql => write ! ( f, "mysql" ) ,
48+ Self :: Sqlite => write ! ( f, "sqlite" ) ,
49+ Self :: DuckDb => write ! ( f, "duckdb" ) ,
5050 }
5151 }
5252}
@@ -56,10 +56,10 @@ impl std::str::FromStr for SqlDialectType {
5656
5757 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
5858 match s. to_lowercase ( ) . as_str ( ) {
59- "postgresql" | "postgres" | "pg" => Ok ( SqlDialectType :: PostgreSql ) ,
60- "mysql" => Ok ( SqlDialectType :: MySql ) ,
61- "sqlite" => Ok ( SqlDialectType :: Sqlite ) ,
62- "duckdb" | "duck" => Ok ( SqlDialectType :: DuckDb ) ,
59+ "postgresql" | "postgres" | "pg" => Ok ( Self :: PostgreSql ) ,
60+ "mysql" => Ok ( Self :: MySql ) ,
61+ "sqlite" => Ok ( Self :: Sqlite ) ,
62+ "duckdb" | "duck" => Ok ( Self :: DuckDb ) ,
6363 _ => Err ( format ! ( "Unsupported SQL dialect: {s}" ) ) ,
6464 }
6565 }
@@ -200,7 +200,7 @@ fn create_dialect(dialect_type: &SqlDialectType) -> Box<dyn SqlDialect> {
200200}
201201
202202/// CLI operation modes
203- #[ derive( Debug , Clone , PartialEq ) ]
203+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
204204pub enum CliMode {
205205 /// File-based processing mode
206206 FileMode {
@@ -248,26 +248,28 @@ impl CliConfig {
248248
249249 /// Determine the CLI mode based on arguments
250250 fn determine_mode ( args : & CliArgs ) -> CliMode {
251- if let Some ( ref input_text) = args. input_text {
252- CliMode :: TextMode {
251+ args. input_text . as_ref ( ) . map_or_else (
252+ || {
253+ args. input_file . as_ref ( ) . map_or (
254+ CliMode :: StdinMode {
255+ validate_only : args. validate_only ,
256+ streaming : false , // Future extension
257+ } ,
258+ |input_file| CliMode :: FileMode {
259+ input_file : input_file. clone ( ) ,
260+ output_file : args. output_file . clone ( ) ,
261+ } ,
262+ )
263+ } ,
264+ |input_text| CliMode :: TextMode {
253265 input_text : input_text. clone ( ) ,
254266 output_file : args. output_file . clone ( ) ,
255- }
256- } else if let Some ( ref input_file) = args. input_file {
257- CliMode :: FileMode {
258- input_file : input_file. clone ( ) ,
259- output_file : args. output_file . clone ( ) ,
260- }
261- } else {
262- CliMode :: StdinMode {
263- validate_only : args. validate_only ,
264- streaming : false , // Future extension
265- }
266- }
267+ } ,
268+ )
267269 }
268270
269271 /// Determine output format based on arguments
270- fn determine_output_format ( args : & CliArgs ) -> OutputFormat {
272+ const fn determine_output_format ( args : & CliArgs ) -> OutputFormat {
271273 if args. json_output {
272274 OutputFormat :: Json
273275 } else if args. compact {
@@ -630,24 +632,20 @@ impl ProcessingPipeline {
630632
631633 /// Check if processing should continue (signal handling)
632634 pub fn should_continue ( & self ) -> bool {
633- if let Some ( ref handler) = self . signal_handler {
634- !handler. should_shutdown ( )
635- } else {
636- true
637- }
635+ self . signal_handler
636+ . as_ref ( )
637+ . is_none_or ( |handler| !handler. should_shutdown ( ) )
638638 }
639639
640640 /// Check if the output pipe was closed
641641 pub fn pipe_closed ( & self ) -> bool {
642- if let Some ( ref handler) = self . signal_handler {
643- handler. pipe_closed ( )
644- } else {
645- false
646- }
642+ self . signal_handler
643+ . as_ref ( )
644+ . is_some_and ( |handler| handler. pipe_closed ( ) )
647645 }
648646
649647 /// Get configuration reference
650- pub fn config ( & self ) -> & CliConfig {
648+ pub const fn config ( & self ) -> & CliConfig {
651649 & self . config
652650 }
653651}
0 commit comments