diff --git a/src/attribute.rs b/src/attribute.rs index bf657a0..f9c5bfc 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -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 { diff --git a/src/parser.rs b/src/parser.rs index 857284d..3e4bb02 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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", diff --git a/tests/attributes.rs b/tests/attributes.rs index 9c79bb7..a604777 100644 --- a/tests/attributes.rs +++ b/tests/attributes.rs @@ -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] diff --git a/tests/groups.rs b/tests/groups.rs index 6c072e8..5834333 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -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(); +}