Skip to content

Commit

Permalink
just use the directories crate for each platform
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Feb 27, 2021
1 parent 1812ee4 commit 85c8b7d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 51 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ clap = "3.0.0-beta.2"
regex = "1"
serde = "1.0"
serde_yaml = "0.8.15"
xdg = "2.2.0"
directories = "3.0"
ticker = "0.1.1"

Expand Down
9 changes: 0 additions & 9 deletions src/config/linux.rs

This file was deleted.

31 changes: 27 additions & 4 deletions src/config/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,33 @@ use std::{error::Error, fs::File, io::prelude::*, path::PathBuf};

use super::Config;

#[cfg_attr(target_os = "linux", path = "windows.rs")]
#[cfg_attr(target_os = "macos", path = "windows.rs")]
#[cfg_attr(windows, path = "windows.rs")]
pub mod os;
use std::fs;
use std::io;
use std::path::Path;

extern crate directories;
use directories::ProjectDirs;

// adapted from xdg crate
fn write_file<P>(home: &PathBuf, path: P) -> io::Result<PathBuf>
where
P: AsRef<Path>,
{
match path.as_ref().parent() {
Some(parent) => (fs::create_dir_all(home.join(parent)))?,
None => (fs::create_dir_all(home))?,
}
Ok(PathBuf::from(home.join(path.as_ref())))
}

pub fn config_path() -> Result<PathBuf, Box<dyn Error>> {
let config_dir = ProjectDirs::from("", "", "lazycli")
.unwrap()
.config_dir()
.to_owned();

Ok(write_file(&PathBuf::from(config_dir), "config.yml")?)
}

pub fn prepare_config(config_path: &PathBuf) -> Result<Config, Box<dyn Error>> {
if config_path.exists() {
Expand Down
29 changes: 0 additions & 29 deletions src/config/windows.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use config::storage;

fn main() -> Result<(), Box<dyn Error>> {
let args = Args::new();
let config_path = storage::os::config_path()?;
let config_path = storage::config_path()?;
let config = storage::prepare_config(&config_path)?;

let app = App::new(&config, config_path, args);
Expand Down

0 comments on commit 85c8b7d

Please sign in to comment.