Skip to content

Commit

Permalink
Feature: Fixed path for default config file (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
subatiq authored Apr 18, 2024
1 parent 5de9364 commit c5307a5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions paws_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};
use serde::Deserialize;

#[derive(Debug)]
Expand Down Expand Up @@ -66,18 +66,20 @@ impl From<String> for KittypawsConfig {
}
}

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

KittypawsConfig::from(contents)
}

#[cfg(test)]
mod tests {
use std::{path::PathBuf, str::FromStr};

use super::load_config;

#[test]
fn test_correct_configs_loading() {
load_config("../configs/dumb_test.yml");
load_config(PathBuf::from_str("../configs/dumb_test.yml").unwrap());
}
}
2 changes: 1 addition & 1 deletion paws_install/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

use zip::ZipArchive;

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

Expand Down
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ mod plug;
mod settings;
mod stdout_styling;

use paws_install::{list_plugins, install_from_github, remove_plugin};
use std::path::PathBuf;

use paws_install::{list_plugins, install_from_github, remove_plugin, get_kittypaws_home};
use plug::start_main_loop;
use paws_config::load_config;

use clap::{Parser, Subcommand};

const DEFAULT_CONFIG_PATH: &str = "paws.yml";
const DEFAULT_CONFIG_FILE_NAME: &str = "paws.yml";

fn get_default_config_path() -> PathBuf {
get_kittypaws_home().join(DEFAULT_CONFIG_FILE_NAME)
}

#[derive(Subcommand, Debug)]
pub enum Command {
Run {
#[arg(long = "config", default_value_t = DEFAULT_CONFIG_PATH.to_string())]
config: String
#[arg(long = "config")]
config: Option<PathBuf>
},

List,
Expand Down Expand Up @@ -43,7 +49,7 @@ fn main() {

match args.command {
Command::Run { config } => {
let config = load_config(&config);
let config = load_config(config.unwrap_or(get_default_config_path()));
start_main_loop(config);
},
Command::List => list_plugins().unwrap(),
Expand Down

0 comments on commit c5307a5

Please sign in to comment.