Skip to content

Commit

Permalink
read from file only when it's not provided from CLI
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Dec 9, 2024
1 parent da8404d commit 716ea09
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mm2src/mm2_main/src/mm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,23 @@ pub fn mm2_main(version: String, datetime: String) {
/// Parses and returns the `first_arg` as JSON.
/// Attempts to load the config from `MM2.json` file if `first_arg` is None
pub fn get_mm2config(first_arg: Option<&str>) -> Result<Json, String> {
let conf_path = common::kdf_config_file().map_err(|e| e.to_string())?;
let conf_from_file = slurp(&conf_path);
let conf = match first_arg {
Some(s) => s,
Some(s) => s.to_owned(),
None => {
let conf_path = common::kdf_config_file().map_err(|e| e.to_string())?;
let conf_from_file = slurp(&conf_path);

if conf_from_file.is_empty() {
return ERR!(
"Config is not set from command line arg and {} file doesn't exist.",
conf_path.display()
);
}
try_s!(std::str::from_utf8(&conf_from_file))
try_s!(String::from_utf8(conf_from_file))
},
};

let mut conf: Json = match json::from_str(conf) {
let mut conf: Json = match json::from_str(&conf) {
Ok(json) => json,
// Syntax or io errors may include the conf string in the error message so we don't want to take risks and show these errors internals in the log.
// If new variants are added to the Error enum, there can be a risk of exposing the conf string in the error message when updating serde_json so
Expand Down

0 comments on commit 716ea09

Please sign in to comment.