use crate::rubase::ruconst::ruconst;
use crate::rubase::rutils::file_utils;
use crate::rubase::JsonEntitySingle;
use serde::{Deserialize, Serialize};
use std::env;
use std::path::{Path, PathBuf};
#[allow(dead_code)]
static BASE_PATH: &str = "/usr/local/bin";
#[derive(Default, Deserialize, Clone, Serialize)]
pub struct RuFile {}
impl JsonEntitySingle for RuFile {}
fn find_config_path() -> String {
let p = file_utils::current_dir().unwrap();
let files = file_utils::find_dir(p.as_path().to_str().unwrap(), "config");
if files.is_empty() {
return "".to_string();
}
return files
.first()
.unwrap()
.parent()
.unwrap()
.to_str()
.unwrap()
.to_string();
}
fn find_config_exist() -> String {
let dir = find_config_path();
if dir.is_empty() {
return dir;
}
return dir;
}
pub fn get_config_path() -> String {
find_base_path() + "/config"
}
pub fn find_base_path() -> String {
if env::var_os(ruconst::ICHUB_BASE_PATH).is_some() {
return env::var_os(ruconst::ICHUB_BASE_PATH)
.unwrap()
.into_string()
.unwrap();
}
let base = find_config_exist();
base
}
pub fn project_path() -> &'static Path {
let manifest_dir = env!("CARGO_MANIFEST_DIR");
Path::new(manifest_dir)
}
pub fn project_path_src() -> PathBuf {
project_path().join("src")
}