Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Fixed path for default config file #21

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading