change fixed dir to read from config
This commit is contained in:
parent
be862d218c
commit
fcfae4f30e
2 changed files with 27 additions and 3 deletions
|
|
@ -17,7 +17,7 @@ pub struct VersionRecipe {
|
||||||
impl VersionRecipe {
|
impl VersionRecipe {
|
||||||
// import - read all file with given format from directory and mixing them together as 1 recipe
|
// import - read all file with given format from directory and mixing them together as 1 recipe
|
||||||
pub fn create_versioning_by_country(country: &str) -> Self {
|
pub fn create_versioning_by_country(country: &str) -> Self {
|
||||||
let mut path = String::from(RECIPES_DIR);
|
let mut path = String::from(get_recipe_dir().get("RECIPE_DIR").unwrap());
|
||||||
path.push_str(country);
|
path.push_str(country);
|
||||||
path.push('/');
|
path.push('/');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,31 @@ use crate::models::{self, recipe::Recipe01};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::{fs::File, io::Read};
|
use std::{fs::File, io::Read};
|
||||||
|
|
||||||
pub const RECIPES_DIR: &str = "/Users/pkntd/Codes/mk4/cofffeemachineConfig/";
|
// Change path here!
|
||||||
|
|
||||||
|
fn extract_tb_config(content: String) -> HashMap<String, String> {
|
||||||
|
let mut result = HashMap::new();
|
||||||
|
let lines = content.lines();
|
||||||
|
|
||||||
|
for line in lines {
|
||||||
|
let parts: Vec<&str> = line.split('=').collect();
|
||||||
|
if parts.len() == 2 {
|
||||||
|
result.insert(parts[0].trim().to_string(), parts[1].trim().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get config from `.tbcfg` file in current directory
|
||||||
|
pub fn get_recipe_dir() -> HashMap<String, String> {
|
||||||
|
// need `.tbcfg`
|
||||||
|
let cfg_result = std::fs::read_to_string("./.tbcfg");
|
||||||
|
match cfg_result {
|
||||||
|
Ok(cfg) => extract_tb_config(cfg),
|
||||||
|
Err(e) => panic!("Failed to read .tbcfg: {}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_recipe_model_from_file(path: String) -> models::recipe::Recipe {
|
pub fn create_recipe_model_from_file(path: String) -> models::recipe::Recipe {
|
||||||
// println!("create_recipe_model_from_file: {}", path);
|
// println!("create_recipe_model_from_file: {}", path);
|
||||||
|
|
@ -18,7 +42,7 @@ pub fn create_recipe_model_from_file(path: String) -> models::recipe::Recipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_recipe_path(country_path: &str, version: usize) -> String {
|
pub fn create_recipe_path(country_path: &str, version: usize) -> String {
|
||||||
let mut path = String::from(RECIPES_DIR);
|
let mut path = String::from(get_recipe_dir().get("RECIPE_DIR").unwrap());
|
||||||
|
|
||||||
path.push_str(country_path);
|
path.push_str(country_path);
|
||||||
path.push_str("/coffeethai02_");
|
path.push_str("/coffeethai02_");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue