-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add variadic parameters that accept zero or more arguments (#645)
Add "star" variadic parameters that accept zero or more arguments, distinguished with a `*` in front of the parameter name.
- Loading branch information
Showing
14 changed files
with
182 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -572,14 +572,14 @@ test triple=(arch + "-unknown-unknown"): | |
./test {{triple}} | ||
``` | ||
|
||
The last parameter of a recipe may be variadic, indicated with a `+` before the argument name: | ||
The last parameter of a recipe may be variadic, indicated with either a `+` or a `*` before the argument name: | ||
|
||
```make | ||
backup +FILES: | ||
scp {{FILES}} [email protected]: | ||
``` | ||
|
||
Variadic parameters accept one or more arguments and expand to a string containing those arguments separated by spaces: | ||
Variadic parameters prefixed with `+` accept _one or more_ arguments and expand to a string containing those arguments separated by spaces: | ||
|
||
```sh | ||
$ just backup FAQ.md GRAMMAR.md | ||
|
@@ -588,13 +588,20 @@ FAQ.md 100% 1831 1.8KB/s 00:00 | |
GRAMMAR.md 100% 1666 1.6KB/s 00:00 | ||
``` | ||
|
||
A variadic parameter with a default argument will accept zero or more arguments: | ||
Variadic parameters prefixed with `*` accept _zero or more_ arguments and expand to a string containing those arguments separated by spaces, or an empty string if no arguments are present: | ||
|
||
```make | ||
commit MESSAGE +FLAGS='': | ||
commit MESSAGE *FLAGS: | ||
git commit {{FLAGS}} -m "{{MESSAGE}}" | ||
``` | ||
|
||
Variadic parameters prefixed by `+` can be assigned default values. These are overridden by arguments passed on the command line: | ||
|
||
```make | ||
test +FLAGS='-q': | ||
cargo test {{FLAGS}} | ||
``` | ||
|
||
`{{...}}` substitutions may need to be quoted if they contains spaces. For example, if you have the following recipe: | ||
|
||
```make | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::common::*; | ||
|
||
/// Parameters can either be… | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
pub(crate) enum ParameterKind { | ||
/// …singular, accepting a single argument | ||
Singular, | ||
/// …variadic, accepting one or more arguments | ||
Plus, | ||
/// …variadic, accepting zero or more arguments | ||
Star, | ||
} | ||
|
||
impl ParameterKind { | ||
pub(crate) fn prefix(self) -> Option<&'static str> { | ||
match self { | ||
Self::Singular => None, | ||
Self::Plus => Some("+"), | ||
Self::Star => Some("*"), | ||
} | ||
} | ||
|
||
pub(crate) fn is_variadic(self) -> bool { | ||
self != Self::Singular | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.