Browse Source

♻️ Settings struct

master
n0m1s 6 years ago
parent
commit
7cd9da9f3d
Signed by: nomis GPG Key ID: BC0454CAD76FE803
2 changed files with 36 additions and 18 deletions
  1. +4
    -18
      src/main.rs
  2. +32
    -0
      src/settings.rs

+ 4
- 18
src/main.rs View File

@ -1,24 +1,10 @@
mod settings;
mod gitmoji;
use std::path::PathBuf;
fn config_path() -> PathBuf {
let mut config_dir = dirs::config_dir().expect("cannot open config dir");
config_dir.push("gitmoji-rust");
config_dir
}
use settings::Settings;
fn main() {
//path to the "gitmoji" git repo
let mut repo_path = config_path();
repo_path.push("gitmoji");
let repo_path = repo_path;
//json file path
let mut json_path = config_path();
json_path.push("gitmoji.json");
let json_path = json_path;
let settings = Settings::new(None);
gitmoji::update(&gitmoji::Url::default_github(), &repo_path, &json_path).unwrap();
gitmoji::update(&gitmoji::Url::default_github(), &settings.repo_path, &settings.json_path).unwrap();
}

+ 32
- 0
src/settings.rs View File

@ -0,0 +1,32 @@
use std::path::PathBuf;
pub struct Settings {
pub config_path : PathBuf,
pub repo_path : PathBuf,
pub json_path : PathBuf,
}
impl Settings {
pub fn new(config_dir: Option<PathBuf>) -> Settings {
let config_dir = match config_dir {
Some(x) => x,
None => {
let mut dir = dirs::config_dir().expect("cannot open config dir");
dir.push("gitmoji-rust");
dir
}
};
let mut repo_dir = config_dir.clone();
repo_dir.push("gitmoji");
let mut json_file = config_dir.clone();
json_file.push("gitmoji.json");
Settings {
config_path: config_dir,
repo_path: repo_dir,
json_path: json_file,
}
}
}

Loading…
Cancel
Save