summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-03 12:43:34 +0800
committersigoden <sigoden@gmail.com>2023-03-03 12:43:34 +0800
commit2e511c13276b7109e6774263d37eafce8df0a434 (patch)
treeaa2066db5a9c7b30d96ba84cc95c1f6411823cf7 /src/config.rs
parent1cde32160bbc594e8ed5d209a429ba57fd541876 (diff)
downloadaichat-2e511c13276b7109e6774263d37eafce8df0a434.tar.gz
chore: optimize config path
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs
index 3c2c633..7f21027 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,10 +7,10 @@ use std::{
use anyhow::{anyhow, Result};
use serde::Deserialize;
-pub const CONFIG_FILE_NAME: &str = "config.yaml";
-pub const ROLES_FILE_NAME: &str = "roles.yaml";
-pub const HISTORY_FILE_NAME: &str = "history.txt";
-pub const MESSAGE_FILE_NAME: &str = "messages.md";
+const CONFIG_FILE_NAME: &str = "config.yaml";
+const ROLES_FILE_NAME: &str = "roles.yaml";
+const HISTORY_FILE_NAME: &str = "history.txt";
+const MESSAGE_FILE_NAME: &str = "messages.md";
#[derive(Debug, Clone, Deserialize)]
pub struct Config {
@@ -40,6 +40,7 @@ impl Config {
config.load_roles()?;
Ok(config)
}
+
pub fn local_file(name: &str) -> Result<PathBuf> {
let env_name = format!(
"{}_CONFIG_DIR",
@@ -58,8 +59,25 @@ impl Config {
path.push(name);
Ok(path)
}
+
+ pub fn config_file() -> Result<PathBuf> {
+ Self::local_file(CONFIG_FILE_NAME)
+ }
+
+ pub fn roles_file() -> Result<PathBuf> {
+ Self::local_file(ROLES_FILE_NAME)
+ }
+
+ pub fn history_file() -> Result<PathBuf> {
+ Self::local_file(HISTORY_FILE_NAME)
+ }
+
+ pub fn messages_file() -> Result<PathBuf> {
+ Self::local_file(MESSAGE_FILE_NAME)
+ }
+
fn load_roles(&mut self) -> Result<()> {
- let path = Self::local_file(ROLES_FILE_NAME)?;
+ let path = Self::roles_file()?;
if !path.exists() {
return Ok(());
}