diff --git a/CHANGELOG.md b/CHANGELOG.md index 01a5174..fef0b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + - Replace `--no_overwrite` with `--exists` in `zarrs_filter` and `zarrs_ome` + - Both support `erase` and `exit` options + - `zarrs_ome` also supports an `overwrite` option + ## [0.4.0] - 2024-04-20 ### Added diff --git a/Cargo.lock b/Cargo.lock index 83372a9..c4f9c29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,12 +227,13 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] @@ -904,9 +905,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -1554,9 +1555,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -1864,18 +1865,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", @@ -2180,11 +2181,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "134306a13c5647ad6453e8deaec55d3a44d6021970129e6188735e74bf546697" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -2408,7 +2409,7 @@ dependencies = [ [[package]] name = "zarrs_tools" -version = "0.4.0" +version = "0.4.1" dependencies = [ "approx", "async-scoped", diff --git a/Cargo.toml b/Cargo.toml index 18837f4..bd92205 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zarrs_tools" -version = "0.4.0" +version = "0.4.1" authors = ["Lachlan Deakin "] edition = "2021" rust-version = "1.75" diff --git a/docs/zarrs_ome.md b/docs/zarrs_ome.md index a0f7378..d563313 100644 --- a/docs/zarrs_ome.md +++ b/docs/zarrs_ome.md @@ -66,8 +66,15 @@ Options: --discrete Do majority downsampling and do not apply gaussian smoothing - --no-overwrite - Exit instead of overwriting an existing array + --exists + Behaviour if the output exists + + [default: overwrite] + + Possible values: + - overwrite: Overwrite existing files. Useful if the output includes additional non-zarr files to be preserved + - erase: Erase the output + - exit: Exit if the output already exists --group-attributes Attributes (optional). diff --git a/src/bin/zarrs_filter.rs b/src/bin/zarrs_filter.rs index 36c8abb..40b9bf1 100644 --- a/src/bin/zarrs_filter.rs +++ b/src/bin/zarrs_filter.rs @@ -22,6 +22,14 @@ use zarrs_tools::{ ZarrReencodingArgs, }; +#[derive(clap::ValueEnum, Debug, Clone)] +enum OutputExists { + /// Erase the output + Erase, + /// Exit if the output already exists + Exit, +} + /// Apply simple image filters (transformations) to a Zarr V3 array. #[derive(Parser, Debug)] #[command(author, version)] @@ -30,9 +38,10 @@ struct Cli { #[arg(long)] hide_progress: bool, - /// Exit instead of overwriting an existing array. + /// Behaviour if the output exists. #[arg(long)] - no_overwrite: bool, + #[clap(value_enum, default_value_t=OutputExists::Erase)] + exists: OutputExists, /// Directory for temporary arrays. /// @@ -211,11 +220,15 @@ fn run() -> Result<(), Box> { output_paths, exists, } = get_input_output_paths(&filter_commands, tmp_dir.path())?; - // println!("{output_paths:?}"); - if cli.no_overwrite && exists.iter().any(|i| *i) { - Err(FilterError::Other( - "Run without --no-overwrite to overwrite".to_string(), - ))?; + + // Handle an existing output + match cli.exists { + OutputExists::Exit => { + if exists.iter().any(|i| *i) { + Err(FilterError::Other("Output exists, exiting".to_string()))?; + } + } + OutputExists::Erase => {} } // Instantiate the filters diff --git a/src/bin/zarrs_ome.rs b/src/bin/zarrs_ome.rs index b033ce8..95dafdd 100644 --- a/src/bin/zarrs_ome.rs +++ b/src/bin/zarrs_ome.rs @@ -28,6 +28,16 @@ use zarrs_tools::{ ZarrReEncodingChangeType, ZarrReencodingArgs, }; +#[derive(clap::ValueEnum, Debug, Clone)] +enum OutputExists { + /// Overwrite existing files. Useful if the output includes additional non-zarr files to be preserved. + Overwrite, + /// Erase the output + Erase, + /// Exit if the output already exists + Exit, +} + /// Convert a Zarr V3 array to OME-Zarr (0.5-dev). #[derive(Parser, Debug)] #[command(author, version)] @@ -67,9 +77,10 @@ struct Cli { #[arg(long)] discrete: bool, - /// Exit instead of overwriting an existing array. + /// Behaviour if the output exists. #[arg(long)] - no_overwrite: bool, + #[clap(value_enum, default_value_t=OutputExists::Overwrite)] + exists: OutputExists, /// Attributes (optional). /// @@ -251,13 +262,18 @@ fn run() -> Result<(), Box> { group.attributes_mut().append(&mut group_attributes); } - // Check for overwrite - if cli.no_overwrite && cli.output.exists() { - Err(FilterError::Other( - "Run without --no-overwrite to overwrite".to_string(), - ))?; + // Handle an existing output + match cli.exists { + OutputExists::Exit => { + if cli.output.exists() { + Err(FilterError::Other("Output exists, exiting".to_string()))?; + } + } + OutputExists::Erase => { + store.erase_prefix(&StorePrefix::root()).unwrap(); + } + OutputExists::Overwrite => {} } - store.erase_prefix(&StorePrefix::root()).unwrap(); { let output_0_path = cli.output.join("0");