Skip to content

Commit cea1ad1

Browse files
committed
changing detection of files
1 parent 2e543d3 commit cea1ad1

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

cli/src/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ enum Commands {
121121
Doctor,
122122
/// Reset the ontology environment by removing the .ontoenv directory
123123
Reset {
124-
#[clap(long, short, action = clap::ArgAction::Set, default_value = "false")]
124+
#[clap(long, short, action = clap::ArgAction::SetTrue, default_value = "false")]
125125
force: bool,
126126
},
127127
}
@@ -171,7 +171,11 @@ fn main() -> Result<()> {
171171
if cmd.verbose || cmd.debug {
172172
config.print();
173173
}
174-
let ontoenv_exists = current_dir()?.join(".ontoenv").exists();
174+
let ontoenv_exists = current_dir()?
175+
.join(".ontoenv")
176+
.join("ontoenv.json")
177+
.exists();
178+
println!("[INFO] OntoEnv exists: {}", ontoenv_exists);
175179

176180
// create the env object to use in the subcommand.
177181
// - if temporary is true, create a new env object each time
@@ -181,12 +185,13 @@ fn main() -> Result<()> {
181185
let mut e = OntoEnv::init(config.clone(), false)?;
182186
e.update()?;
183187
Some(e)
184-
} else if cmd.command.to_string() != "Init" && ontoenv_exists{
188+
} else if cmd.command.to_string() != "Init" && ontoenv_exists {
185189
// if .ontoenv exists, load it
186190
Some(OntoEnv::load_from_directory(current_dir()?, false)?) // no read-only
187191
} else {
188192
None
189193
};
194+
println!("[INFO] OntoEnv loaded: {}", env.is_some());
190195

191196
match cmd.command {
192197
Commands::Init {
@@ -342,7 +347,7 @@ fn main() -> Result<()> {
342347
// remove .ontoenv directory
343348
let path = current_dir()?.join(".ontoenv");
344349
println!("Removing .ontoenv directory at {}...", path.display());
345-
if path.exists() && !force {
350+
if !force {
346351
// check delete? [y/N]
347352
let mut input = String::new();
348353
println!("Are you sure you want to delete the .ontoenv directory? [y/N] ");
@@ -354,6 +359,8 @@ fn main() -> Result<()> {
354359
println!("Aborting...");
355360
return Ok(());
356361
}
362+
}
363+
if path.exists() {
357364
std::fs::remove_dir_all(path)?;
358365
}
359366
}

lib/src/api.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ impl OntoEnv {
311311
let id = ont.id().clone();
312312
self.env.add_ontology(ont);
313313
self.add_ids_to_dependency_graph(vec![id.clone()])?;
314+
self.save_to_directory()?;
314315
Ok(id)
315316
}
316317

@@ -347,7 +348,24 @@ impl OntoEnv {
347348
// load all of these files into the environment
348349
let mut ontologies: Vec<Ontology> = vec![];
349350
for location in updated_files {
350-
let ontology = self.io.add(location.clone(), true)?;
351+
// if 'strict' mode then fail on any errors when adding the ontology
352+
// otherwise just warn
353+
354+
let result = self.io.add(location.clone(), true);
355+
if result.is_err() {
356+
if self.config.strict {
357+
return Err(result.unwrap_err());
358+
} else {
359+
warn!(
360+
"Failed to read ontology file {}: {}",
361+
location,
362+
result.unwrap_err()
363+
);
364+
continue;
365+
}
366+
}
367+
368+
let ontology = result.unwrap();
351369
ontologies.push(ontology);
352370
}
353371

@@ -359,6 +377,7 @@ impl OntoEnv {
359377
update_ids.push(id);
360378
}
361379
self.add_ids_to_dependency_graph(update_ids)?;
380+
self.save_to_directory()?;
362381
Ok(())
363382
}
364383

0 commit comments

Comments
 (0)