File tree 3 files changed +17
-9
lines changed
3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1
- use std:: collections:: HashMap ;
1
+ use std:: { collections:: HashMap , path :: PathBuf } ;
2
2
use serde:: Deserialize ;
3
3
4
4
#[ derive( Debug ) ]
@@ -66,18 +66,20 @@ impl From<String> for KittypawsConfig {
66
66
}
67
67
}
68
68
69
- pub fn load_config ( path : & str ) -> KittypawsConfig {
69
+ pub fn load_config ( path : PathBuf ) -> KittypawsConfig {
70
70
let contents = std:: fs:: read_to_string ( path) . expect ( "Should have been able to read the file" ) ;
71
71
72
72
KittypawsConfig :: from ( contents)
73
73
}
74
74
75
75
#[ cfg( test) ]
76
76
mod tests {
77
+ use std:: { path:: PathBuf , str:: FromStr } ;
78
+
77
79
use super :: load_config;
78
80
79
81
#[ test]
80
82
fn test_correct_configs_loading ( ) {
81
- load_config ( "../configs/dumb_test.yml" ) ;
83
+ load_config ( PathBuf :: from_str ( "../configs/dumb_test.yml" ) . unwrap ( ) ) ;
82
84
}
83
85
}
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use std::{
8
8
9
9
use zip:: ZipArchive ;
10
10
11
- fn get_kittypaws_home ( ) -> PathBuf {
11
+ pub fn get_kittypaws_home ( ) -> PathBuf {
12
12
PathBuf :: from ( env:: var ( "PAWS_HOME" ) . unwrap_or ( unwrap_home_path ( "~/.kittypaws" ) ) )
13
13
}
14
14
Original file line number Diff line number Diff line change @@ -3,19 +3,25 @@ mod plug;
3
3
mod settings;
4
4
mod stdout_styling;
5
5
6
- use paws_install:: { list_plugins, install_from_github, remove_plugin} ;
6
+ use std:: path:: PathBuf ;
7
+
8
+ use paws_install:: { list_plugins, install_from_github, remove_plugin, get_kittypaws_home} ;
7
9
use plug:: start_main_loop;
8
10
use paws_config:: load_config;
9
11
10
12
use clap:: { Parser , Subcommand } ;
11
13
12
- const DEFAULT_CONFIG_PATH : & str = "paws.yml" ;
14
+ const DEFAULT_CONFIG_FILE_NAME : & str = "paws.yml" ;
15
+
16
+ fn get_default_config_path ( ) -> PathBuf {
17
+ get_kittypaws_home ( ) . join ( DEFAULT_CONFIG_FILE_NAME )
18
+ }
13
19
14
20
#[ derive( Subcommand , Debug ) ]
15
21
pub enum Command {
16
22
Run {
17
- #[ arg( long = "config" , default_value_t = DEFAULT_CONFIG_PATH . to_string ( ) ) ]
18
- config : String
23
+ #[ arg( long = "config" ) ]
24
+ config : Option < PathBuf >
19
25
} ,
20
26
21
27
List ,
@@ -43,7 +49,7 @@ fn main() {
43
49
44
50
match args. command {
45
51
Command :: Run { config } => {
46
- let config = load_config ( & config) ;
52
+ let config = load_config ( config. unwrap_or ( get_default_config_path ( ) ) ) ;
47
53
start_main_loop ( config) ;
48
54
} ,
49
55
Command :: List => list_plugins ( ) . unwrap ( ) ,
You can’t perform that action at this time.
0 commit comments