Skip to content

Commit

Permalink
Replace --no_overwrite with --exists in zarrs_{filter,ome}
Browse files Browse the repository at this point in the history
Adds overwrite option to `zarrs_ome`.
  • Loading branch information
LDeakin committed Apr 25, 2024
1 parent 3069d86 commit 633c91c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zarrs_tools"
version = "0.4.0"
version = "0.4.1"
authors = ["Lachlan Deakin <ljdgit@gmail.com>"]
edition = "2021"
rust-version = "1.75"
Expand Down
11 changes: 9 additions & 2 deletions docs/zarrs_ome.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 <GROUP_ATTRIBUTES>
Attributes (optional).
Expand Down
27 changes: 20 additions & 7 deletions src/bin/zarrs_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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.
///
Expand Down Expand Up @@ -211,11 +220,15 @@ fn run() -> Result<(), Box<dyn Error>> {
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
Expand Down
32 changes: 24 additions & 8 deletions src/bin/zarrs_ome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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).
///
Expand Down Expand Up @@ -251,13 +262,18 @@ fn run() -> Result<(), Box<dyn Error>> {
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");
Expand Down

0 comments on commit 633c91c

Please sign in to comment.