File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -34,24 +34,23 @@ impl ConfigOptions {
34
34
}
35
35
}
36
36
37
- pub fn write_default < P > ( path : P ) -> Result < ( ) >
37
+ pub fn write < P > ( self , path : P ) -> Result < ( ) >
38
38
// I believe user would like to generate config with CLI flags
39
39
// I mean to write disabled_fields with --disabled-fields flag
40
40
where
41
- // Nah this feels really bad but rust-analyser told me to add ' + std::fmt::Display'
42
41
P : AsRef < Path > ,
43
42
{
44
43
// I dont think this can panic so i simply unwrapped it
45
- let defaults = toml:: to_string ( & Self :: default ( ) ) . unwrap ( ) ;
44
+ let contents = toml:: to_string ( & self ) . unwrap ( ) ;
46
45
match fs:: create_dir_all ( & path. as_ref ( ) . parent ( ) . unwrap_or ( Path :: new ( "/" ) ) ) {
47
- Ok ( _) => match fs:: write ( & path, & defaults ) {
46
+ Ok ( _) => match fs:: write ( & path, & contents ) {
48
47
Ok ( _) => {
49
48
let path = path. as_ref ( ) . display ( ) ;
50
- println ! ( "Default config file created at: {path}" )
49
+ println ! ( "Config config file created at: {path}" )
51
50
}
52
51
Err ( e) => {
53
52
let path = path. as_ref ( ) . display ( ) ;
54
- eprintln ! ( "Failed to write default config file at {path}: {e}" )
53
+ eprintln ! ( "Failed to write config file at {path}: {e}" )
55
54
}
56
55
} ,
57
56
Err ( e) => {
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ use onefetch::config::ConfigOptions;
8
8
use onefetch:: info:: build_info;
9
9
use onefetch:: ui:: printer:: Printer ;
10
10
use std:: io;
11
- use std:: process:: exit;
12
11
13
12
fn main ( ) -> Result < ( ) > {
14
13
setup_panic ! ( ) ;
@@ -33,12 +32,22 @@ fn main() -> Result<()> {
33
32
}
34
33
35
34
if cli_options. config . generate_config {
36
- // what the actual FUCK is happening here?
37
- // why default path is EMPTY?
38
- return ConfigOptions :: write_default ( & cli_options. config . config_path . unwrap_or_default ( ) ) ;
35
+ return ConfigOptions :: default ( ) . write (
36
+ & cli_options. config . config_path . unwrap_or (
37
+ dirs:: config_dir ( )
38
+ . expect ( "Could not find config dir!" )
39
+ . join ( "onefetch/config.toml" ) ,
40
+ ) ,
41
+ ) ;
39
42
}
40
43
41
- let config_options = ConfigOptions :: read ( & cli_options. config . config_path . clone ( ) . unwrap_or_default ( ) ) ;
44
+ let config_options = ConfigOptions :: read (
45
+ & cli_options. config . config_path . as_ref ( ) . unwrap_or (
46
+ & dirs:: config_dir ( )
47
+ . expect ( "Could not find config dir!" )
48
+ . join ( "onefetch/config.toml" ) ,
49
+ ) ,
50
+ ) ;
42
51
43
52
let info = build_info ( & cli_options, & config_options) ?;
44
53
You can’t perform that action at this time.
0 commit comments