add user assign config, -c -config
This commit is contained in:
@@ -195,8 +195,8 @@ pub fn get_string_value(json: &json::JsonValue, key: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_json() -> Option<json::JsonValue> {
|
||||
let config_content = get_config_content()?;
|
||||
pub fn get_config_json(custom_oss_backupd_config: Option<&str>) -> Option<json::JsonValue> {
|
||||
let config_content = get_config_content(custom_oss_backupd_config)?;
|
||||
match json::parse(&config_content) {
|
||||
Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Parse config json failed: {}", e));
|
||||
@@ -206,7 +206,24 @@ pub fn get_config_json() -> Option<json::JsonValue> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_config_content() -> Option<String> {
|
||||
pub fn get_config_content(custom_oss_backupd_config: Option<&str>) -> Option<String> {
|
||||
if custom_oss_backupd_config.is_some() {
|
||||
let custom_oss_backupd_config_unrwaped = custom_oss_backupd_config.unwrap();
|
||||
let custom_oss_backupd_config_path = Path::new(custom_oss_backupd_config_unrwaped);
|
||||
if custom_oss_backupd_config_path.exists() {
|
||||
match fs::read_to_string(custom_oss_backupd_config_path) {
|
||||
Err(e) => {
|
||||
print_message(MessageType::ERROR, &format!("Read config file {} error: {}", custom_oss_backupd_config_unrwaped, e));
|
||||
return None;
|
||||
},
|
||||
Ok(o) => return Some(o),
|
||||
};
|
||||
} else {
|
||||
print_message(MessageType::ERROR, &format!("Custom config file not found: {}", custom_oss_backupd_config_unrwaped));
|
||||
return None;
|
||||
}
|
||||
}
|
||||
// is not assigned by -c or --conifg FILE
|
||||
let oss_backupd_config_path = Path::new(OSS_BACKUPD_CONFIG);
|
||||
if oss_backupd_config_path.exists() {
|
||||
match fs::read_to_string(oss_backupd_config_path) {
|
||||
|
||||
@@ -13,7 +13,7 @@ use rust_util::{
|
||||
util_msg::*,
|
||||
};
|
||||
use oss_util::*;
|
||||
// use config_util::*;
|
||||
use config_util::*;
|
||||
// use pgp_util::OpenPGPTool;
|
||||
use opt::{
|
||||
Options,
|
||||
@@ -44,7 +44,8 @@ fn main() -> XResult<()> {
|
||||
// let openpgp_client = OpenPGPTool::from_file("sample.gpg")?;
|
||||
// openpgp_client.encrypt_file("a", "b.asc", true)?;
|
||||
|
||||
// let config_json = get_config_json();
|
||||
let config_json = get_config_json(None); // TODO
|
||||
|
||||
// let j = config_json.unwrap();
|
||||
// println!("{}", j);
|
||||
// let c = parse_config(&j);
|
||||
|
||||
Reference in New Issue
Block a user