Skip to content

Commit

Permalink
fix clippy warnings + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sslivkoff committed Nov 24, 2024
1 parent ef34912 commit eba6192
Showing 1 changed file with 20 additions and 43 deletions.
63 changes: 20 additions & 43 deletions crates/cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ pub async fn run(args: args::Args) -> Result<Option<FreezeSummary>, 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");
Expand All @@ -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<args::Args, CollectError> {
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");
Expand All @@ -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::<Vec<_>>()
.join(" ")
.white()
.bold()
command.iter().skip(1).cloned().collect::<Vec<_>>().join(" ").white().bold()
);
println!();
}

/// Run the main freezing process with the provided arguments.
async fn run_freeze_process(
args: args::Args,
) -> Result<Option<FreezeSummary>, CollectError> {
async fn run_freeze_process(args: args::Args) -> Result<Option<FreezeSummary>, 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
}
Expand All @@ -109,8 +94,8 @@ fn print_general_help() {

/// Print syntax help for block and transaction specification.
fn print_syntax_help() {
let content = cstr!(
r#"<white><bold>Block specification syntax</bold></white>
let content = cstr!(
r#"<white><bold>Block specification syntax</bold></white>
- can use numbers <white><bold>--blocks 5000 6000 7000</bold></white>
- can use ranges <white><bold>--blocks 12M:13M 15M:16M</bold></white>
- can use a parquet file <white><bold>--blocks ./path/to/file.parquet[:COLUMN_NAME]</bold></white>
Expand All @@ -128,16 +113,13 @@ fn print_syntax_help() {
- can use a parquet file <white><bold>--txs ./path/to/file.parquet[:COLUMN_NAME]</bold></white>
(default column name is <white><bold>transaction_hash</bold></white>)
- can use multiple parquet files <white><bold>--txs ./path/to/ethereum__logs*.parquet</bold></white>"#
);
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() {
Expand All @@ -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);

Expand All @@ -194,4 +171,4 @@ mod tests {

assert!(result.is_ok());
}
}
}

0 comments on commit eba6192

Please sign in to comment.