Update release command

This commit is contained in:
sagie gur ari 2021-06-26 12:34:48 +00:00
parent fda0966424
commit dd760cfb50
2 changed files with 24 additions and 13 deletions

View file

@ -55,13 +55,14 @@ impl Command for CommandImpl {
(arguments[0].to_string(), false)
};
if recursive {
remove_handle_recursive(state, key);
let removed = if recursive {
remove_handle_recursive(state, key)
} else {
remove_handle(state, key);
}
let old_value = remove_handle(state, key);
old_value.is_some()
};
CommandResult::Continue(Some(true.to_string()))
CommandResult::Continue(Some(removed.to_string()))
}
}
}

View file

@ -68,30 +68,40 @@ pub(crate) fn remove_handle(
handle_state.remove(&key)
}
pub(crate) fn remove_handle_recursive(state: &mut HashMap<String, StateValue>, key: String) {
if let Some(state_value) = remove_handle(state, key.to_string()) {
match state_value {
pub(crate) fn remove_handle_recursive(
state: &mut HashMap<String, StateValue>,
key: String,
) -> bool {
match remove_handle(state, key.to_string()) {
Some(state_value) => match state_value {
StateValue::List(list) => {
for value in list {
if let StateValue::String(value) = value {
remove_handle_recursive(state, value)
remove_handle_recursive(state, value);
};
}
true
}
StateValue::Set(set) => {
for value in set {
remove_handle_recursive(state, value)
remove_handle_recursive(state, value);
}
true
}
StateValue::SubState(map) => {
for (_, map_value) in map {
if let StateValue::String(value) = map_value {
remove_handle_recursive(state, value)
remove_handle_recursive(state, value);
};
}
true
}
_ => (),
}
_ => true,
},
None => false,
}
}