Add special error case for alias (#10975)

Adds a special error, which is triggered by `alias foo=bar` style
commands. It adds a help string which recommends adding spaces.

Resolve #10958

---------

Co-authored-by: Jakub Žádník <kubouch@gmail.com>
This commit is contained in:
Andrej Kolchin 2023-11-08 19:35:40 +00:00 committed by GitHub
parent 86cd387439
commit 435abadd8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1005,7 +1005,28 @@ pub fn parse_alias(
working_set.add_decl(Box::new(decl));
}
if spans.len() < 4 {
// special case for `alias foo=bar`
if spans.len() == 2 && working_set.get_span_contents(spans[1]).contains(&b'=') {
let arg = String::from_utf8_lossy(working_set.get_span_contents(spans[1]));
// split at '='. Note that the output must never be None, the
// `unwrap` is just to avoid the possibility of panic, if the
// invariant is broken.
let (name, initial_value) = arg.split_once('=').unwrap_or((&arg, ""));
let name = if name.is_empty() { "{name}" } else { name };
let initial_value = if initial_value.is_empty() {
"{initial_value}"
} else {
initial_value
};
working_set.error(ParseError::IncorrectValue(
"alias argument".into(),
spans[1],
format!("Make sure to put spaces around '=': alias {name} = {initial_value}"),
))
} else if spans.len() < 4 {
working_set.error(ParseError::IncorrectValue(
"Incomplete alias".into(),
span(&spans[..split_id]),