Add [ATTRIBUTE: VALUE]
shorthand (#2136)
This commit is contained in:
parent
4fbd03735a
commit
1ca53e8b22
@ -57,9 +57,7 @@ impl<'src> Attribute<'src> {
|
||||
})?;
|
||||
|
||||
let found = argument.as_ref().iter().count();
|
||||
|
||||
let range = discriminant.argument_range();
|
||||
|
||||
if !range.contains(&found) {
|
||||
return Err(
|
||||
name.error(CompileErrorKind::AttributeArgumentCountMismatch {
|
||||
|
@ -987,15 +987,18 @@ impl<'run, 'src> Parser<'run, 'src> {
|
||||
loop {
|
||||
let name = self.parse_name()?;
|
||||
|
||||
let argument = if self.accepted(ParenL)? {
|
||||
let argument = self.parse_string_literal()?;
|
||||
let maybe_argument = if self.accepted(Colon)? {
|
||||
let arg = self.parse_string_literal()?;
|
||||
Some(arg)
|
||||
} else if self.accepted(ParenL)? {
|
||||
let arg = self.parse_string_literal()?;
|
||||
self.expect(ParenR)?;
|
||||
Some(argument)
|
||||
Some(arg)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let attribute = Attribute::new(name, argument)?;
|
||||
let attribute = Attribute::new(name, maybe_argument)?;
|
||||
|
||||
if let Some(line) = attributes.get(&attribute) {
|
||||
return Err(name.error(CompileErrorKind::DuplicateAttribute {
|
||||
@ -1158,6 +1161,18 @@ mod tests {
|
||||
tree: (justfile (alias t test)),
|
||||
}
|
||||
|
||||
test! {
|
||||
name: single_argument_attribute_shorthand,
|
||||
text: "[group: 'some-group']\nalias t := test",
|
||||
tree: (justfile (alias t test)),
|
||||
}
|
||||
|
||||
test! {
|
||||
name: single_argument_attribute_shorthand_multiple_same_line,
|
||||
text: "[group: 'some-group', group: 'some-other-group']\nalias t := test",
|
||||
tree: (justfile (alias t test)),
|
||||
}
|
||||
|
||||
test! {
|
||||
name: aliases_multiple,
|
||||
text: "alias t := test\nalias b := build",
|
||||
|
@ -72,7 +72,7 @@ fn multiple_attributes_one_line_error_message() {
|
||||
)
|
||||
.stderr(
|
||||
"
|
||||
error: Expected ']', ',', or '(', but found identifier
|
||||
error: Expected ']', ':', ',', or '(', but found identifier
|
||||
——▶ justfile:1:17
|
||||
│
|
||||
1 │ [macos, windows linux]
|
||||
|
@ -144,3 +144,26 @@ fn list_groups_with_custom_prefix() {
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_groups_with_shorthand_syntax() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
[group: 'B']
|
||||
foo:
|
||||
|
||||
[group: 'A', group: 'B']
|
||||
bar:
|
||||
",
|
||||
)
|
||||
.args(["--groups", "--list-prefix", "..."])
|
||||
.stdout(
|
||||
"
|
||||
Recipe groups:
|
||||
...A
|
||||
...B
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user