Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2135,28 +2135,31 @@ change their behavior.
|------|------|-------------|
| `[arg(ARG, help="HELP")]`<sup>1.46.0</sup> | recipe | Print help string `HELP` for `ARG` in usage messages. |
| `[arg(ARG, long="LONG")]`<sup>1.46.0</sup> | recipe | Require values of argument `ARG` to be passed as `--LONG` option. |
| `[arg(ARG, pattern="PATTERN")]`<sup>1.45.0</sup> | recipe | Require values of argument `ARG` to match regular expression `PATTERN`. |
| `[arg(ARG, short="S")]`<sup>1.46.0</sup> | recipe | Require values of argument `ARG` to be passed as short `-S` option. |
| `[arg(ARG, value="VALUE")]`<sup>1.46.0</sup> | recipe | Makes option `ARG` a flag which does not take a value. |
| `[arg(ARG, pattern="PATTERN")]`<sup>1.45.0</sup> | recipe | Require values of argument `ARG` to match regular expression `PATTERN`. |
| `[confirm]`<sup>1.17.0</sup> | recipe | Require confirmation prior to executing recipe. |
| `[confirm(PROMPT)]`<sup>1.23.0</sup> | recipe | Require confirmation prior to executing recipe with a custom prompt. |
| `[confirm]`<sup>1.17.0</sup> | recipe | Require confirmation prior to executing recipe. |
| `[default]`<sup>1.43.0</sup> | recipe | Use recipe as module's default recipe. |
| `[doc(DOC)]`<sup>1.27.0</sup> | module, recipe | Set recipe or module's [documentation comment](#documentation-comments) to `DOC`. |
| `[dragonfly]`<sup>master</sup> | recipe | Enable recipe on DragonFly BSD. |
| `[env(ENV_VAR, VALUE)]` <sup>master</sup> | recipe | Set environment variables for recipe. |
| `[extension(EXT)]`<sup>1.32.0</sup> | recipe | Set shebang recipe script's file extension to `EXT`. `EXT` should include a period if one is desired. |
| `[freebsd]`<sup>master</sup> | recipe | Enable recipe on FreeBSD. |
| `[group(NAME)]`<sup>1.27.0</sup> | module, recipe | Put recipe or module in [group](#groups) `NAME`. |
| `[linux]`<sup>1.8.0</sup> | recipe | Enable recipe on Linux. |
| `[macos]`<sup>1.8.0</sup> | recipe | Enable recipe on MacOS. |
| `[metadata(METADATA)]`<sup>1.42.0</sup> | recipe | Attach `METADATA` to recipe. |
| `[netbsd]`<sup>master</sup> | recipe | Enable recipe on NetBSD. |
| `[no-cd]`<sup>1.9.0</sup> | recipe | Don't change directory before executing recipe. |
| `[no-exit-message]`<sup>1.7.0</sup> | recipe | Don't print an error message if recipe fails. |
| `[no-quiet]`<sup>1.23.0</sup> | recipe | Override globally quiet recipes and always echo out the recipe. |
| `[openbsd]`<sup>1.38.0</sup> | recipe | Enable recipe on OpenBSD. |
| `[parallel]`<sup>1.42.0</sup> | recipe | Run this recipe's dependencies in parallel. |
| `[positional-arguments]`<sup>1.29.0</sup> | recipe | Turn on [positional arguments](#positional-arguments) for this recipe. |
| `[private]`<sup>1.10.0</sup> | alias, recipe | Make recipe, alias, or variable private. See [Private Recipes](#private-recipes). |
| `[script]`<sup>1.33.0</sup> | recipe | Execute recipe as script. See [script recipes](#script-recipes) for more details. |
| `[script(COMMAND)]`<sup>1.32.0</sup> | recipe | Execute recipe as a script interpreted by `COMMAND`. See [script recipes](#script-recipes) for more details. |
| `[script]`<sup>1.33.0</sup> | recipe | Execute recipe as script. See [script recipes](#script-recipes) for more details. |
| `[unix]`<sup>1.8.0</sup> | recipe | Enable recipe on Unixes. (Includes MacOS). |
| `[windows]`<sup>1.8.0</sup> | recipe | Enable recipe on Windows. |
| `[working-directory(PATH)]`<sup>1.38.0</sup> | recipe | Set recipe working directory. `PATH` may be relative or absolute. If relative, it is interpreted relative to the default working directory. |
Expand Down
12 changes: 12 additions & 0 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ pub(crate) enum Attribute<'src> {
Confirm(Option<StringLiteral<'src>>),
Default,
Doc(Option<StringLiteral<'src>>),
Dragonfly,
Env(StringLiteral<'src>, StringLiteral<'src>),
ExitMessage,
Extension(StringLiteral<'src>),
Freebsd,
Group(StringLiteral<'src>),
Linux,
Macos,
Metadata(Vec<StringLiteral<'src>>),
Netbsd,
NoCd,
NoExitMessage,
NoQuiet,
Expand All @@ -47,9 +50,12 @@ impl AttributeDiscriminant {
fn argument_range(self) -> RangeInclusive<usize> {
match self {
Self::Default
| Self::Dragonfly
| Self::ExitMessage
| Self::Freebsd
| Self::Linux
| Self::Macos
| Self::Netbsd
| Self::NoCd
| Self::NoExitMessage
| Self::NoQuiet
Expand Down Expand Up @@ -181,16 +187,19 @@ impl<'src> Attribute<'src> {
AttributeDiscriminant::Confirm => Self::Confirm(arguments.into_iter().next()),
AttributeDiscriminant::Default => Self::Default,
AttributeDiscriminant::Doc => Self::Doc(arguments.into_iter().next()),
AttributeDiscriminant::Dragonfly => Self::Dragonfly,
AttributeDiscriminant::Env => {
let [key, value]: [StringLiteral; 2] = arguments.try_into().unwrap();
Self::Env(key, value)
}
AttributeDiscriminant::ExitMessage => Self::ExitMessage,
AttributeDiscriminant::Extension => Self::Extension(arguments.into_iter().next().unwrap()),
AttributeDiscriminant::Freebsd => Self::Freebsd,
AttributeDiscriminant::Group => Self::Group(arguments.into_iter().next().unwrap()),
AttributeDiscriminant::Linux => Self::Linux,
AttributeDiscriminant::Macos => Self::Macos,
AttributeDiscriminant::Metadata => Self::Metadata(arguments),
AttributeDiscriminant::Netbsd => Self::Netbsd,
AttributeDiscriminant::NoCd => Self::NoCd,
AttributeDiscriminant::NoExitMessage => Self::NoExitMessage,
AttributeDiscriminant::NoQuiet => Self::NoQuiet,
Expand Down Expand Up @@ -295,9 +304,12 @@ impl Display for Attribute<'_> {
Self::Confirm(None)
| Self::Default
| Self::Doc(None)
| Self::Dragonfly
| Self::ExitMessage
| Self::Freebsd
| Self::Linux
| Self::Macos
| Self::Netbsd
| Self::NoCd
| Self::NoExitMessage
| Self::NoQuiet
Expand Down
8 changes: 7 additions & 1 deletion src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,21 @@ impl<'src, D> Recipe<'src, D> {
}

pub(crate) fn enabled(&self) -> bool {
let dragonfly = self.attributes.contains(AttributeDiscriminant::Dragonfly);
let freebsd = self.attributes.contains(AttributeDiscriminant::Freebsd);
let linux = self.attributes.contains(AttributeDiscriminant::Linux);
let macos = self.attributes.contains(AttributeDiscriminant::Macos);
let netbsd = self.attributes.contains(AttributeDiscriminant::Netbsd);
let openbsd = self.attributes.contains(AttributeDiscriminant::Openbsd);
let unix = self.attributes.contains(AttributeDiscriminant::Unix);
let windows = self.attributes.contains(AttributeDiscriminant::Windows);

(!windows && !linux && !macos && !openbsd && !unix)
(!windows && !linux && !macos && !openbsd && !freebsd && !dragonfly && !netbsd && !unix)
|| (cfg!(target_os = "dragonfly") && (dragonfly || unix))
|| (cfg!(target_os = "freebsd") && (freebsd || unix))
|| (cfg!(target_os = "linux") && (linux || unix))
|| (cfg!(target_os = "macos") && (macos || unix))
|| (cfg!(target_os = "netbsd") && (netbsd || unix))
|| (cfg!(target_os = "openbsd") && (openbsd || unix))
|| (cfg!(target_os = "windows") && windows)
|| (cfg!(unix) && unix)
Expand Down
15 changes: 9 additions & 6 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ fn all() {
Test::new()
.justfile(
"
[macos]
[dragonfly]
[freebsd]
[linux]
[macos]
[netbsd]
[no-exit-message]
[openbsd]
[unix]
[windows]
[no-exit-message]
foo:
exit 1
",
Expand Down Expand Up @@ -47,7 +50,7 @@ fn multiple_attributes_one_line() {
Test::new()
.justfile(
"
[macos,windows,linux,openbsd]
[macos,windows,linux,openbsd,freebsd,dragonfly,netbsd]
[no-exit-message]
foo:
exit 1
Expand All @@ -62,7 +65,7 @@ fn multiple_attributes_one_line_error_message() {
Test::new()
.justfile(
"
[macos,windows linux,openbsd]
[macos,windows linux,openbsd,freebsd,dragonfly,netbsd]
[no-exit-message]
foo:
exit 1
Expand All @@ -73,7 +76,7 @@ fn multiple_attributes_one_line_error_message() {
error: Expected ']', ':', ',', or '(', but found identifier
——▶ justfile:1:16
1 │ [macos,windows linux,openbsd]
1 │ [macos,windows linux,openbsd,freebsd,dragonfly,netbsd]
│ ^^^^^
",
)
Expand All @@ -85,7 +88,7 @@ fn multiple_attributes_one_line_duplicate_check() {
Test::new()
.justfile(
"
[macos, windows, linux, openbsd]
[macos, windows, linux, openbsd, freebsd, dragonfly, netbsd]
[linux]
foo:
exit 1
Expand Down
27 changes: 27 additions & 0 deletions tests/os_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ fn os() {
[openbsd]
foo:
echo bob

[freebsd]
foo:
echo corge

[dragonfly]
foo:
echo grault

[netbsd]
foo:
echo garply
",
)
.stdout(if cfg!(target_os = "macos") {
Expand All @@ -61,6 +73,12 @@ fn os() {
"quxx\n"
} else if cfg!(target_os = "openbsd") {
"bob\n"
} else if cfg!(target_os = "freebsd") {
"corge\n"
} else if cfg!(target_os = "dragonfly") {
"grault\n"
} else if cfg!(target_os = "netbsd") {
"garply\n"
} else {
panic!("unexpected os family")
})
Expand All @@ -72,6 +90,12 @@ fn os() {
"echo quxx\n"
} else if cfg!(target_os = "openbsd") {
"echo bob\n"
} else if cfg!(target_os = "freebsd") {
"echo corge\n"
} else if cfg!(target_os = "dragonfly") {
"echo grault\n"
} else if cfg!(target_os = "netbsd") {
"echo garply\n"
} else {
panic!("unexpected os family")
})
Expand All @@ -86,6 +110,9 @@ fn all() {
[linux]
[macos]
[openbsd]
[freebsd]
[dragonfly]
[netbsd]
[unix]
[windows]
foo:
Expand Down