Skip to content

Commit

Permalink
feat(patch): add ignore-not-found option
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit committed Mar 4, 2024
1 parent 62f24ff commit f0c132a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/commands/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub struct Patch {
/// Don't prettify the geojson.
#[arg(long = "no-pretty")]
pub no_pretty: bool,
/// Continue on data not found
#[arg(long = "ignore-not-found", default_value = "false")]
pub ignore_not_found: bool,
}

impl Patch {
Expand Down Expand Up @@ -105,10 +108,16 @@ impl Patch {
.ok_or("The key `id` must be an integer")?;

if let Some(sqlite) = sqlite {
let mut original_json = sqlite
let original_json = sqlite
.get_geojson_by_id(id)
.stringify_err(&format!("Something goes wrong on id {}", id))?
.ok_or(&format!("GeoJSON {} not found in {}", id, self.original))?;
.ok_or(format!("GeoJSON {} not found in {}", id, self.original));

if self.ignore_not_found && original_json.is_err() {
return Ok(());
}

let mut original_json = original_json?;
let original_source = Patch::get_source(&original_json)?;
Patch::apply_patch_to_original(&json, &mut original_json)
.stringify_err(&format!("Can't apply patch on id {}", id))?;
Expand All @@ -117,7 +126,13 @@ impl Patch {
sqlite.add(wof)?;
} else {
let path = utils::get_geojson_path_from_id(&self.original, id)
.ok_or(&format!("GeoJSON {} not found in {}", id, self.original))?;
.ok_or(format!("GeoJSON {} not found in {}", id, self.original));

if self.ignore_not_found && path.is_err() {
return Ok(());
}

let path = path?;
let mut original_json = parse_file_to_json(path.clone())
.stringify_err(&format!("Can't open file id {} from {}", id, self.original))?;
Patch::apply_patch_to_original(&json, &mut original_json)
Expand Down

0 comments on commit f0c132a

Please sign in to comment.