@@ -37,30 +37,35 @@ pub struct Profile {
3737}
3838
3939impl Profile {
40- fn get_bin_path ( & self ) -> PathBuf {
41- build_path ( & self . root_path ) . unwrap ( ) . join ( "bin" )
40+ fn get_bin_path ( & self ) -> SoarResult < PathBuf > {
41+ Ok ( self . get_root_path ( ) ? . join ( "bin" ) )
4242 }
4343
44- fn get_db_path ( & self ) -> PathBuf {
45- build_path ( & self . root_path ) . unwrap ( ) . join ( "db" )
44+ fn get_db_path ( & self ) -> SoarResult < PathBuf > {
45+ Ok ( self . get_root_path ( ) ? . join ( "db" ) )
4646 }
4747
48- pub fn get_packages_path ( & self ) -> PathBuf {
49- build_path (
50- & self
51- . packages_path
52- . clone ( )
53- . unwrap_or_else ( || format ! ( "{}/packages" , self . root_path) ) ,
54- )
55- . unwrap ( )
48+ pub fn get_packages_path ( & self ) -> SoarResult < PathBuf > {
49+ if let Some ( ref packages_path) = self . packages_path {
50+ build_path ( packages_path)
51+ } else {
52+ Ok ( self . get_root_path ( ) ?. join ( "packages" ) )
53+ }
54+ }
55+
56+ pub fn get_cache_path ( & self ) -> SoarResult < PathBuf > {
57+ Ok ( self . get_root_path ( ) ?. join ( "cache" ) )
5658 }
5759
58- pub fn get_cache_path ( & self ) -> PathBuf {
59- build_path ( & self . root_path ) . unwrap ( ) . join ( "cache" )
60+ fn get_repositories_path ( & self ) -> SoarResult < PathBuf > {
61+ Ok ( self . get_root_path ( ) ? . join ( "repos" ) )
6062 }
6163
62- fn get_repositories_path ( & self ) -> PathBuf {
63- build_path ( & self . root_path ) . unwrap ( ) . join ( "repos" )
64+ pub fn get_root_path ( & self ) -> SoarResult < PathBuf > {
65+ if let Ok ( env_path) = std:: env:: var ( "SOAR_ROOT" ) {
66+ return build_path ( & env_path) ;
67+ }
68+ build_path ( & self . root_path )
6469 }
6570}
6671
@@ -229,7 +234,8 @@ pub fn set_current_profile(name: &str) -> Result<()> {
229234
230235impl Config {
231236 pub fn generate_default_config ( external : bool ) -> Self {
232- let soar_root = format ! ( "{}/soar" , home_data_path( ) ) ;
237+ let soar_root =
238+ std:: env:: var ( "SOAR_ROOT" ) . unwrap_or_else ( |_| format ! ( "{}/soar" , home_data_path( ) ) ) ;
233239
234240 let default_profile = Profile {
235241 root_path : soar_root. clone ( ) ,
@@ -319,6 +325,10 @@ impl Config {
319325 /// Creates a new configuration by loading it from the configuration file.
320326 /// If the configuration file is not found, it uses the default configuration.
321327 pub fn new ( ) -> Result < Self > {
328+ if std:: env:: var ( "SOAR_STEALTH" ) . is_ok ( ) {
329+ return Ok ( Self :: generate_default_config ( false ) ) ;
330+ }
331+
322332 let config_path = CONFIG_PATH . read ( ) . unwrap ( ) . to_path_buf ( ) ;
323333
324334 let mut config = match fs:: read_to_string ( & config_path) {
@@ -408,18 +418,14 @@ impl Config {
408418 . ok_or ( ConfigError :: MissingProfile ( name. to_string ( ) ) )
409419 }
410420
411- pub fn get_root_path ( & self ) -> SoarResult < PathBuf > {
412- build_path ( & self . get_profile ( & get_current_profile ( ) ) ?. root_path )
413- }
414-
415421 pub fn get_bin_path ( & self ) -> SoarResult < PathBuf > {
416422 if let Ok ( env_path) = std:: env:: var ( "SOAR_BIN" ) {
417423 return build_path ( & env_path) ;
418424 }
419425 if let Some ( bin_path) = & self . bin_path {
420426 return build_path ( bin_path) ;
421427 }
422- Ok ( self . default_profile ( ) ?. get_bin_path ( ) )
428+ self . default_profile ( ) ?. get_bin_path ( )
423429 }
424430
425431 pub fn get_db_path ( & self ) -> SoarResult < PathBuf > {
@@ -429,15 +435,15 @@ impl Config {
429435 if let Some ( soar_db) = & self . db_path {
430436 return build_path ( soar_db) ;
431437 }
432- Ok ( self . default_profile ( ) ?. get_db_path ( ) )
438+ self . default_profile ( ) ?. get_db_path ( )
433439 }
434440
435- pub fn get_packages_path (
436- & self ,
437- profile_name : Option < String > ,
438- ) -> std :: result :: Result < PathBuf , SoarError > {
441+ pub fn get_packages_path ( & self , profile_name : Option < String > ) -> SoarResult < PathBuf > {
442+ if let Ok ( env_path ) = std :: env :: var ( "SOAR_PACKAGES" ) {
443+ return build_path ( & env_path ) ;
444+ }
439445 let profile_name = profile_name. unwrap_or_else ( get_current_profile) ;
440- Ok ( self . get_profile ( & profile_name) ?. get_packages_path ( ) )
446+ self . get_profile ( & profile_name) ?. get_packages_path ( )
441447 }
442448
443449 pub fn get_cache_path ( & self ) -> SoarResult < PathBuf > {
@@ -447,7 +453,7 @@ impl Config {
447453 if let Some ( soar_cache) = & self . cache_path {
448454 return build_path ( soar_cache) ;
449455 }
450- Ok ( self . get_profile ( & get_current_profile ( ) ) ?. get_cache_path ( ) )
456+ self . get_profile ( & get_current_profile ( ) ) ?. get_cache_path ( )
451457 }
452458
453459 pub fn get_repositories_path ( & self ) -> SoarResult < PathBuf > {
@@ -457,7 +463,7 @@ impl Config {
457463 if let Some ( repositories_path) = & self . repositories_path {
458464 return build_path ( repositories_path) ;
459465 }
460- Ok ( self . default_profile ( ) ?. get_repositories_path ( ) )
466+ self . default_profile ( ) ?. get_repositories_path ( )
461467 }
462468
463469 pub fn get_repository ( & self , repo_name : & str ) -> Option < & Repository > {
0 commit comments