Skip to content

Commit

Permalink
added support for wildcard and an option to ignore sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
piquu committed Apr 7, 2024
1 parent bd0c192 commit 1b3305f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/*.xlsx
/out
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryver"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["piquu [email protected]"]
license = "MIT"
Expand All @@ -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"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].0"
river = "piquu/[email protected].2"
```

Or use the `aftman` Cli to add it:
Expand All @@ -28,6 +28,8 @@ cargo install ryver
* Folder where the luau/ts files are put
* `-s`, `--sheet <SHEET>`
* Sheets that luau/ts files should be generated for
* `-i`, `--ignore-sheet`
* Sheets that luau/ts files wont be generated for
* `--table-name <NUMBER>`
* Spreadsheet column thats used as the table/object name
* `-n`, `--no-type`
Expand Down
26 changes: 16 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// Input file
#[arg(short, long)]
file: PathBuf,
Expand All @@ -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<String>,

/// Ignore sheet names
#[arg(short, long)]
ignore_sheet: Vec<String>,

/// 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
Expand Down Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 1b3305f

Please sign in to comment.