forked from mirrors/jj
cli: use deserialize to parse alias definition
Unfortunately, config::Value is lax and '[7]' could be parsed as '["7"]'. I don't like it, but I think that's actually better for consistency as we use config.get_string() in various places.
This commit is contained in:
parent
283231b1e4
commit
b6e06f6dc9
2 changed files with 2 additions and 28 deletions
|
@ -1371,32 +1371,6 @@ pub fn create_ui() -> (Ui, Result<(), CommandError>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn string_list_from_config(value: config::Value) -> Option<Vec<String>> {
|
||||
match value {
|
||||
config::Value {
|
||||
kind: config::ValueKind::Array(elements),
|
||||
..
|
||||
} => {
|
||||
let mut strings = vec![];
|
||||
for arg in elements {
|
||||
match arg {
|
||||
config::Value {
|
||||
kind: config::ValueKind::String(string_value),
|
||||
..
|
||||
} => {
|
||||
strings.push(string_value);
|
||||
}
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(strings)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_aliases(
|
||||
user_settings: &UserSettings,
|
||||
app: &clap::Command,
|
||||
|
@ -1432,7 +1406,7 @@ fn resolve_aliases(
|
|||
)));
|
||||
}
|
||||
if let Some(value) = aliases_map.remove(&alias_name) {
|
||||
if let Some(alias_definition) = string_list_from_config(value) {
|
||||
if let Ok(alias_definition) = value.try_deserialize::<Vec<String>>() {
|
||||
assert!(string_args.ends_with(&alias_args));
|
||||
string_args.truncate(string_args.len() - 1 - alias_args.len());
|
||||
string_args.extend(alias_definition);
|
||||
|
|
|
@ -180,7 +180,7 @@ fn test_alias_invalid_definition() {
|
|||
test_env.add_config(
|
||||
br#"[alias]
|
||||
non-list = 5
|
||||
non-string-list = [7]
|
||||
non-string-list = [[]]
|
||||
"#,
|
||||
);
|
||||
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["non-list"]);
|
||||
|
|
Loading…
Reference in a new issue