Skip to content

Commit

Permalink
small refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISCARLON committed Oct 12, 2024
1 parent 3420661 commit 512e3a2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Cli {
command: Commands,
}

// Define Commands
#[derive(Subcommand, Debug)]
enum Commands {
/// Display basic information about an Excel file
Expand Down Expand Up @@ -59,6 +60,7 @@ enum Commands {
BasicCsv { url: String },
}

// Call commands and file logic
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
match &cli.command {
Expand All @@ -72,16 +74,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

// file logic
fn process_json(url: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;

let pb = create_progress_bar("Processing JSON...");
let result = analyze_json_nesting(url);

pb.finish_with_message("JSON Processed");
result
}

fn process_excel(url: &str, operation: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;

let pb = create_progress_bar(&format!("Processing Excel {}...", operation));
let bytes = fetch_remote_file(url)?;

Expand All @@ -101,10 +107,12 @@ fn process_excel_with_header(
header_index: usize,
) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;

let pb = create_progress_bar(&format!(
"Processing Excel with header set at INDEX {}...",
header_index
));

let bytes = fetch_remote_file(url)?;
let result = display_remote_basic_info_specify_header_idx(bytes, header_index);
pb.finish_with_message("Excel processing with header complete");
Expand All @@ -113,9 +121,11 @@ fn process_excel_with_header(

fn process_view_bytes(url: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;

let pb = create_progress_bar("Viewing first 100 bytes...");
let (bytes, file_type) = view_bytes(url)?;
pb.finish_and_clear();

println!("First 100 bytes:");
for (i, byte) in bytes.iter().enumerate() {
print!("{:02X} ", byte);
Expand All @@ -129,9 +139,11 @@ fn process_view_bytes(url: &str) -> Result<(), Box<dyn std::error::Error>> {

fn process_csv(url: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;

let pb = create_progress_bar("Processing CSV...");
let bytes = fetch_remote_csv(url)?;
let result = process_basic_csv(bytes);

pb.finish_with_message("CSV Processed");
result
}
Expand Down

0 comments on commit 512e3a2

Please sign in to comment.