Skip to content

Commit

Permalink
Changes 12.07.24: Added excel file format functionality. Updated cli …
Browse files Browse the repository at this point in the history
…commands and added exqs format --url. Updated unit tests.
  • Loading branch information
CHRISCARLON committed Jul 12, 2024
1 parent 65af3c5 commit de4573b
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 252 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ calamine = "0.25.0"
comfy-table = "7.1.0"
clap = { version = "4.5.7", features = ["derive"] }
reqwest = { version = "0.12", features = ["blocking"] }
colored = "2.1.0"

[lib]
name = "exqs"
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Excel Quick Scan

## WORK IN PROGRESS
## WORK IN PROGRESS

A simple CLI tool name Excel Quick Scan.
A simple CLI tool named Excel Quick Scan (ExQS).

This is a very basic tool, for forgetful people like me, that provides basic information about excel files - both remote and local.
This is a very basic tool that provides basic information about remote excel files.

This is a project for me to practice Rust but I may make it available as a package in the future.
This is a project for me to practice Rust but I may make it available as a package in the future.

## It currently only has 2 basic commands:
## It currently only has 2 basic commands:

```zsh
exqs --file file/path/here
```zsh
exqs basic --url "URL to Excel File here"
```

```zsh
exqs --url "URL HERE"
exqs format --url "URL to Excel File here"
```

## Example Output:
## Example Output for exqs basic:

```zsh
Sheet Name: 2023
Expand All @@ -41,14 +41,14 @@ Total number of rows: 76
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
│ Column 7: DATE REFERRED TO TREASURY SOLICITOR ┆ String │
└───────────────────────────────────────────────┴───────────┘
Data Row 1: MALE LS25 41619 72 1590 1590 41900
Data Row 2: MALE LS22 41625 69 1350.54 1350.54 NOT REFERRED
Data Row 3: MALE LS8 41628 77 1702 0 NOT REFERRED
Data Row 4: MALE LS11 41653 63 2270 1673.4 NOT REFERRED
Data Row 5: MALE LS6 41654 54 1307 0 NOT REFERRED
Data Row 6: FEMALE LS12 41655 91 1474 1474 41767
Data Row 7: MALE LS14 41658 89 1630 1630 NOT REFERRED
Data Row 8: MALE LS12 41673 66 1378.5 1378.5 NOT REFERRED
Data Row 9: MALE LS3 41684 56 1660.64 855.49 NOT REFERRED
Data Row 10: FEMALE LS9 41689 46 1266 215.24 NOT REFERRED
Data Row 1: MALE LS25 41619 72 1590 1590 41900
Data Row 2: MALE LS22 41625 69 1350.54 1350.54 NOT REFERRED
Data Row 3: MALE LS8 41628 77 1702 0 NOT REFERRED
Data Row 4: MALE LS11 41653 63 2270 1673.4 NOT REFERRED
Data Row 5: MALE LS6 41654 54 1307 0 NOT REFERRED
Data Row 6: FEMALE LS12 41655 91 1474 1474 41767
Data Row 7: MALE LS14 41658 89 1630 1630 NOT REFERRED
Data Row 8: MALE LS12 41673 66 1378.5 1378.5 NOT REFERRED
Data Row 9: MALE LS3 41684 56 1660.64 855.49 NOT REFERRED
Data Row 10: FEMALE LS9 41689 46 1266 215.24 NOT REFERRED
```
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
// src/lib.rs

pub mod local_file_functions;
pub mod remote_file_functions;
pub mod remote_file_functions;
97 changes: 0 additions & 97 deletions src/local_file_functions.rs

This file was deleted.

85 changes: 57 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,66 @@
// src/main.rs

mod local_file_functions;
mod remote_file_functions;
use local_file_functions::display_basic_info;
use remote_file_functions::display_remote_basic_info;
use clap::Parser;
use std::path::PathBuf;

/// A program to display basic Excel file information
use clap::{Parser, Subcommand};
use colored::Colorize;
use remote_file_functions::{
analyze_excel_formatting, display_remote_basic_info, fetch_remote_file,
};

#[derive(Parser, Debug)]
#[command(author = "Chris Carlon", version = "0.1", about = "Displays Basic Info About Excel Files", long_about = None)]
struct Args {
/// Path to the Excel file
#[arg(short, long)]
file: Option<PathBuf>,

/// URL of the Excel file
#[arg(short, long)]
url: Option<String>,
#[command(author = "Chris Carlon", version = "0.1", about = "Excel Query and Statistics (EXQS) Tool", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
/// Display basic information about the Excel file
Basic {
/// URL of the Excel file
#[arg(short, long)]
url: String,
},
/// Check formatting of the Excel file
Format {
/// URL of the Excel file
#[arg(short, long)]
url: String,
},
}

fn main() {
let args = Args::parse();

if let Some(file) = args.file {
if let Err(e) = display_basic_info(&file) {
eprintln!("Error processing file: {}", e);
}
} else if let Some(url) = args.url {
if let Err(e) = display_remote_basic_info(&url) {
eprintln!("Error processing URL: {}", e);
}
} else {
eprintln!("Please provide either a file path or a URL.");
let cli = Cli::parse();

match &cli.command {
Commands::Basic { url } => process_url(url, display_remote_basic_info, "basic info"),
Commands::Format { url } => process_url(url, analyze_excel_formatting, "formatting"),
}
}

fn process_url<F>(url: &str, process_fn: F, operation: &str)
where
F: Fn(Vec<u8>) -> Result<(), Box<dyn std::error::Error>>,
{
if url.is_empty() {
eprintln!("{}", "Error: URL cannot be empty".red());
return;
}

if !url.starts_with("http://") && !url.starts_with("https://") {
eprintln!("{}", "Error: URL must start with http:// or https://".red());
return;
}

match fetch_remote_file(url) {
Ok(content) => match process_fn(content) {
Ok(_) => println!(
"{}",
format!("Successfully Processed {}!", operation).green()
),
Err(e) => eprintln!("{}", format!("Error processing file content: {}", e).red()),
},
Err(e) => eprintln!("{}", format!("Error fetching file from URL: {}", e).red()),
}
}
Loading

0 comments on commit de4573b

Please sign in to comment.