Skip to content

Commit c5307a5

Browse files
authored
Feature: Fixed path for default config file (#21)
1 parent 5de9364 commit c5307a5

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

paws_config/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::{collections::HashMap, path::PathBuf};
22
use serde::Deserialize;
33

44
#[derive(Debug)]
@@ -66,18 +66,20 @@ impl From<String> for KittypawsConfig {
6666
}
6767
}
6868

69-
pub fn load_config(path: &str) -> KittypawsConfig {
69+
pub fn load_config(path: PathBuf) -> KittypawsConfig {
7070
let contents = std::fs::read_to_string(path).expect("Should have been able to read the file");
7171

7272
KittypawsConfig::from(contents)
7373
}
7474

7575
#[cfg(test)]
7676
mod tests {
77+
use std::{path::PathBuf, str::FromStr};
78+
7779
use super::load_config;
7880

7981
#[test]
8082
fn test_correct_configs_loading() {
81-
load_config("../configs/dumb_test.yml");
83+
load_config(PathBuf::from_str("../configs/dumb_test.yml").unwrap());
8284
}
8385
}

paws_install/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88

99
use zip::ZipArchive;
1010

11-
fn get_kittypaws_home() -> PathBuf {
11+
pub fn get_kittypaws_home() -> PathBuf {
1212
PathBuf::from(env::var("PAWS_HOME").unwrap_or(unwrap_home_path("~/.kittypaws")))
1313
}
1414

src/main.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@ mod plug;
33
mod settings;
44
mod stdout_styling;
55

6-
use paws_install::{list_plugins, install_from_github, remove_plugin};
6+
use std::path::PathBuf;
7+
8+
use paws_install::{list_plugins, install_from_github, remove_plugin, get_kittypaws_home};
79
use plug::start_main_loop;
810
use paws_config::load_config;
911

1012
use clap::{Parser, Subcommand};
1113

12-
const DEFAULT_CONFIG_PATH: &str = "paws.yml";
14+
const DEFAULT_CONFIG_FILE_NAME: &str = "paws.yml";
15+
16+
fn get_default_config_path() -> PathBuf {
17+
get_kittypaws_home().join(DEFAULT_CONFIG_FILE_NAME)
18+
}
1319

1420
#[derive(Subcommand, Debug)]
1521
pub enum Command {
1622
Run {
17-
#[arg(long = "config", default_value_t = DEFAULT_CONFIG_PATH.to_string())]
18-
config: String
23+
#[arg(long = "config")]
24+
config: Option<PathBuf>
1925
},
2026

2127
List,
@@ -43,7 +49,7 @@ fn main() {
4349

4450
match args.command {
4551
Command::Run { config } => {
46-
let config = load_config(&config);
52+
let config = load_config(config.unwrap_or(get_default_config_path()));
4753
start_main_loop(config);
4854
},
4955
Command::List => list_plugins().unwrap(),

0 commit comments

Comments
 (0)