From eba6192298e40add4d35d1587511d875f6d770e4 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 24 Nov 2024 14:12:59 +0000 Subject: [PATCH] fix clippy warnings + fmt --- crates/cli/src/run.rs | 63 ++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs index faf090c7..7251348c 100644 --- a/crates/cli/src/run.rs +++ b/crates/cli/src/run.rs @@ -11,14 +11,10 @@ pub async fn run(args: args::Args) -> Result, CollectError return handle_help_subcommands(args); } - let cryo_dir = build_cryo_directory(&args.output_dir.clone().into()); + let cryo_dir = build_cryo_directory(std::path::Path::new(&args.output_dir)); - - let args = if args.datatype.is_empty() { - load_or_remember_command(args, &cryo_dir)? - } else { - args - }; + let args = + if args.datatype.is_empty() { load_or_remember_command(args, &cryo_dir)? } else { args }; if args.remember { println!("remembering this command for future use\n"); @@ -35,16 +31,16 @@ fn is_help_command(args: &args::Args) -> bool { } /// Build the cryo directory path. -fn build_cryo_directory(output_dir: &std::path::PathBuf) -> std::path::PathBuf { +fn build_cryo_directory(output_dir: &std::path::Path) -> std::path::PathBuf { output_dir.join(".cryo") } /// Load a previously remembered command or return the current args. fn load_or_remember_command( mut args: args::Args, - cryo_dir: &std::path::PathBuf, + cryo_dir: &std::path::Path, ) -> Result { - let remembered = remember::load_remembered_command(cryo_dir.clone())?; + let remembered = remember::load_remembered_command(cryo_dir.to_path_buf())?; // Warn if the remembered command comes from a different Cryo version. if remembered.cryo_version != cryo_freeze::CRYO_VERSION { eprintln!("remembered command comes from a different Cryo version, proceed with caution\n"); @@ -54,35 +50,24 @@ fn load_or_remember_command( Ok(args) } - /// Print the remembered command to the console. fn print_remembered_command(command: &[String]) { println!( "{} {} {}", "remembering previous command:".truecolor(170, 170, 170), "cryo".bold().white(), - command - .iter() - .skip(1) - .cloned() - .collect::>() - .join(" ") - .white() - .bold() + command.iter().skip(1).cloned().collect::>().join(" ").white().bold() ); println!(); } /// Run the main freezing process with the provided arguments. -async fn run_freeze_process( - args: args::Args, -) -> Result, CollectError> { +async fn run_freeze_process(args: args::Args) -> Result, CollectError> { let t_start_parse = Some(SystemTime::now()); let (query, source, sink, env) = parse::parse_args(&args).await?; let source = Arc::new(source); - let env = ExecutionEnv {t_start_parse, ..env} - .set_start_time(); + let env = ExecutionEnv { t_start_parse, ..env }.set_start_time(); cryo_freeze::freeze(&query, &source, &sink, &env).await } @@ -109,8 +94,8 @@ fn print_general_help() { /// Print syntax help for block and transaction specification. fn print_syntax_help() { - let content = cstr!( - r#"Block specification syntax + let content = cstr!( + r#"Block specification syntax - can use numbers --blocks 5000 6000 7000 - can use ranges --blocks 12M:13M 15M:16M - can use a parquet file --blocks ./path/to/file.parquet[:COLUMN_NAME] @@ -128,16 +113,13 @@ fn print_syntax_help() { - can use a parquet file --txs ./path/to/file.parquet[:COLUMN_NAME] (default column name is transaction_hash) - can use multiple parquet files --txs ./path/to/ethereum__logs*.parquet"# - ); - println!("{}", content); + ); + println!("{}", content); } /// Handle detailed help by parsing schemas and printing dataset information. fn handle_detailed_help(args: args::Args) -> Result<(), CollectError> { - let args = args::Args { - datatype: args.datatype[1..].to_vec(), - ..args - }; + let args = args::Args { datatype: args.datatype[1..].to_vec(), ..args }; let (datatypes, schemas) = super::parse::schemas::parse_schemas(&args)?; for datatype in datatypes.into_iter() { @@ -159,24 +141,19 @@ mod tests { use super::*; use crate::args::Args; - #[test] + #[test] fn test_handle_help_subcommands_general_help() { - let args = Args { - datatype: vec!["help".to_string()], - ..Default::default() - }; + let args = Args { datatype: vec!["help".to_string()], ..Default::default() }; let result = handle_help_subcommands(args); assert!(result.is_ok()); } - #[test] + #[test] fn test_handle_help_subcommands_syntax_help() { - let args = Args { - datatype: vec!["help".to_string(), "syntax".to_string()], - ..Default::default() - }; + let args = + Args { datatype: vec!["help".to_string(), "syntax".to_string()], ..Default::default() }; let result = handle_help_subcommands(args); @@ -194,4 +171,4 @@ mod tests { assert!(result.is_ok()); } -} \ No newline at end of file +}