From 1b3305f2a0bdbac32cbd7fc90a58c7dbb436e0b9 Mon Sep 17 00:00:00 2001 From: piqu Date: Mon, 8 Apr 2024 01:40:14 +0200 Subject: [PATCH] added support for wildcard and an option to ignore sheets --- .gitignore | 2 ++ Cargo.lock | 9 ++++++++- Cargo.toml | 3 ++- README.md | 4 +++- src/main.rs | 26 ++++++++++++++++---------- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..9e96927 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +/*.xlsx +/out \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index f881a1c..42b49b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -369,13 +369,14 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "ryver" -version = "0.1.1" +version = "0.1.2" dependencies = [ "calamine", "clap", "color-eyre", "tracing", "tracing-subscriber", + "wildmatch", ] [[package]] @@ -525,6 +526,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "wildmatch" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "939e59c1bc731542357fdaad98b209ef78c8743d652bb61439d16b16a79eb025" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index c1bf9e0..faa36c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ryver" -version = "0.1.1" +version = "0.1.2" edition = "2021" authors = ["piquu piqu@cock.li"] license = "MIT" @@ -19,3 +19,4 @@ clap = { version = "4.5.4", features = ["derive"] } color-eyre = "0.6.3" tracing = "0.1.40" tracing-subscriber = "0.3.18" +wildmatch = "2.3.3" diff --git a/README.md b/README.md index a1b7c34..38bf94f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A Cli that generates luau/ts files from spreadsheets ### With Aftman Add an entry to the `[tools]` section of `aftman.toml`: ```toml -river = "piquu/ryver@0.1.0" +river = "piquu/ryver@0.1.2" ``` Or use the `aftman` Cli to add it: @@ -28,6 +28,8 @@ cargo install ryver * Folder where the luau/ts files are put * `-s`, `--sheet ` * Sheets that luau/ts files should be generated for +* `-i`, `--ignore-sheet` + * Sheets that luau/ts files wont be generated for * `--table-name ` * Spreadsheet column thats used as the table/object name * `-n`, `--no-type` diff --git a/src/main.rs b/src/main.rs index d310e33..64f5498 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,12 +7,17 @@ use calamine::{open_workbook_auto, Reader}; use clap::{arg, command, Parser}; use color_eyre::eyre::Result; use tracing::{error, info, trace, Level}; +use wildmatch::WildMatch; use crate::sheet::Sheet; #[derive(Parser, Debug)] #[command(version, about)] struct Args { + /// Config file + #[arg(short, long)] + config: Option, + /// Input file #[arg(short, long)] file: PathBuf, @@ -22,13 +27,15 @@ struct Args { out: PathBuf, /// Sheet names - #[arg(short, long)] - #[clap(default_values_t = ["*".to_owned()])] + #[arg(short, long, default_values_t = ["*".to_owned()])] sheet: Vec, + /// Ignore sheet names + #[arg(short, long)] + ignore_sheet: Vec, + /// Column to be used as the table/object name - #[arg(long)] - #[clap(default_value_t = 0)] + #[arg(long, default_value_t = 0)] table_name: i32, /// Dont generate type @@ -71,13 +78,12 @@ fn main() -> Result<()> { Some("xlsx") | Some("xlsm") | Some("xlsb") | Some("xls") => { let mut xl = open_workbook_auto(args.file)?; - if args.sheet.len() == 1 && args.sheet[0] == "*" { - for (name, range) in xl.worksheets() { - sheets.push(Sheet::excel(name, range)); + for (name, range) in xl.worksheets() { + if args.ignore_sheet.iter().any(|s| WildMatch::new(s).matches(&name)) { + continue; } - } else { - for name in args.sheet { - let range = xl.worksheet_range(&name)?; + + if args.sheet.iter().any(|s| WildMatch::new(s).matches(&name)) { sheets.push(Sheet::excel(name, range)); } }