File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,7 @@ pub struct VisualsCliOptions {
220
220
pub struct ConfigCliOptions {
221
221
/// Path to the config file
222
222
#[ arg( long, value_hint = ValueHint :: FilePath ) ]
223
- pub config_path : PathBuf ,
223
+ pub config_path : Option < PathBuf > ,
224
224
/// Creates a default config file
225
225
/// Writes to $XDG_CONFIG_HOME/onefetch/config.toml but can be overridden with --config-path
226
226
#[ arg( long) ]
@@ -321,7 +321,7 @@ impl Default for ConfigCliOptions {
321
321
fn default ( ) -> Self {
322
322
ConfigCliOptions {
323
323
// Not sure about unwrap
324
- config_path : dirs:: config_dir ( ) . unwrap ( ) . join ( "onefetch/config.toml" ) ,
324
+ config_path : Some ( dirs:: config_dir ( ) . unwrap ( ) . join ( "onefetch/config.toml" ) ) ,
325
325
generate_config : false ,
326
326
}
327
327
}
Original file line number Diff line number Diff line change @@ -39,16 +39,23 @@ impl ConfigOptions {
39
39
// I mean to write disabled_fields with --disabled-fields flag
40
40
where
41
41
// Nah this feels really bad but rust-analyser told me to add ' + std::fmt::Display'
42
- P : AsRef < Path > + std :: fmt :: Display ,
42
+ P : AsRef < Path > ,
43
43
{
44
44
// I dont think this can panic so i simply unwrapped it
45
45
let defaults = toml:: to_string ( & Self :: default ( ) ) . unwrap ( ) ;
46
46
match fs:: create_dir_all ( & path) {
47
47
Ok ( _) => match fs:: write ( & path, & defaults) {
48
- Ok ( _) => println ! ( "Default config file created at: {path}" ) ,
49
- Err ( e) => eprintln ! ( "Failed to write default config file: {}" , e) ,
48
+ Ok ( _) => {
49
+ let path = path. as_ref ( ) . display ( ) ;
50
+ println ! ( "Default config file created at: {path}" )
51
+ }
52
+ Err ( e) => {
53
+ let path = path. as_ref ( ) . display ( ) ;
54
+ eprintln ! ( "Failed to write default config file at {path}: {e}" )
55
+ }
50
56
} ,
51
57
Err ( e) => {
58
+ let path = path. as_ref ( ) . display ( ) ;
52
59
eprintln ! ( "Failed to create config directory {path}: {e}" ) ;
53
60
}
54
61
}
Original file line number Diff line number Diff line change @@ -32,12 +32,10 @@ fn main() -> Result<()> {
32
32
}
33
33
34
34
if cli_options. config . generate_config {
35
- // @spenserblack fixme pls
36
- // it complans if i add .display(), and complains if i remove .display()
37
- return ConfigOptions :: write_default ( cli_options. config . config_path . display ( ) ) ;
35
+ return ConfigOptions :: write_default ( cli_options. config . config_path . unwrap_or_default ( ) ) ;
38
36
}
39
37
40
- let config_options = ConfigOptions :: read ( & cli_options. config . config_path ) ;
38
+ let config_options = ConfigOptions :: read ( & cli_options. config . config_path . clone ( ) . unwrap_or_default ( ) ) ;
41
39
42
40
let info = build_info ( & cli_options, & config_options) ?;
43
41
You can’t perform that action at this time.
0 commit comments