Skip to content

Commit 9f6af78

Browse files
committed
let code compile
1 parent 735e97e commit 9f6af78

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub struct VisualsCliOptions {
220220
pub struct ConfigCliOptions {
221221
/// Path to the config file
222222
#[arg(long, value_hint = ValueHint::FilePath)]
223-
pub config_path: PathBuf,
223+
pub config_path: Option<PathBuf>,
224224
/// Creates a default config file
225225
/// Writes to $XDG_CONFIG_HOME/onefetch/config.toml but can be overridden with --config-path
226226
#[arg(long)]
@@ -321,7 +321,7 @@ impl Default for ConfigCliOptions {
321321
fn default() -> Self {
322322
ConfigCliOptions {
323323
// 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")),
325325
generate_config: false,
326326
}
327327
}

src/config.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,23 @@ impl ConfigOptions {
3939
// I mean to write disabled_fields with --disabled-fields flag
4040
where
4141
// 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>,
4343
{
4444
// I dont think this can panic so i simply unwrapped it
4545
let defaults = toml::to_string(&Self::default()).unwrap();
4646
match fs::create_dir_all(&path) {
4747
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+
}
5056
},
5157
Err(e) => {
58+
let path = path.as_ref().display();
5259
eprintln!("Failed to create config directory {path}: {e}");
5360
}
5461
}

src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ fn main() -> Result<()> {
3232
}
3333

3434
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());
3836
}
3937

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());
4139

4240
let info = build_info(&cli_options, &config_options)?;
4341

0 commit comments

Comments
 (0)