11use anyhow:: Result ;
22use clap:: { Parser , Subcommand } ;
3+ use ontoenv:: config:: { Config , EnvironmentConfig } ;
34use ontoenv:: ontology:: { GraphIdentifier , OntologyLocation } ;
45use ontoenv:: util:: write_dataset_to_file;
5- use ontoenv:: { config :: Config , OntoEnv , ontology_config :: { OntologyConfig , OntologyLocation } } ;
6+ use ontoenv:: OntoEnv ;
67use oxigraph:: model:: { NamedNode , NamedNodeRef } ;
8+ use serde_json;
79use std:: env:: current_dir;
10+ use std:: fs:: File ;
811use std:: path:: PathBuf ;
912
1013#[ derive( Debug , Parser ) ]
@@ -46,14 +49,15 @@ enum Commands {
4649 /// Glob patterns for which files to exclude, defaults to []
4750 #[ clap( long, short, num_args = 1 ..) ]
4851 excludes : Vec < String > ,
52+ /// Recreate the environment if it already exists
4953 #[ clap( long, short, default_value = "false" ) ]
5054 recreate : bool ,
51- } ,
52- /// Fetch all ontologies and their dependencies from a configuration file
53- Fetch {
54- /// Path to the environment JSON configuration file
55- #[ clap( long, short) ]
56- config_file : PathBuf ,
55+ /// A JSON file containing a list of ontologies to add to the environment
56+ # [ clap ( long = "list" , short = 'l' ) ]
57+ ontology_list_file : Option < String > ,
58+ /// Do not search for ontologies in the search directories
59+ #[ clap( long = "no-search" , short = 'n' , action ) ]
60+ no_search : bool ,
5761 } ,
5862 /// Prints the version of the ontoenv binary
5963 Version ,
@@ -106,6 +110,8 @@ enum Commands {
106110 } ,
107111 /// Run the doctor to check the environment for issues
108112 Doctor ,
113+ /// Reset the ontology environment by removing the .ontoenv directory
114+ Reset ,
109115}
110116
111117fn main ( ) -> Result < ( ) > {
@@ -127,8 +133,11 @@ fn main() -> Result<()> {
127133 includes,
128134 excludes,
129135 recreate,
136+ ontology_list_file,
137+ no_search,
130138 } => {
131139 // if search_directories is empty, use the current directory
140+ println ! ( "no search? {}" , no_search) ;
132141 let config = Config :: new (
133142 current_dir ( ) ?,
134143 search_directories,
@@ -138,8 +147,19 @@ fn main() -> Result<()> {
138147 strict,
139148 offline,
140149 policy,
150+ no_search,
141151 ) ?;
142152 let mut env = OntoEnv :: new ( config, recreate) ?;
153+
154+ // if an ontology config file is provided, load it and add the ontologies
155+ if let Some ( file) = ontology_list_file {
156+ let file = File :: open ( file) ?;
157+ let config: EnvironmentConfig = serde_json:: from_reader ( file) ?;
158+ for ont in config. ontologies {
159+ env. add ( ont. location ) ?;
160+ }
161+ }
162+
143163 env. update ( ) ?;
144164 env. save_to_directory ( ) ?;
145165 }
@@ -276,27 +296,12 @@ fn main() -> Result<()> {
276296 let env = OntoEnv :: from_file ( & path, true ) ?;
277297 env. doctor ( ) ;
278298 }
279- Commands :: Fetch { config_file } => {
280- // Load the configuration from the specified JSON file
281- let config: EnvironmentConfig = serde_json:: from_reader ( std:: fs:: File :: open ( & config_file) ?) ?;
282-
283- // Create a new OntoEnv with the default configuration
284- let mut env = OntoEnv :: new ( Config :: default ( ) , false ) ?;
285-
286- // Iterate over each ontology in the configuration and add it to the environment
287- for ontology in config. ontologies {
288- let location = match ontology. location {
289- OntologyLocation :: File { file } => OntologyLocation :: File ( file) ,
290- OntologyLocation :: Uri { uri } => OntologyLocation :: Url ( uri) ,
291- } ;
292- env. add ( location) ?;
299+ Commands :: Reset => {
300+ // remove .ontoenv directory
301+ let path = current_dir ( ) ?. join ( ".ontoenv" ) ;
302+ if path. exists ( ) {
303+ std:: fs:: remove_dir_all ( path) ?;
293304 }
294-
295- // Update the environment to fetch dependencies
296- env. update ( ) ?;
297-
298- // Save the updated environment
299- env. save_to_directory ( ) ?;
300305 }
301306 }
302307
0 commit comments