Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
a7a28ed
1
Parent(s):
ea3f211
chore: make websurfx directory and config file names as constants
Browse files- src/config_parser/parser.rs +19 -6
src/config_parser/parser.rs
CHANGED
@@ -5,6 +5,10 @@ use super::parser_models::Style;
|
|
5 |
use rlua::Lua;
|
6 |
use std::{format, fs, path::Path};
|
7 |
|
|
|
|
|
|
|
|
|
8 |
/// A named struct which stores the parsed config file options.
|
9 |
///
|
10 |
/// # Fields
|
@@ -67,20 +71,29 @@ impl Config {
|
|
67 |
fn handle_different_config_file_path() -> Result<String, Box<dyn std::error::Error>> {
|
68 |
if Path::new(
|
69 |
format!(
|
70 |
-
"{}/.config/
|
71 |
-
std::env::var("HOME").unwrap()
|
|
|
72 |
)
|
73 |
.as_str(),
|
74 |
)
|
75 |
.exists()
|
76 |
{
|
77 |
Ok(format!(
|
78 |
-
"{}/.config/
|
79 |
-
std::env::var("HOME").unwrap()
|
|
|
|
|
80 |
))
|
81 |
-
} else if Path::new(
|
|
|
|
|
|
|
|
|
82 |
Ok("/etc/xdg/websurfx/config.lua".to_string())
|
83 |
-
} else if Path::new("./
|
|
|
|
|
84 |
Ok("./websurfx/config.lua".to_string())
|
85 |
} else {
|
86 |
Err(format!("Config file not found!!").into())
|
|
|
5 |
use rlua::Lua;
|
6 |
use std::{format, fs, path::Path};
|
7 |
|
8 |
+
// ------- Constants --------
|
9 |
+
static COMMON_DIRECTORY_NAME: &str = "websurfx";
|
10 |
+
static CONFIG_FILE_NAME: &str = "config.lua";
|
11 |
+
|
12 |
/// A named struct which stores the parsed config file options.
|
13 |
///
|
14 |
/// # Fields
|
|
|
71 |
fn handle_different_config_file_path() -> Result<String, Box<dyn std::error::Error>> {
|
72 |
if Path::new(
|
73 |
format!(
|
74 |
+
"{}/.config/{}/config.lua",
|
75 |
+
std::env::var("HOME").unwrap(),
|
76 |
+
COMMON_DIRECTORY_NAME
|
77 |
)
|
78 |
.as_str(),
|
79 |
)
|
80 |
.exists()
|
81 |
{
|
82 |
Ok(format!(
|
83 |
+
"{}/.config/{}/{}",
|
84 |
+
std::env::var("HOME").unwrap(),
|
85 |
+
COMMON_DIRECTORY_NAME,
|
86 |
+
CONFIG_FILE_NAME
|
87 |
))
|
88 |
+
} else if Path::new(
|
89 |
+
format!("/etc/xdg/{}/{}", COMMON_DIRECTORY_NAME, CONFIG_FILE_NAME).as_str(),
|
90 |
+
)
|
91 |
+
.exists()
|
92 |
+
{
|
93 |
Ok("/etc/xdg/websurfx/config.lua".to_string())
|
94 |
+
} else if Path::new(format!("./{}/{}", COMMON_DIRECTORY_NAME, CONFIG_FILE_NAME).as_str())
|
95 |
+
.exists()
|
96 |
+
{
|
97 |
Ok("./websurfx/config.lua".to_string())
|
98 |
} else {
|
99 |
Err(format!("Config file not found!!").into())
|