Skip to content

Commit ffb84d0

Browse files
committed
Store alias StringLiteral as well for dumping
1 parent 4e651d8 commit ffb84d0

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
8888
self.recipes.push(recipe);
8989

9090
for attribute in &recipe.attributes {
91-
if let Attribute::Alias(name) = attribute {
91+
if let Attribute::Alias(name, _) = attribute {
9292
Self::define(&mut definitions, *name, "alias", false)?;
9393
self.aliases.insert(Alias {
9494
name: *name,

src/attribute.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::*;
99
#[strum_discriminants(derive(EnumString, Ord, PartialOrd))]
1010
#[strum_discriminants(strum(serialize_all = "kebab-case"))]
1111
pub(crate) enum Attribute<'src> {
12-
Alias(Name<'src>),
12+
Alias(Name<'src>, StringLiteral<'src>),
1313
Confirm(Option<StringLiteral<'src>>),
1414
Doc(Option<StringLiteral<'src>>),
1515
ExitMessage,
@@ -85,8 +85,9 @@ impl<'src> Attribute<'src> {
8585
.unwrap_or_default();
8686

8787
Ok(match discriminant {
88-
AttributeDiscriminant::Alias => Self::Alias({
89-
let delim = argument.unwrap().kind.delimiter_len();
88+
AttributeDiscriminant::Alias => {
89+
let string_literal = argument.unwrap();
90+
let delim = string_literal.kind.delimiter_len();
9091
let token = token.unwrap();
9192
let token = Token {
9293
kind: TokenKind::Identifier,
@@ -105,8 +106,8 @@ impl<'src> Attribute<'src> {
105106
}));
106107
}
107108

108-
Name::from_identifier(token)
109-
}),
109+
Self::Alias(Name::from_identifier(token), string_literal)
110+
}
110111
AttributeDiscriminant::Confirm => Self::Confirm(argument),
111112
AttributeDiscriminant::Doc => Self::Doc(argument),
112113
AttributeDiscriminant::ExitMessage => Self::ExitMessage,
@@ -141,7 +142,7 @@ impl<'src> Attribute<'src> {
141142
}
142143

143144
pub(crate) fn repeatable(&self) -> bool {
144-
matches!(self, Attribute::Group(_) | Attribute::Alias(_))
145+
matches!(self, Attribute::Group(_) | Attribute::Alias(_, _))
145146
}
146147
}
147148

@@ -150,8 +151,8 @@ impl Display for Attribute<'_> {
150151
write!(f, "{}", self.name())?;
151152

152153
match self {
153-
Self::Alias(argument) => write!(f, "({argument})")?,
154-
Self::Confirm(Some(argument))
154+
Self::Alias(_, argument)
155+
| Self::Confirm(Some(argument))
155156
| Self::Doc(Some(argument))
156157
| Self::Extension(argument)
157158
| Self::Group(argument)

tests/attributes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,17 @@ fn duplicate_non_repeatable_attributes_are_forbidden() {
254254
.status(EXIT_FAILURE)
255255
.run();
256256
}
257+
258+
#[test]
259+
fn aliases_can_be_defined_as_attributes() {
260+
Test::new()
261+
.justfile(
262+
"
263+
[alias('bar')]
264+
baz:
265+
",
266+
)
267+
.arg("bar")
268+
.status(EXIT_SUCCESS)
269+
.run();
270+
}

0 commit comments

Comments
 (0)