Compare commits
No commits in common. "use-value-parser-dump-format" and "master" have entirely different histories.
use-value-
...
master
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
@ -30,6 +30,12 @@ jobs:
|
||||
- name: Format
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
- name: Completion Scripts
|
||||
run: |
|
||||
./bin/update-completions
|
||||
git diff --no-ext-diff --quiet --exit-code
|
||||
./tests/completions/just.bash
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
|
15
.github/workflows/release.yaml
vendored
15
.github/workflows/release.yaml
vendored
@ -73,17 +73,6 @@ jobs:
|
||||
id: ref-type
|
||||
run: cargo run --package ref-type -- --reference ${{ github.ref }} >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Generate Completion Scripts and Manpage
|
||||
run: |
|
||||
set -euxo pipefail
|
||||
cargo build
|
||||
mkdir -p completions
|
||||
for shell in bash elvish fish nu powershell zsh; do
|
||||
./target/debug/just --completions $shell > completions/just.$shell
|
||||
done
|
||||
mkdir -p man
|
||||
./target/debug/just --man > man/just.1
|
||||
|
||||
- name: Package
|
||||
id: package
|
||||
env:
|
||||
@ -95,7 +84,7 @@ jobs:
|
||||
shell: bash
|
||||
|
||||
- name: Publish Archive
|
||||
uses: softprops/action-gh-release@v2.0.6
|
||||
uses: softprops/action-gh-release@v2.0.5
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
with:
|
||||
draft: false
|
||||
@ -105,7 +94,7 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Publish Changelog
|
||||
uses: softprops/action-gh-release@v2.0.6
|
||||
uses: softprops/action-gh-release@v2.0.5
|
||||
if: >-
|
||||
${{
|
||||
startsWith(github.ref, 'refs/tags/')
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,7 +10,6 @@
|
||||
/fuzz/artifacts
|
||||
/fuzz/corpus
|
||||
/fuzz/target
|
||||
/man
|
||||
/target
|
||||
/test-utilities/Cargo.lock
|
||||
/test-utilities/target
|
||||
|
955
CHANGELOG.md
955
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
113
Cargo.lock
generated
113
Cargo.lock
generated
@ -67,9 +67,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.0"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
|
||||
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
@ -174,9 +174,9 @@ checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.99"
|
||||
version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695"
|
||||
checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
@ -221,19 +221,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.7"
|
||||
version = "4.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f"
|
||||
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.7"
|
||||
version = "4.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f"
|
||||
checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@ -244,38 +243,26 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.5.5"
|
||||
version = "4.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2020fa13af48afc65a9a87335bda648309ab3d154cd03c7ff95b378c7ed39c4"
|
||||
checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e"
|
||||
dependencies = [
|
||||
"clap 4.5.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
"clap 4.5.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70"
|
||||
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
|
||||
|
||||
[[package]]
|
||||
name = "clap_mangen"
|
||||
version = "0.2.21"
|
||||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74b70fc13e60c0e1d490dc50eb73a749be6d81f4ef03783df1d9b7b0c62bc937"
|
||||
checksum = "e1dd95b5ebb5c1c54581dd6346f3ed6a79a3eef95dd372fc2ac13d535535300e"
|
||||
dependencies = [
|
||||
"clap 4.5.7",
|
||||
"clap 4.5.4",
|
||||
"roff",
|
||||
]
|
||||
|
||||
@ -306,6 +293,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cradle"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7096122c1023d53de7298f322590170540ad3eba46bbc2750b495f098c27c09a"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.5"
|
||||
@ -509,6 +505,12 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
@ -591,15 +593,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "just"
|
||||
version = "1.29.1"
|
||||
version = "1.27.0"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"blake3",
|
||||
"camino",
|
||||
"chrono",
|
||||
"clap 4.5.7",
|
||||
"clap 4.5.4",
|
||||
"clap_complete",
|
||||
"clap_mangen",
|
||||
"cradle",
|
||||
"ctrlc",
|
||||
"derivative",
|
||||
"dirs",
|
||||
@ -675,9 +678,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||
|
||||
[[package]]
|
||||
name = "memmap2"
|
||||
@ -779,9 +782,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.85"
|
||||
version = "1.0.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
|
||||
checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@ -888,13 +891,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.5"
|
||||
version = "1.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata 0.4.7",
|
||||
"regex-automata 0.4.6",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
@ -906,9 +909,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.7"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@ -917,9 +920,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.4"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
|
||||
|
||||
[[package]]
|
||||
name = "roff"
|
||||
@ -960,18 +963,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.203"
|
||||
version = "1.0.202"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
|
||||
checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.203"
|
||||
version = "1.0.202"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
|
||||
checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1087,11 +1090,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.26.4"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
|
||||
checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"heck 0.4.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
@ -1122,9 +1125,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "target"
|
||||
version = "2.1.0"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e8f05f774b2db35bdad5a8237a90be1102669f8ea013fea9777b366d34ab145"
|
||||
checksum = "f4df6b0340c7cc29eb3b955cc588d145ed60651bf1ab939083295d19ec8cc282"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
@ -1221,9 +1224,9 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.13"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d"
|
||||
checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6"
|
||||
|
||||
[[package]]
|
||||
name = "update-contributors"
|
||||
@ -1234,9 +1237,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "just"
|
||||
version = "1.29.1"
|
||||
version = "1.27.0"
|
||||
authors = ["Casey Rodarmor <casey@rodarmor.com>"]
|
||||
autotests = false
|
||||
categories = ["command-line-utilities", "development-tools"]
|
||||
@ -22,7 +22,7 @@ ansi_term = "0.12.0"
|
||||
blake3 = { version = "1.5.0", features = ["rayon", "mmap"] }
|
||||
camino = "1.0.4"
|
||||
chrono = "0.4.38"
|
||||
clap = { version = "4.0.0", features = ["derive", "env", "wrap_help"] }
|
||||
clap = { version = "4.0.0", features = ["env", "wrap_help"] }
|
||||
clap_complete = "4.0.0"
|
||||
clap_mangen = "0.2.20"
|
||||
ctrlc = { version = "3.1.1", features = ["termination"] }
|
||||
@ -54,6 +54,7 @@ unicode-width = "0.1.0"
|
||||
uuid = { version = "1.0.0", features = ["v4"] }
|
||||
|
||||
[dev-dependencies]
|
||||
cradle = "0.2.0"
|
||||
executable-path = "1.0.0"
|
||||
pretty_assertions = "1.0.0"
|
||||
temptree = "0.2.0"
|
||||
|
134
README.md
134
README.md
@ -656,8 +656,8 @@ Available recipes:
|
||||
lint
|
||||
```
|
||||
|
||||
Recipes in [submodules](#modules1190) can be listed with `just --list PATH`,
|
||||
where `PATH` is a space- or `::`-separated module path:
|
||||
Recipes in submodules can be listed with `just --list PATH`, where `PATH` is a
|
||||
space- or `::`-separated module path:
|
||||
|
||||
```
|
||||
$ cat justfile
|
||||
@ -812,7 +812,6 @@ foo:
|
||||
| `dotenv-filename` | string | - | Load a `.env` file with a custom name, if present. |
|
||||
| `dotenv-load` | boolean | `false` | Load a `.env` file, if present. |
|
||||
| `dotenv-path` | string | - | Load a `.env` file from a custom path and error if not present. Overrides `dotenv-filename`. |
|
||||
| `dotenv-required` | boolean | `false` | Error if a `.env` file isn't found. |
|
||||
| `export` | boolean | `false` | Export all variables as environment variables. |
|
||||
| `fallback` | boolean | `false` | Search `justfile` in parent directory if the first recipe on the command line is not found. |
|
||||
| `ignore-comments` | boolean | `false` | Ignore recipe lines beginning with `#`. |
|
||||
@ -878,25 +877,17 @@ bar
|
||||
|
||||
#### Dotenv Settings
|
||||
|
||||
If any of `dotenv-load`, `dotenv-filename`, `dotenv-path`, or `dotenv-required`
|
||||
are set, `just` will try to load environment variables from a file.
|
||||
If `dotenv-load`, `dotenv-filename` or `dotenv-path` is set, `just` will load
|
||||
environment variables from a file.
|
||||
|
||||
If `dotenv-path` is set, `just` will look for a file at the given path, which
|
||||
may be absolute, or relative to the working directory.
|
||||
If `dotenv-path` is set, `just` will look for a file at the given path. It is
|
||||
an error if a dotenv file is not found at `dotenv-path`, but not an error if a
|
||||
dotenv file is not found with `dotenv-filename`.
|
||||
|
||||
If `dotenv-filename` is set `just` will look for a file at the given path,
|
||||
relative to the working directory and each of its ancestors.
|
||||
|
||||
If `dotenv-filename` is not set, but `dotenv-load` or `dotenv-required` are
|
||||
set, just will look for a file named `.env`, relative to the working directory
|
||||
and each of its ancestors.
|
||||
|
||||
`dotenv-filename` and `dotenv-path` and similar, but `dotenv-path` is only
|
||||
checked relative to the working directory, whereas `dotenv-filename` is checked
|
||||
relative to the working directory and each of its ancestors.
|
||||
|
||||
It is not an error if an environment file is not found, unless
|
||||
`dotenv-required` is set.
|
||||
Otherwise, `just` looks for a file named `.env` by default, unless
|
||||
`dotenv-filename` set, in which case the value of `dotenv-filename` is used.
|
||||
This file can be located in the same directory as your `justfile` or in a
|
||||
parent directory.
|
||||
|
||||
The loaded variables are environment variables, not `just` variables, and so
|
||||
must be accessed using `$VARIABLE_NAME` in recipes and backticks.
|
||||
@ -996,24 +987,10 @@ $ just test foo "bar baz"
|
||||
- bar baz
|
||||
```
|
||||
|
||||
Positional arguments may also be turned on on a per-recipe basis with the
|
||||
`[positional-arguments]` attribute<sup>1.29.0</sup>:
|
||||
|
||||
```just
|
||||
[positional-arguments]
|
||||
@foo bar:
|
||||
echo $0
|
||||
echo $1
|
||||
```
|
||||
|
||||
Note that PowerShell does not handle positional arguments in the same way as
|
||||
other shells, so turning on positional arguments will likely break recipes that
|
||||
use PowerShell.
|
||||
|
||||
#### Shell
|
||||
|
||||
The `shell` setting controls the command used to invoke recipe lines and
|
||||
backticks. Shebang recipes are unaffected. The default shell is `sh -cu`.
|
||||
backticks. Shebang recipes are unaffected.
|
||||
|
||||
```just
|
||||
# use python3 to execute recipe lines and backticks
|
||||
@ -1314,7 +1291,6 @@ foobar := x'~/$FOO/${BAR}'
|
||||
|------|-------------|
|
||||
| `$VAR` | value of environment variable `VAR` |
|
||||
| `${VAR}` | value of environment variable `VAR` |
|
||||
| `${VAR:-DEFAULT}` | value of environment variable `VAR`, or `DEFAULT` if `VAR` is not set |
|
||||
| Leading `~` | path to current user's home directory |
|
||||
| Leading `~USER` | path to `USER`'s home directory |
|
||||
|
||||
@ -1441,12 +1417,6 @@ $ just
|
||||
- `env(key)`<sup>1.15.0</sup> — Alias for `env_var(key)`.
|
||||
- `env(key, default)`<sup>1.15.0</sup> — Alias for `env_var_or_default(key, default)`.
|
||||
|
||||
#### Invocation Information
|
||||
|
||||
- `is_dependency()` - Returns the string `true` if the current recipe is being
|
||||
run as a dependency of another recipe, rather than being run directly,
|
||||
otherwise returns the string `false`.
|
||||
|
||||
#### Invocation Directory
|
||||
|
||||
- `invocation_directory()` - Retrieves the absolute path to the current
|
||||
@ -1642,16 +1612,6 @@ which will halt execution.
|
||||
characters. For example, `choose('64', HEX)` will generate a random
|
||||
64-character lowercase hex string.
|
||||
|
||||
#### Datetime
|
||||
|
||||
- `datetime(format)`<sup>master</sup> - Return local time with `format`.
|
||||
- `datetime_utc(format)`<sup>master</sup> - Return UTC time with `format`.
|
||||
|
||||
The arguments to `datetime` and `datetime_utc` are `strftime`-style format
|
||||
strings, see the
|
||||
[`chrono` library docs](https://docs.rs/chrono/latest/chrono/format/strftime/index.html)
|
||||
for details.
|
||||
|
||||
#### Semantic Versions
|
||||
|
||||
- `semver_matches(version, requirement)`<sup>1.16.0</sup> - Check whether a
|
||||
@ -1711,7 +1671,6 @@ Recipes may be annotated with attributes that change their behavior.
|
||||
| `[no-cd]`<sup>1.9.0</sup> | Don't change directory before executing recipe. |
|
||||
| `[no-exit-message]`<sup>1.7.0</sup> | Don't print an error message if recipe fails. |
|
||||
| `[no-quiet]`<sup>1.23.0</sup> | Override globally quiet recipes and always echo out the recipe. |
|
||||
| `[positional-arguments]`<sup>1.29.0</sup> | Turn on [positional arguments](#positional-arguments) for this recipe. |
|
||||
| `[private]`<sup>1.10.0</sup> | See [Private Recipes](#private-recipes). |
|
||||
| `[unix]`<sup>1.8.0</sup> | Enable recipe on Unixes. (Includes MacOS). |
|
||||
| `[windows]`<sup>1.8.0</sup> | Enable recipe on Windows. |
|
||||
@ -1817,7 +1776,7 @@ js-lint:
|
||||
[group('rust recipes')]
|
||||
[group('lint')]
|
||||
rust-lint:
|
||||
echo 'Running Rust linter…'
|
||||
echo 'Runninng Rust linter…'
|
||||
|
||||
[group('lint')]
|
||||
cpp-lint:
|
||||
@ -1871,8 +1830,6 @@ Recipe groups:
|
||||
rust recipes
|
||||
```
|
||||
|
||||
Use `just --groups --unsorted` to print groups in their justfile order.
|
||||
|
||||
### Command Evaluation Using Backticks
|
||||
|
||||
Backticks can be used to store the result of commands:
|
||||
@ -2087,23 +2044,6 @@ a $A $B=`echo $A`:
|
||||
When [export](#export) is set, all `just` variables are exported as environment
|
||||
variables.
|
||||
|
||||
#### Unexporting Environment Variables<sup>1.29.0</sup>
|
||||
|
||||
Environment variables can be unexported with the `unexport keyword`:
|
||||
|
||||
```just
|
||||
unexport FOO
|
||||
|
||||
@foo:
|
||||
echo $FOO
|
||||
```
|
||||
|
||||
```
|
||||
$ export FOO=bar
|
||||
$ just foo
|
||||
sh: FOO: unbound variable
|
||||
```
|
||||
|
||||
#### Getting Environment Variables from the environment
|
||||
|
||||
Environment variables from the environment are passed automatically to the
|
||||
@ -3145,7 +3085,7 @@ import? 'foo/bar.just'
|
||||
|
||||
Missing source files for optional imports do not produce an error.
|
||||
|
||||
### Modules<sup>1.19.0</sup>
|
||||
### Modules <sup>1.19.0</sup>
|
||||
|
||||
A `justfile` can declare modules using `mod` statements. `mod` statements are
|
||||
currently unstable, so you'll need to use the `--unstable` flag, or set the
|
||||
@ -3390,9 +3330,9 @@ foo argument:
|
||||
touch "$1"
|
||||
```
|
||||
|
||||
This defeats `just`'s ability to catch typos, for example if you type `$2`
|
||||
instead of `$1`, but works for all possible values of `argument`, including
|
||||
those with double quotes.
|
||||
This defeats `just`'s ability to catch typos, for example if you type `$2`, but
|
||||
works for all possible values of `argument`, including those with double
|
||||
quotes.
|
||||
|
||||
#### Exported Arguments
|
||||
|
||||
@ -3523,18 +3463,18 @@ complete -F _just -o bashdefault -o default j
|
||||
|
||||
### Shell Completion Scripts
|
||||
|
||||
Shell completion scripts for Bash, Elvish, Fish, Nushell, PowerShell, and Zsh
|
||||
are available [release archives](https://github.com/casey/just/releases).
|
||||
Shell completion scripts for Bash, Zsh, Fish, PowerShell, and Elvish are
|
||||
available in the
|
||||
[completions](https://github.com/casey/just/tree/master/completions) directory.
|
||||
Please refer to your shell's documentation for how to install them.
|
||||
|
||||
The `just` binary can also generate the same completion scripts at runtime
|
||||
using `just --completions SHELL`:
|
||||
The `just` binary can also generate the same completion scripts at runtime,
|
||||
using the `--completions` command:
|
||||
|
||||
```sh
|
||||
$ just --completions zsh > just.zsh
|
||||
```
|
||||
|
||||
Please refer to your shell's documentation for how to install them.
|
||||
|
||||
*macOS Note:* Recent versions of macOS use zsh as the default shell. If you use
|
||||
Homebrew to install `just`, it will automatically install the most recent copy
|
||||
of the zsh completion script in the Homebrew zsh directory, which the built-in
|
||||
@ -3657,33 +3597,6 @@ Node.js `package.json` files:
|
||||
export PATH := "./node_modules/.bin:" + env_var('PATH')
|
||||
```
|
||||
|
||||
### Paths on Windows
|
||||
|
||||
On Windows, functions that return paths will return `\`-separated paths. When
|
||||
not using PowerShell or `cmd.exe` these paths should be quoted to prevent the
|
||||
`\`s from being intepreted as character escapes:
|
||||
|
||||
```just
|
||||
ls:
|
||||
echo '{{absolute_path(".")}}'
|
||||
```
|
||||
|
||||
### Remote Justfiles
|
||||
|
||||
If you wish to include a `mod` or `import` source file in many `justfiles`
|
||||
without needing to duplicate it, you can use an optional `mod` or `import`,
|
||||
along with a recipe to fetch the module source:
|
||||
|
||||
```just
|
||||
import? 'foo.just'
|
||||
|
||||
fetch:
|
||||
curl https://raw.githubusercontent.com/casey/just/master/justfile > foo.just
|
||||
```
|
||||
|
||||
Given the above `justfile`, after running `just fetch`, the recipes in
|
||||
`foo.just` will be available.
|
||||
|
||||
### Alternatives and Prior Art
|
||||
|
||||
There is no shortage of command runners! Some more or less similar alternatives
|
||||
@ -3751,6 +3664,7 @@ Release x.y.z
|
||||
- Update changelog
|
||||
- Update changelog contributor credits
|
||||
- Update dependencies
|
||||
- Update man page
|
||||
- Update version references in readme
|
||||
```
|
||||
|
||||
|
124
README.中文.md
124
README.中文.md
@ -50,7 +50,7 @@ Yay, all your tests passed!
|
||||
|
||||
- 错误会尽可能被静态地解决。未知的配方和循环依赖关系会在运行之前被报告。
|
||||
|
||||
- `just` 可以 [加载`.env`文件](#环境变量加载),简化环境变量注入。
|
||||
- `just` 可以 [加载`.env`文件](#env-集成),简化环境变量注入。
|
||||
|
||||
- 配方可以在 [命令行中列出](#列出可用的配方)。
|
||||
|
||||
@ -641,22 +641,18 @@ foo:
|
||||
|
||||
#### 设置一览表
|
||||
|
||||
| 名称 | 值 | 默认 | 描述 |
|
||||
| --------------------------- | ------------------ | ----- | --------------------------------------------------------------------------------------- |
|
||||
| `allow-duplicate-recipes` | boolean | False | 允许在 `justfile` 后面出现的配方覆盖之前的同名配方 |
|
||||
| `allow-duplicate-variables` | boolean | False | 允许在 `justfile` 后面出现的变量覆盖之前的同名变量 |
|
||||
| `dotenv-filename` | string | - | 如果有自定义名称的 `.env` 环境变量文件的话,则将其加载 |
|
||||
| `dotenv-load` | boolean | False | 如果有`.env` 环境变量文件的话,则将其加载 |
|
||||
| `dotenv-path` | string | - | 从自定义路径中加载 `.env` 环境变量文件, 文件不存在将会报错。可以覆盖 `dotenv-filename` |
|
||||
| `dotenv-required` | boolean | False | 如果 `.env` 环境变量文件不存在的话,需要报错 |
|
||||
| `export` | boolean | False | 将所有变量导出为环境变量 |
|
||||
| `fallback` | boolean | False | 如果命令行中的第一个配方没有找到,则在父目录中搜索 `justfile` |
|
||||
| `ignore-comments` | boolean | False | 忽略以`#`开头的配方行 |
|
||||
| `positional-arguments` | boolean | False | 传递位置参数 |
|
||||
| `shell` | `[COMMAND, ARGS…]` | - | 设置用于调用配方和评估反引号内包裹内容的命令 |
|
||||
| `tempdir` | string | - | 在 `tempdir` 位置创建临时目录,而不是系统默认的临时目录 |
|
||||
| `windows-powershell` | boolean | False | 在 Windows 上使用 PowerShell 作为默认 Shell(废弃,建议使用 `windows-shell`) |
|
||||
| `windows-shell` | `[COMMAND, ARGS…]` | - | 设置用于调用配方和评估反引号内包裹内容的命令 |
|
||||
| 名称 | 值 | 默认 | 描述 |
|
||||
| ------------------------- | ------------------ | --------|------------------------------------------------------------------------------- |
|
||||
| `allow-duplicate-recipes` | boolean | False | 允许在 `justfile` 后面出现的配方覆盖之前的同名配方 |
|
||||
| `dotenv-load` | boolean | False | 如果有`.env` 环境变量文件的话,则将其加载 |
|
||||
| `export` | boolean | False | 将所有变量导出为环境变量 |
|
||||
| `fallback` | boolean | False | 如果命令行中的第一个配方没有找到,则在父目录中搜索 `justfile` |
|
||||
| `ignore-comments` | boolean | False | 忽略以`#`开头的配方行 |
|
||||
| `positional-arguments` | boolean | False | 传递位置参数 |
|
||||
| `shell` | `[COMMAND, ARGS…]` | - | 设置用于调用配方和评估反引号内包裹内容的命令 |
|
||||
| `tempdir` | string | - | 在 `tempdir` 位置创建临时目录,而不是系统默认的临时目录 |
|
||||
| `windows-powershell` | boolean | False | 在 Windows 上使用 PowerShell 作为默认 Shell(废弃,建议使用 `windows-shell`) |
|
||||
| `windows-shell` | `[COMMAND, ARGS…]` | - | 设置用于调用配方和评估反引号内包裹内容的命令 |
|
||||
|
||||
Bool 类型设置可以写成:
|
||||
|
||||
@ -689,69 +685,9 @@ $ just foo
|
||||
bar
|
||||
```
|
||||
|
||||
#### 允许重复的变量
|
||||
如果 `allow-duplicate-variables` 被设置为 `true`,那么定义多个同名的变量将不会报错。默认为 `false`。
|
||||
|
||||
```just
|
||||
set allow-duplicate-variables
|
||||
|
||||
a := "foo"
|
||||
a := "bar"
|
||||
|
||||
@foo:
|
||||
echo $a
|
||||
```
|
||||
|
||||
```sh
|
||||
$ just foo
|
||||
bar
|
||||
```
|
||||
|
||||
#### 环境变量加载
|
||||
|
||||
如果 `dotenv-load`, `dotenv-filename`, `dotenv-path`, or `dotenv-required`
|
||||
中任意一项被设置, `just` 会尝试从文件中加载环境变量
|
||||
|
||||
如果设置了 `dotenv-path`, `just` 会在指定的路径下搜索文件,该路径可以是绝对路径,
|
||||
也可以是基于当前工作路径的相对路径
|
||||
|
||||
如果设置了 `dotenv-filename`,`just` 会在指定的相对路径,以及其所有的上层目录中,搜索指定文件
|
||||
|
||||
如果没有设置 `dotenv-filename`,但是设置了 `dotenv-load` 或 `dotenv-required`,
|
||||
`just` 会在当前工作路径,以及其所有的上层目录中,寻找名为 `.env` 的文件。
|
||||
|
||||
`dotenv-filename` 和 `dotenv-path` 很相似,但是 `dotenv-path` 只会检查指定的目录
|
||||
而 `dotenv-filename` 会检查指定目录以及其所有的上层目录。
|
||||
|
||||
如果没有找到环境变量文件也不会报错,除非设置了 `dotenv-required`。
|
||||
|
||||
从文件中加载的变量是环境变量,而非 `just` 变量,所以在配方和反引号中需要必须通过 `$VARIABLE_NAME` 来调用。
|
||||
|
||||
比如,如果你的 `.env` 文件包含以下内容:
|
||||
|
||||
```sh
|
||||
# a comment, will be ignored
|
||||
DATABASE_ADDRESS=localhost:6379
|
||||
SERVER_PORT=1337
|
||||
```
|
||||
|
||||
并且你的 `justfile` 包含:
|
||||
|
||||
```just
|
||||
set dotenv-load
|
||||
|
||||
serve:
|
||||
@echo "Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…"
|
||||
./server --database $DATABASE_ADDRESS --port $SERVER_PORT
|
||||
```
|
||||
|
||||
`just serve` 将会输出:
|
||||
|
||||
```sh
|
||||
$ just serve
|
||||
Starting server with database localhost:6379 on port 1337…
|
||||
./server --database $DATABASE_ADDRESS --port $SERVER_PORT
|
||||
```
|
||||
如果将 `dotenv-load` 设置为 `true`,并且存在 `.env` 文件,则该环境配置文件将被加载。默认为 `false`。
|
||||
|
||||
#### 导出
|
||||
|
||||
@ -917,6 +853,36 @@ Available recipes:
|
||||
test # test stuff
|
||||
```
|
||||
|
||||
### `.env` 集成
|
||||
|
||||
如果 [`dotenv-load`](#环境变量加载) 被设置,`just` 将从一个名为 `.env` 的文件中加载环境变量。这个文件可以和你的 `justfile` 位于同一目录下,或者位于其父目录下。这些变量是环境变量,而不是 `just` 的变量,因此必须使用 `$VARIABLE_NAME` 在配方和反引号中访问。
|
||||
|
||||
例如,假如你的 `.env` 文件包含:
|
||||
|
||||
```sh
|
||||
# 注释,将被忽略
|
||||
DATABASE_ADDRESS=localhost:6379
|
||||
SERVER_PORT=1337
|
||||
```
|
||||
|
||||
而你的 `justfile` 包含:
|
||||
|
||||
```just
|
||||
set dotenv-load
|
||||
|
||||
serve:
|
||||
@echo "Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…"
|
||||
./server --database $DATABASE_ADDRESS --port $SERVER_PORT
|
||||
```
|
||||
|
||||
`just serve` 将会输出:
|
||||
|
||||
```sh
|
||||
$ just serve
|
||||
Starting server with database localhost:6379 on port 1337…
|
||||
./server --database $DATABASE_ADDRESS --port $SERVER_PORT
|
||||
```
|
||||
|
||||
### 变量和替换
|
||||
|
||||
支持在变量、字符串、拼接、路径连接和替换中使用 `{{…}}` :
|
||||
@ -1497,7 +1463,7 @@ HOME is '/home/myuser'
|
||||
|
||||
#### 从 `.env` 文件加载环境变量
|
||||
|
||||
如果 [dotenv-load](#环境变量加载) 被设置,`just` 将从 `.env` 文件中加载环境变量。该文件中的变量将作为环境变量提供给配方。参见 [环境变量集成](#环境变量加载) 以获得更多信息。
|
||||
如果 [dotenv-load](#环境变量加载) 被设置,`just` 将从 `.env` 文件中加载环境变量。该文件中的变量将作为环境变量提供给配方。参见 [环境变量集成](#env-集成) 以获得更多信息。
|
||||
|
||||
#### 从环境变量中设置 `just` 变量
|
||||
|
||||
|
13
bin/update-completions
Executable file
13
bin/update-completions
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
cargo build
|
||||
|
||||
for script in completions/*; do
|
||||
shell=${script##*.}
|
||||
if [ $shell == nu ]; then
|
||||
continue
|
||||
fi
|
||||
./target/debug/just --completions $shell > $script
|
||||
done
|
165
completions/just.bash
Normal file
165
completions/just.bash
Normal file
@ -0,0 +1,165 @@
|
||||
_just() {
|
||||
local i cur prev words cword opts cmd
|
||||
COMPREPLY=()
|
||||
|
||||
# Modules use "::" as the separator, which is considered a wordbreak character in bash.
|
||||
# The _get_comp_words_by_ref function is a hack to allow for exceptions to this rule without
|
||||
# modifying the global COMP_WORDBREAKS environment variable.
|
||||
if type _get_comp_words_by_ref &>/dev/null; then
|
||||
_get_comp_words_by_ref -n : cur prev words cword
|
||||
else
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
words=$COMP_WORDS
|
||||
cword=$COMP_CWORD
|
||||
fi
|
||||
|
||||
cmd=""
|
||||
opts=""
|
||||
|
||||
for i in ${words[@]}
|
||||
do
|
||||
case "${cmd},${i}" in
|
||||
",$1")
|
||||
cmd="just"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "${cmd}" in
|
||||
just)
|
||||
opts="-n -f -q -u -v -d -c -e -l -s -E -g -h -V --check --chooser --color --command-color --yes --dry-run --dump-format --highlight --list-heading --list-prefix --no-aliases --no-deps --no-dotenv --no-highlight --justfile --quiet --set --shell --shell-arg --shell-command --clear-shell-args --unsorted --unstable --verbose --working-directory --changelog --choose --command --completions --dump --edit --evaluate --fmt --init --list --groups --man --show --summary --variables --dotenv-filename --dotenv-path --global-justfile --timestamp --timestamp-format --help --version [ARGUMENTS]..."
|
||||
if [[ ${cur} == -* ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
elif [[ ${cword} -eq 1 ]]; then
|
||||
local recipes=$(just --summary 2> /dev/null)
|
||||
|
||||
if echo "${cur}" | \grep -qF '/'; then
|
||||
local path_prefix=$(echo "${cur}" | sed 's/[/][^/]*$/\//')
|
||||
local recipes=$(just --summary 2> /dev/null -- "${path_prefix}")
|
||||
local recipes=$(printf "${path_prefix}%s\t" $recipes)
|
||||
fi
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
COMPREPLY=( $(compgen -W "${recipes}" -- "${cur}") )
|
||||
if type __ltrim_colon_completions &>/dev/null; then
|
||||
__ltrim_colon_completions "$cur"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
case "${prev}" in
|
||||
--chooser)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--color)
|
||||
COMPREPLY=($(compgen -W "auto always never" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--command-color)
|
||||
COMPREPLY=($(compgen -W "black blue cyan green purple red yellow" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--dump-format)
|
||||
COMPREPLY=($(compgen -W "just json" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--list-heading)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--list-prefix)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--justfile)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-f)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--set)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--shell)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--shell-arg)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--working-directory)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-d)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--command)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-c)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--completions)
|
||||
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--list)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-l)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--show)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-s)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--dotenv-filename)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--dotenv-path)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-E)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--timestamp-format)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
|
||||
complete -F _just -o nosort -o bashdefault -o default just
|
||||
else
|
||||
complete -F _just -o bashdefault -o default just
|
||||
fi
|
84
completions/just.elvish
Normal file
84
completions/just.elvish
Normal file
@ -0,0 +1,84 @@
|
||||
use builtin;
|
||||
use str;
|
||||
|
||||
set edit:completion:arg-completer[just] = {|@words|
|
||||
fn spaces {|n|
|
||||
builtin:repeat $n ' ' | str:join ''
|
||||
}
|
||||
fn cand {|text desc|
|
||||
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
|
||||
}
|
||||
var command = 'just'
|
||||
for word $words[1..-1] {
|
||||
if (str:has-prefix $word '-') {
|
||||
break
|
||||
}
|
||||
set command = $command';'$word
|
||||
}
|
||||
var completions = [
|
||||
&'just'= {
|
||||
cand --chooser 'Override binary invoked by `--choose`'
|
||||
cand --color 'Print colorful output'
|
||||
cand --command-color 'Echo recipe lines in <COMMAND-COLOR>'
|
||||
cand --dump-format 'Dump justfile as <FORMAT>'
|
||||
cand --list-heading 'Print <TEXT> before list'
|
||||
cand --list-prefix 'Print <TEXT> before each list item'
|
||||
cand -f 'Use <JUSTFILE> as justfile'
|
||||
cand --justfile 'Use <JUSTFILE> as justfile'
|
||||
cand --set 'Override <VARIABLE> with <VALUE>'
|
||||
cand --shell 'Invoke <SHELL> to run recipes'
|
||||
cand --shell-arg 'Invoke shell with <SHELL-ARG> as an argument'
|
||||
cand -d 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set'
|
||||
cand --working-directory 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set'
|
||||
cand -c 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set'
|
||||
cand --command 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set'
|
||||
cand --completions 'Print shell completion script for <SHELL>'
|
||||
cand -l 'List available recipes'
|
||||
cand --list 'List available recipes'
|
||||
cand -s 'Show recipe at <PATH>'
|
||||
cand --show 'Show recipe at <PATH>'
|
||||
cand --dotenv-filename 'Search for environment file named <DOTENV-FILENAME> instead of `.env`'
|
||||
cand -E 'Load <DOTENV-PATH> as environment file instead of searching for one'
|
||||
cand --dotenv-path 'Load <DOTENV-PATH> as environment file instead of searching for one'
|
||||
cand --timestamp-format 'Timestamp format string'
|
||||
cand --check 'Run `--fmt` in ''check'' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.'
|
||||
cand --yes 'Automatically confirm all recipes.'
|
||||
cand -n 'Print what just would do without doing it'
|
||||
cand --dry-run 'Print what just would do without doing it'
|
||||
cand --highlight 'Highlight echoed recipe lines in bold'
|
||||
cand --no-aliases 'Don''t show aliases in list'
|
||||
cand --no-deps 'Don''t run recipe dependencies'
|
||||
cand --no-dotenv 'Don''t load `.env` file'
|
||||
cand --no-highlight 'Don''t highlight echoed recipe lines in bold'
|
||||
cand -q 'Suppress all output'
|
||||
cand --quiet 'Suppress all output'
|
||||
cand --shell-command 'Invoke <COMMAND> with the shell used to run recipe lines and backticks'
|
||||
cand --clear-shell-args 'Clear shell arguments'
|
||||
cand -u 'Return list and summary entries in source order'
|
||||
cand --unsorted 'Return list and summary entries in source order'
|
||||
cand --unstable 'Enable unstable features'
|
||||
cand -v 'Use verbose output'
|
||||
cand --verbose 'Use verbose output'
|
||||
cand --changelog 'Print changelog'
|
||||
cand --choose 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
|
||||
cand --dump 'Print justfile'
|
||||
cand -e 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
|
||||
cand --edit 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
|
||||
cand --evaluate 'Evaluate and print all variables. If a variable name is given as an argument, only print that variable''s value.'
|
||||
cand --fmt 'Format and overwrite justfile'
|
||||
cand --init 'Initialize new justfile in project root'
|
||||
cand --groups 'List recipe groups'
|
||||
cand --man 'Print man page'
|
||||
cand --summary 'List names of available recipes'
|
||||
cand --variables 'List names of variables'
|
||||
cand -g 'Use global justfile'
|
||||
cand --global-justfile 'Use global justfile'
|
||||
cand --timestamp 'Print recipe command timestamps'
|
||||
cand -h 'Print help'
|
||||
cand --help 'Print help'
|
||||
cand -V 'Print version'
|
||||
cand --version 'Print version'
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
}
|
84
completions/just.fish
Normal file
84
completions/just.fish
Normal file
@ -0,0 +1,84 @@
|
||||
function __fish_just_complete_recipes
|
||||
just --list 2> /dev/null | tail -n +2 | awk '{
|
||||
command = $1;
|
||||
args = $0;
|
||||
desc = "";
|
||||
delim = "";
|
||||
sub(/^[[:space:]]*[^[:space:]]*/, "", args);
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", args);
|
||||
|
||||
if (match(args, /#.*/)) {
|
||||
desc = substr(args, RSTART+2, RLENGTH);
|
||||
args = substr(args, 0, RSTART-1);
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", args);
|
||||
}
|
||||
|
||||
gsub(/\+|=[`\'"][^`\'"]*[`\'"]/, "", args);
|
||||
gsub(/ /, ",", args);
|
||||
|
||||
if (args != ""){
|
||||
args = "Args: " args;
|
||||
}
|
||||
|
||||
if (args != "" && desc != "") {
|
||||
delim = "; ";
|
||||
}
|
||||
|
||||
print command "\t" args delim desc
|
||||
}'
|
||||
end
|
||||
|
||||
# don't suggest files right off
|
||||
complete -c just -n "__fish_is_first_arg" --no-files
|
||||
|
||||
# complete recipes
|
||||
complete -c just -a '(__fish_just_complete_recipes)'
|
||||
|
||||
# autogenerated completions
|
||||
complete -c just -l chooser -d 'Override binary invoked by `--choose`' -r
|
||||
complete -c just -l color -d 'Print colorful output' -r -f -a "{auto '',always '',never ''}"
|
||||
complete -c just -l command-color -d 'Echo recipe lines in <COMMAND-COLOR>' -r -f -a "{black '',blue '',cyan '',green '',purple '',red '',yellow ''}"
|
||||
complete -c just -l dump-format -d 'Dump justfile as <FORMAT>' -r -f -a "{just '',json ''}"
|
||||
complete -c just -l list-heading -d 'Print <TEXT> before list' -r
|
||||
complete -c just -l list-prefix -d 'Print <TEXT> before each list item' -r
|
||||
complete -c just -s f -l justfile -d 'Use <JUSTFILE> as justfile' -r -F
|
||||
complete -c just -l set -d 'Override <VARIABLE> with <VALUE>' -r
|
||||
complete -c just -l shell -d 'Invoke <SHELL> to run recipes' -r
|
||||
complete -c just -l shell-arg -d 'Invoke shell with <SHELL-ARG> as an argument' -r
|
||||
complete -c just -s d -l working-directory -d 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set' -r -F
|
||||
complete -c just -s c -l command -d 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set' -r
|
||||
complete -c just -l completions -d 'Print shell completion script for <SHELL>' -r -f -a "{bash '',elvish '',fish '',powershell '',zsh ''}"
|
||||
complete -c just -s l -l list -d 'List available recipes' -r
|
||||
complete -c just -s s -l show -d 'Show recipe at <PATH>' -r
|
||||
complete -c just -l dotenv-filename -d 'Search for environment file named <DOTENV-FILENAME> instead of `.env`' -r
|
||||
complete -c just -s E -l dotenv-path -d 'Load <DOTENV-PATH> as environment file instead of searching for one' -r -F
|
||||
complete -c just -l timestamp-format -d 'Timestamp format string' -r
|
||||
complete -c just -l check -d 'Run `--fmt` in \'check\' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.'
|
||||
complete -c just -l yes -d 'Automatically confirm all recipes.'
|
||||
complete -c just -s n -l dry-run -d 'Print what just would do without doing it'
|
||||
complete -c just -l highlight -d 'Highlight echoed recipe lines in bold'
|
||||
complete -c just -l no-aliases -d 'Don\'t show aliases in list'
|
||||
complete -c just -l no-deps -d 'Don\'t run recipe dependencies'
|
||||
complete -c just -l no-dotenv -d 'Don\'t load `.env` file'
|
||||
complete -c just -l no-highlight -d 'Don\'t highlight echoed recipe lines in bold'
|
||||
complete -c just -s q -l quiet -d 'Suppress all output'
|
||||
complete -c just -l shell-command -d 'Invoke <COMMAND> with the shell used to run recipe lines and backticks'
|
||||
complete -c just -l clear-shell-args -d 'Clear shell arguments'
|
||||
complete -c just -s u -l unsorted -d 'Return list and summary entries in source order'
|
||||
complete -c just -l unstable -d 'Enable unstable features'
|
||||
complete -c just -s v -l verbose -d 'Use verbose output'
|
||||
complete -c just -l changelog -d 'Print changelog'
|
||||
complete -c just -l choose -d 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`'
|
||||
complete -c just -l dump -d 'Print justfile'
|
||||
complete -c just -s e -l edit -d 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`'
|
||||
complete -c just -l evaluate -d 'Evaluate and print all variables. If a variable name is given as an argument, only print that variable\'s value.'
|
||||
complete -c just -l fmt -d 'Format and overwrite justfile'
|
||||
complete -c just -l init -d 'Initialize new justfile in project root'
|
||||
complete -c just -l groups -d 'List recipe groups'
|
||||
complete -c just -l man -d 'Print man page'
|
||||
complete -c just -l summary -d 'List names of available recipes'
|
||||
complete -c just -l variables -d 'List names of variables'
|
||||
complete -c just -s g -l global-justfile -d 'Use global justfile'
|
||||
complete -c just -l timestamp -d 'Print recipe command timestamps'
|
||||
complete -c just -s h -l help -d 'Print help'
|
||||
complete -c just -s V -l version -d 'Print version'
|
8
completions/just.nu
Normal file
8
completions/just.nu
Normal file
@ -0,0 +1,8 @@
|
||||
def "nu-complete just" [] {
|
||||
(^just --dump --unstable --dump-format json | from json).recipes | transpose recipe data | flatten | where {|row| $row.private == false } | select recipe doc parameters | rename value description
|
||||
}
|
||||
|
||||
# Just: A Command Runner
|
||||
export extern "just" [
|
||||
...recipe: string@"nu-complete just", # Recipe(s) to run, may be with argument(s)
|
||||
]
|
110
completions/just.powershell
Normal file
110
completions/just.powershell
Normal file
@ -0,0 +1,110 @@
|
||||
using namespace System.Management.Automation
|
||||
using namespace System.Management.Automation.Language
|
||||
|
||||
Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
|
||||
param($wordToComplete, $commandAst, $cursorPosition)
|
||||
|
||||
$commandElements = $commandAst.CommandElements
|
||||
$command = @(
|
||||
'just'
|
||||
for ($i = 1; $i -lt $commandElements.Count; $i++) {
|
||||
$element = $commandElements[$i]
|
||||
if ($element -isnot [StringConstantExpressionAst] -or
|
||||
$element.StringConstantType -ne [StringConstantType]::BareWord -or
|
||||
$element.Value.StartsWith('-') -or
|
||||
$element.Value -eq $wordToComplete) {
|
||||
break
|
||||
}
|
||||
$element.Value
|
||||
}) -join ';'
|
||||
|
||||
$completions = @(switch ($command) {
|
||||
'just' {
|
||||
[CompletionResult]::new('--chooser', 'chooser', [CompletionResultType]::ParameterName, 'Override binary invoked by `--choose`')
|
||||
[CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'Print colorful output')
|
||||
[CompletionResult]::new('--command-color', 'command-color', [CompletionResultType]::ParameterName, 'Echo recipe lines in <COMMAND-COLOR>')
|
||||
[CompletionResult]::new('--dump-format', 'dump-format', [CompletionResultType]::ParameterName, 'Dump justfile as <FORMAT>')
|
||||
[CompletionResult]::new('--list-heading', 'list-heading', [CompletionResultType]::ParameterName, 'Print <TEXT> before list')
|
||||
[CompletionResult]::new('--list-prefix', 'list-prefix', [CompletionResultType]::ParameterName, 'Print <TEXT> before each list item')
|
||||
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Use <JUSTFILE> as justfile')
|
||||
[CompletionResult]::new('--justfile', 'justfile', [CompletionResultType]::ParameterName, 'Use <JUSTFILE> as justfile')
|
||||
[CompletionResult]::new('--set', 'set', [CompletionResultType]::ParameterName, 'Override <VARIABLE> with <VALUE>')
|
||||
[CompletionResult]::new('--shell', 'shell', [CompletionResultType]::ParameterName, 'Invoke <SHELL> to run recipes')
|
||||
[CompletionResult]::new('--shell-arg', 'shell-arg', [CompletionResultType]::ParameterName, 'Invoke shell with <SHELL-ARG> as an argument')
|
||||
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set')
|
||||
[CompletionResult]::new('--working-directory', 'working-directory', [CompletionResultType]::ParameterName, 'Use <WORKING-DIRECTORY> as working directory. --justfile must also be set')
|
||||
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set')
|
||||
[CompletionResult]::new('--command', 'command', [CompletionResultType]::ParameterName, 'Run an arbitrary command with the working directory, `.env`, overrides, and exports set')
|
||||
[CompletionResult]::new('--completions', 'completions', [CompletionResultType]::ParameterName, 'Print shell completion script for <SHELL>')
|
||||
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'List available recipes')
|
||||
[CompletionResult]::new('--list', 'list', [CompletionResultType]::ParameterName, 'List available recipes')
|
||||
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Show recipe at <PATH>')
|
||||
[CompletionResult]::new('--show', 'show', [CompletionResultType]::ParameterName, 'Show recipe at <PATH>')
|
||||
[CompletionResult]::new('--dotenv-filename', 'dotenv-filename', [CompletionResultType]::ParameterName, 'Search for environment file named <DOTENV-FILENAME> instead of `.env`')
|
||||
[CompletionResult]::new('-E', 'E ', [CompletionResultType]::ParameterName, 'Load <DOTENV-PATH> as environment file instead of searching for one')
|
||||
[CompletionResult]::new('--dotenv-path', 'dotenv-path', [CompletionResultType]::ParameterName, 'Load <DOTENV-PATH> as environment file instead of searching for one')
|
||||
[CompletionResult]::new('--timestamp-format', 'timestamp-format', [CompletionResultType]::ParameterName, 'Timestamp format string')
|
||||
[CompletionResult]::new('--check', 'check', [CompletionResultType]::ParameterName, 'Run `--fmt` in ''check'' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.')
|
||||
[CompletionResult]::new('--yes', 'yes', [CompletionResultType]::ParameterName, 'Automatically confirm all recipes.')
|
||||
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Print what just would do without doing it')
|
||||
[CompletionResult]::new('--dry-run', 'dry-run', [CompletionResultType]::ParameterName, 'Print what just would do without doing it')
|
||||
[CompletionResult]::new('--highlight', 'highlight', [CompletionResultType]::ParameterName, 'Highlight echoed recipe lines in bold')
|
||||
[CompletionResult]::new('--no-aliases', 'no-aliases', [CompletionResultType]::ParameterName, 'Don''t show aliases in list')
|
||||
[CompletionResult]::new('--no-deps', 'no-deps', [CompletionResultType]::ParameterName, 'Don''t run recipe dependencies')
|
||||
[CompletionResult]::new('--no-dotenv', 'no-dotenv', [CompletionResultType]::ParameterName, 'Don''t load `.env` file')
|
||||
[CompletionResult]::new('--no-highlight', 'no-highlight', [CompletionResultType]::ParameterName, 'Don''t highlight echoed recipe lines in bold')
|
||||
[CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Suppress all output')
|
||||
[CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Suppress all output')
|
||||
[CompletionResult]::new('--shell-command', 'shell-command', [CompletionResultType]::ParameterName, 'Invoke <COMMAND> with the shell used to run recipe lines and backticks')
|
||||
[CompletionResult]::new('--clear-shell-args', 'clear-shell-args', [CompletionResultType]::ParameterName, 'Clear shell arguments')
|
||||
[CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Return list and summary entries in source order')
|
||||
[CompletionResult]::new('--unsorted', 'unsorted', [CompletionResultType]::ParameterName, 'Return list and summary entries in source order')
|
||||
[CompletionResult]::new('--unstable', 'unstable', [CompletionResultType]::ParameterName, 'Enable unstable features')
|
||||
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Use verbose output')
|
||||
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Use verbose output')
|
||||
[CompletionResult]::new('--changelog', 'changelog', [CompletionResultType]::ParameterName, 'Print changelog')
|
||||
[CompletionResult]::new('--choose', 'choose', [CompletionResultType]::ParameterName, 'Select one or more recipes to run using a binary chooser. If `--chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`')
|
||||
[CompletionResult]::new('--dump', 'dump', [CompletionResultType]::ParameterName, 'Print justfile')
|
||||
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`')
|
||||
[CompletionResult]::new('--edit', 'edit', [CompletionResultType]::ParameterName, 'Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`')
|
||||
[CompletionResult]::new('--evaluate', 'evaluate', [CompletionResultType]::ParameterName, 'Evaluate and print all variables. If a variable name is given as an argument, only print that variable''s value.')
|
||||
[CompletionResult]::new('--fmt', 'fmt', [CompletionResultType]::ParameterName, 'Format and overwrite justfile')
|
||||
[CompletionResult]::new('--init', 'init', [CompletionResultType]::ParameterName, 'Initialize new justfile in project root')
|
||||
[CompletionResult]::new('--groups', 'groups', [CompletionResultType]::ParameterName, 'List recipe groups')
|
||||
[CompletionResult]::new('--man', 'man', [CompletionResultType]::ParameterName, 'Print man page')
|
||||
[CompletionResult]::new('--summary', 'summary', [CompletionResultType]::ParameterName, 'List names of available recipes')
|
||||
[CompletionResult]::new('--variables', 'variables', [CompletionResultType]::ParameterName, 'List names of variables')
|
||||
[CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, 'Use global justfile')
|
||||
[CompletionResult]::new('--global-justfile', 'global-justfile', [CompletionResultType]::ParameterName, 'Use global justfile')
|
||||
[CompletionResult]::new('--timestamp', 'timestamp', [CompletionResultType]::ParameterName, 'Print recipe command timestamps')
|
||||
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
|
||||
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
|
||||
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
function Get-JustFileRecipes([string[]]$CommandElements) {
|
||||
$justFileIndex = $commandElements.IndexOf("--justfile");
|
||||
|
||||
if ($justFileIndex -ne -1 && $justFileIndex + 1 -le $commandElements.Length) {
|
||||
$justFileLocation = $commandElements[$justFileIndex + 1]
|
||||
}
|
||||
|
||||
$justArgs = @("--summary")
|
||||
|
||||
if (Test-Path $justFileLocation) {
|
||||
$justArgs += @("--justfile", $justFileLocation)
|
||||
}
|
||||
|
||||
$recipes = $(just @justArgs) -split ' '
|
||||
return $recipes | ForEach-Object { [CompletionResult]::new($_) }
|
||||
}
|
||||
|
||||
$elementValues = $commandElements | Select-Object -ExpandProperty Value
|
||||
$recipes = Get-JustFileRecipes -CommandElements $elementValues
|
||||
$completions += $recipes
|
||||
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
||||
Sort-Object -Property ListItemText
|
||||
}
|
171
completions/just.zsh
Normal file
171
completions/just.zsh
Normal file
@ -0,0 +1,171 @@
|
||||
#compdef just
|
||||
|
||||
autoload -U is-at-least
|
||||
|
||||
_just() {
|
||||
typeset -A opt_args
|
||||
typeset -a _arguments_options
|
||||
local ret=1
|
||||
|
||||
if is-at-least 5.2; then
|
||||
_arguments_options=(-s -S -C)
|
||||
else
|
||||
_arguments_options=(-s -C)
|
||||
fi
|
||||
|
||||
local context curcontext="$curcontext" state line
|
||||
local common=(
|
||||
'--chooser=[Override binary invoked by \`--choose\`]: : ' \
|
||||
'--color=[Print colorful output]: :(auto always never)' \
|
||||
'--command-color=[Echo recipe lines in <COMMAND-COLOR>]: :(black blue cyan green purple red yellow)' \
|
||||
'--dump-format=[Dump justfile as <FORMAT>]:FORMAT:(just json)' \
|
||||
'--list-heading=[Print <TEXT> before list]:TEXT: ' \
|
||||
'--list-prefix=[Print <TEXT> before each list item]:TEXT: ' \
|
||||
'-f+[Use <JUSTFILE> as justfile]: :_files' \
|
||||
'--justfile=[Use <JUSTFILE> as justfile]: :_files' \
|
||||
'*--set=[Override <VARIABLE> with <VALUE>]: :(_just_variables)' \
|
||||
'--shell=[Invoke <SHELL> to run recipes]: : ' \
|
||||
'*--shell-arg=[Invoke shell with <SHELL-ARG> as an argument]: : ' \
|
||||
'-d+[Use <WORKING-DIRECTORY> as working directory. --justfile must also be set]: :_files' \
|
||||
'--working-directory=[Use <WORKING-DIRECTORY> as working directory. --justfile must also be set]: :_files' \
|
||||
'*-c+[Run an arbitrary command with the working directory, \`.env\`, overrides, and exports set]: : ' \
|
||||
'*--command=[Run an arbitrary command with the working directory, \`.env\`, overrides, and exports set]: : ' \
|
||||
'*--completions=[Print shell completion script for <SHELL>]:SHELL:(bash elvish fish powershell zsh)' \
|
||||
'()-l+[List available recipes]' \
|
||||
'()--list=[List available recipes]' \
|
||||
'-s+[Show recipe at <PATH>]: :(_just_commands)' \
|
||||
'--show=[Show recipe at <PATH>]: :(_just_commands)' \
|
||||
'(-E --dotenv-path)--dotenv-filename=[Search for environment file named <DOTENV-FILENAME> instead of \`.env\`]: : ' \
|
||||
'-E+[Load <DOTENV-PATH> as environment file instead of searching for one]: :_files' \
|
||||
'--dotenv-path=[Load <DOTENV-PATH> as environment file instead of searching for one]: :_files' \
|
||||
'--timestamp-format=[Timestamp format string]: : ' \
|
||||
'--check[Run \`--fmt\` in '\''check'\'' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.]' \
|
||||
'--yes[Automatically confirm all recipes.]' \
|
||||
'(-q --quiet)-n[Print what just would do without doing it]' \
|
||||
'(-q --quiet)--dry-run[Print what just would do without doing it]' \
|
||||
'--highlight[Highlight echoed recipe lines in bold]' \
|
||||
'--no-aliases[Don'\''t show aliases in list]' \
|
||||
'--no-deps[Don'\''t run recipe dependencies]' \
|
||||
'--no-dotenv[Don'\''t load \`.env\` file]' \
|
||||
'--no-highlight[Don'\''t highlight echoed recipe lines in bold]' \
|
||||
'(-n --dry-run)-q[Suppress all output]' \
|
||||
'(-n --dry-run)--quiet[Suppress all output]' \
|
||||
'--shell-command[Invoke <COMMAND> with the shell used to run recipe lines and backticks]' \
|
||||
'--clear-shell-args[Clear shell arguments]' \
|
||||
'-u[Return list and summary entries in source order]' \
|
||||
'--unsorted[Return list and summary entries in source order]' \
|
||||
'--unstable[Enable unstable features]' \
|
||||
'*-v[Use verbose output]' \
|
||||
'*--verbose[Use verbose output]' \
|
||||
'--changelog[Print changelog]' \
|
||||
'--choose[Select one or more recipes to run using a binary chooser. If \`--chooser\` is not passed the chooser defaults to the value of \$JUST_CHOOSER, falling back to \`fzf\`]' \
|
||||
'--dump[Print justfile]' \
|
||||
'-e[Edit justfile with editor given by \$VISUAL or \$EDITOR, falling back to \`vim\`]' \
|
||||
'--edit[Edit justfile with editor given by \$VISUAL or \$EDITOR, falling back to \`vim\`]' \
|
||||
'--evaluate[Evaluate and print all variables. If a variable name is given as an argument, only print that variable'\''s value.]' \
|
||||
'--fmt[Format and overwrite justfile]' \
|
||||
'--init[Initialize new justfile in project root]' \
|
||||
'--groups[List recipe groups]' \
|
||||
'--man[Print man page]' \
|
||||
'--summary[List names of available recipes]' \
|
||||
'--variables[List names of variables]' \
|
||||
'(-f --justfile -d --working-directory)-g[Use global justfile]' \
|
||||
'(-f --justfile -d --working-directory)--global-justfile[Use global justfile]' \
|
||||
'--timestamp[Print recipe command timestamps]' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
)
|
||||
|
||||
_arguments "${_arguments_options[@]}" $common \
|
||||
'1: :_just_commands' \
|
||||
'*: :->args' \
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
args)
|
||||
curcontext="${curcontext%:*}-${words[2]}:"
|
||||
|
||||
local lastarg=${words[${#words}]}
|
||||
local recipe
|
||||
|
||||
local cmds; cmds=(
|
||||
${(s: :)$(_call_program commands just --summary)}
|
||||
)
|
||||
|
||||
# Find first recipe name
|
||||
for ((i = 2; i < $#words; i++ )) do
|
||||
if [[ ${cmds[(I)${words[i]}]} -gt 0 ]]; then
|
||||
recipe=${words[i]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $lastarg = */* ]]; then
|
||||
# Arguments contain slash would be recognised as a file
|
||||
_arguments -s -S $common '*:: :_files'
|
||||
elif [[ $lastarg = *=* ]]; then
|
||||
# Arguments contain equal would be recognised as a variable
|
||||
_message "value"
|
||||
elif [[ $recipe ]]; then
|
||||
# Show usage message
|
||||
_message "`just --show $recipe`"
|
||||
# Or complete with other commands
|
||||
#_arguments -s -S $common '*:: :_just_commands'
|
||||
else
|
||||
_arguments -s -S $common '*:: :_just_commands'
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
(( $+functions[_just_commands] )) ||
|
||||
_just_commands() {
|
||||
[[ $PREFIX = -* ]] && return 1
|
||||
integer ret=1
|
||||
local variables; variables=(
|
||||
${(s: :)$(_call_program commands just --variables)}
|
||||
)
|
||||
local commands; commands=(
|
||||
${${${(M)"${(f)$(_call_program commands just --list)}":# *}/ ##/}/ ##/:Args: }
|
||||
)
|
||||
|
||||
if compset -P '*='; then
|
||||
case "${${words[-1]%=*}#*=}" in
|
||||
*) _message 'value' && ret=0 ;;
|
||||
esac
|
||||
else
|
||||
_describe -t variables 'variables' variables -qS "=" && ret=0
|
||||
_describe -t commands 'just commands' commands "$@"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
if [ "$funcstack[1]" = "_just" ]; then
|
||||
(( $+functions[_just_variables] )) ||
|
||||
_just_variables() {
|
||||
[[ $PREFIX = -* ]] && return 1
|
||||
integer ret=1
|
||||
local variables; variables=(
|
||||
${(s: :)$(_call_program commands just --variables)}
|
||||
)
|
||||
|
||||
if compset -P '*='; then
|
||||
case "${${words[-1]%=*}#*=}" in
|
||||
*) _message 'value' && ret=0 ;;
|
||||
esac
|
||||
else
|
||||
_describe -t variables 'variables' variables && ret=0
|
||||
fi
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
_just "$@"
|
||||
else
|
||||
compdef _just just
|
||||
fi
|
@ -30,9 +30,13 @@ fn main() {
|
||||
.replace_all(
|
||||
&fs::read_to_string("CHANGELOG.md").unwrap(),
|
||||
|captures: &Captures| {
|
||||
let pr = captures[1].parse().unwrap();
|
||||
let contributor = author(pr);
|
||||
format!("([#{pr}](https://github.com/casey/just/pull/{pr}) by [{contributor}](https://github.com/{contributor}))")
|
||||
let pr = captures[1].parse().unwrap();
|
||||
match author(pr).as_str() {
|
||||
"casey" => format!("([#{pr}](https://github.com/casey/just/pull/{pr}))"),
|
||||
contributor => {
|
||||
format!("([#{pr}](https://github.com/casey/just/pull/{pr}) by [{contributor}](https://github.com/{contributor}))")
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
|
4
justfile
4
justfile
@ -43,7 +43,6 @@ shellcheck:
|
||||
shellcheck www/install.sh
|
||||
|
||||
man:
|
||||
mkdir -p man
|
||||
cargo run -- --man > man/just.1
|
||||
|
||||
view-man: man
|
||||
@ -165,6 +164,9 @@ watch-readme:
|
||||
just render-readme
|
||||
fswatch -ro README.adoc | xargs -n1 -I{} just render-readme
|
||||
|
||||
update-completions:
|
||||
./bin/update-completions
|
||||
|
||||
test-completions:
|
||||
./tests/completions/just.bash
|
||||
|
||||
|
195
man/just.1
Normal file
195
man/just.1
Normal file
@ -0,0 +1,195 @@
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.TH just 1 "just 1.27.0"
|
||||
.SH NAME
|
||||
just \- 🤖 Just a command runner \- https://github.com/casey/just
|
||||
.SH SYNOPSIS
|
||||
\fBjust\fR [\fB\-\-check\fR] [\fB\-\-chooser\fR] [\fB\-\-color\fR] [\fB\-\-command\-color\fR] [\fB\-\-yes\fR] [\fB\-n\fR|\fB\-\-dry\-run\fR] [\fB\-\-dump\-format\fR] [\fB\-\-highlight\fR] [\fB\-\-list\-heading\fR] [\fB\-\-list\-prefix\fR] [\fB\-\-no\-aliases\fR] [\fB\-\-no\-deps\fR] [\fB\-\-no\-dotenv\fR] [\fB\-\-no\-highlight\fR] [\fB\-f\fR|\fB\-\-justfile\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-set\fR] [\fB\-\-shell\fR] [\fB\-\-shell\-arg\fR] [\fB\-\-shell\-command\fR] [\fB\-\-clear\-shell\-args\fR] [\fB\-u\fR|\fB\-\-unsorted\fR] [\fB\-\-unstable\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-d\fR|\fB\-\-working\-directory\fR] [\fB\-\-changelog\fR] [\fB\-\-choose\fR] [\fB\-c\fR|\fB\-\-command\fR] [\fB\-\-completions\fR] [\fB\-\-dump\fR] [\fB\-e\fR|\fB\-\-edit\fR] [\fB\-\-evaluate\fR] [\fB\-\-fmt\fR] [\fB\-\-init\fR] [\fB\-l\fR|\fB\-\-list\fR] [\fB\-\-groups\fR] [\fB\-\-man\fR] [\fB\-s\fR|\fB\-\-show\fR] [\fB\-\-summary\fR] [\fB\-\-variables\fR] [\fB\-\-dotenv\-filename\fR] [\fB\-E\fR|\fB\-\-dotenv\-path\fR] [\fB\-g\fR|\fB\-\-global\-justfile\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIARGUMENTS\fR]
|
||||
.SH DESCRIPTION
|
||||
🤖 Just a command runner \- https://github.com/casey/just
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-\-check\fR
|
||||
Run `\-\-fmt` in \*(Aqcheck\*(Aq mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required.
|
||||
.TP
|
||||
\fB\-\-chooser\fR
|
||||
Override binary invoked by `\-\-choose`
|
||||
.RS
|
||||
May also be specified with the \fBJUST_CHOOSER\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-\-color\fR [default: auto]
|
||||
Print colorful output
|
||||
.br
|
||||
|
||||
.br
|
||||
[\fIpossible values: \fRauto, always, never]
|
||||
.RS
|
||||
May also be specified with the \fBJUST_COLOR\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-\-command\-color\fR
|
||||
Echo recipe lines in <COMMAND\-COLOR>
|
||||
.br
|
||||
|
||||
.br
|
||||
[\fIpossible values: \fRblack, blue, cyan, green, purple, red, yellow]
|
||||
.RS
|
||||
May also be specified with the \fBJUST_COMMAND_COLOR\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-\-yes\fR
|
||||
Automatically confirm all recipes.
|
||||
.TP
|
||||
\fB\-n\fR, \fB\-\-dry\-run\fR
|
||||
Print what just would do without doing it
|
||||
.RS
|
||||
May also be specified with the \fBJUST_DRY_RUN\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-\-dump\-format\fR=\fIFORMAT\fR [default: just]
|
||||
Dump justfile as <FORMAT>
|
||||
.br
|
||||
|
||||
.br
|
||||
[\fIpossible values: \fRjust, json]
|
||||
.TP
|
||||
\fB\-\-highlight\fR
|
||||
Highlight echoed recipe lines in bold
|
||||
.TP
|
||||
\fB\-\-list\-heading\fR=\fITEXT\fR
|
||||
Print <TEXT> before list
|
||||
.TP
|
||||
\fB\-\-list\-prefix\fR=\fITEXT\fR
|
||||
Print <TEXT> before each list item
|
||||
.TP
|
||||
\fB\-\-no\-aliases\fR
|
||||
Don\*(Aqt show aliases in list
|
||||
.TP
|
||||
\fB\-\-no\-deps\fR
|
||||
Don\*(Aqt run recipe dependencies
|
||||
.TP
|
||||
\fB\-\-no\-dotenv\fR
|
||||
Don\*(Aqt load `.env` file
|
||||
.TP
|
||||
\fB\-\-no\-highlight\fR
|
||||
Don\*(Aqt highlight echoed recipe lines in bold
|
||||
.TP
|
||||
\fB\-f\fR, \fB\-\-justfile\fR
|
||||
Use <JUSTFILE> as justfile
|
||||
.RS
|
||||
May also be specified with the \fBJUST_JUSTFILE\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-q\fR, \fB\-\-quiet\fR
|
||||
Suppress all output
|
||||
.RS
|
||||
May also be specified with the \fBJUST_QUIET\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-\-set\fR=\fIVARIABLE VALUE\fR
|
||||
Override <VARIABLE> with <VALUE>
|
||||
.TP
|
||||
\fB\-\-shell\fR
|
||||
Invoke <SHELL> to run recipes
|
||||
.TP
|
||||
\fB\-\-shell\-arg\fR
|
||||
Invoke shell with <SHELL\-ARG> as an argument
|
||||
.TP
|
||||
\fB\-\-shell\-command\fR
|
||||
Invoke <COMMAND> with the shell used to run recipe lines and backticks
|
||||
.TP
|
||||
\fB\-\-clear\-shell\-args\fR
|
||||
Clear shell arguments
|
||||
.TP
|
||||
\fB\-u\fR, \fB\-\-unsorted\fR
|
||||
Return list and summary entries in source order
|
||||
.TP
|
||||
\fB\-\-unstable\fR
|
||||
Enable unstable features
|
||||
.RS
|
||||
May also be specified with the \fBJUST_UNSTABLE\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
Use verbose output
|
||||
.RS
|
||||
May also be specified with the \fBJUST_VERBOSE\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-working\-directory\fR
|
||||
Use <WORKING\-DIRECTORY> as working directory. \-\-justfile must also be set
|
||||
.RS
|
||||
May also be specified with the \fBJUST_WORKING_DIRECTORY\fR environment variable.
|
||||
.RE
|
||||
.TP
|
||||
\fB\-\-changelog\fR
|
||||
Print changelog
|
||||
.TP
|
||||
\fB\-\-choose\fR
|
||||
Select one or more recipes to run using a binary chooser. If `\-\-chooser` is not passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`
|
||||
.TP
|
||||
\fB\-c\fR, \fB\-\-command\fR
|
||||
Run an arbitrary command with the working directory, `.env`, overrides, and exports set
|
||||
.TP
|
||||
\fB\-\-completions\fR=\fISHELL\fR
|
||||
Print shell completion script for <SHELL>
|
||||
.br
|
||||
|
||||
.br
|
||||
[\fIpossible values: \fRbash, elvish, fish, powershell, zsh]
|
||||
.TP
|
||||
\fB\-\-dump\fR
|
||||
Print justfile
|
||||
.TP
|
||||
\fB\-e\fR, \fB\-\-edit\fR
|
||||
Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`
|
||||
.TP
|
||||
\fB\-\-evaluate\fR
|
||||
Evaluate and print all variables. If a variable name is given as an argument, only print that variable\*(Aqs value.
|
||||
.TP
|
||||
\fB\-\-fmt\fR
|
||||
Format and overwrite justfile
|
||||
.TP
|
||||
\fB\-\-init\fR
|
||||
Initialize new justfile in project root
|
||||
.TP
|
||||
\fB\-l\fR, \fB\-\-list\fR
|
||||
List available recipes and their arguments
|
||||
.TP
|
||||
\fB\-\-groups\fR
|
||||
List recipe groups
|
||||
.TP
|
||||
\fB\-\-man\fR
|
||||
Print man page
|
||||
.TP
|
||||
\fB\-s\fR, \fB\-\-show\fR=\fIRECIPE\fR
|
||||
Show information about <RECIPE>
|
||||
.TP
|
||||
\fB\-\-summary\fR
|
||||
List names of available recipes
|
||||
.TP
|
||||
\fB\-\-variables\fR
|
||||
List names of variables
|
||||
.TP
|
||||
\fB\-\-dotenv\-filename\fR
|
||||
Search for environment file named <DOTENV\-FILENAME> instead of `.env`
|
||||
.TP
|
||||
\fB\-E\fR, \fB\-\-dotenv\-path\fR
|
||||
Load <DOTENV\-PATH> as environment file instead of searching for one
|
||||
.TP
|
||||
\fB\-g\fR, \fB\-\-global\-justfile\fR
|
||||
Use global justfile
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Print help
|
||||
.TP
|
||||
\fB\-V\fR, \fB\-\-version\fR
|
||||
Print version
|
||||
.TP
|
||||
[\fIARGUMENTS\fR]
|
||||
Overrides and recipe(s) to run, defaulting to the first recipe in the justfile
|
||||
.SH VERSION
|
||||
v1.27.0
|
||||
.SH AUTHORS
|
||||
Casey Rodarmor <casey@rodarmor.com>
|
@ -37,8 +37,6 @@ impl<'src> Analyzer<'src> {
|
||||
|
||||
let mut modules: Table<Justfile> = Table::new();
|
||||
|
||||
let mut unexports: HashSet<String> = HashSet::new();
|
||||
|
||||
let mut definitions: HashMap<&str, (&'static str, Name)> = HashMap::new();
|
||||
|
||||
let mut define = |name: Name<'src>,
|
||||
@ -100,13 +98,6 @@ impl<'src> Analyzer<'src> {
|
||||
self.analyze_set(set)?;
|
||||
self.sets.insert(set.clone());
|
||||
}
|
||||
Item::Unexport { name } => {
|
||||
if !unexports.insert(name.lexeme().to_string()) {
|
||||
return Err(name.token.error(DuplicateUnexport {
|
||||
variable: name.lexeme(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,23 +109,21 @@ impl<'src> Analyzer<'src> {
|
||||
let mut recipe_table: Table<'src, UnresolvedRecipe<'src>> = Table::default();
|
||||
|
||||
for assignment in assignments {
|
||||
let variable = assignment.name.lexeme();
|
||||
|
||||
if !settings.allow_duplicate_variables && self.assignments.contains_key(variable) {
|
||||
return Err(assignment.name.token.error(DuplicateVariable { variable }));
|
||||
if !settings.allow_duplicate_variables
|
||||
&& self.assignments.contains_key(assignment.name.lexeme())
|
||||
{
|
||||
return Err(assignment.name.token.error(DuplicateVariable {
|
||||
variable: assignment.name.lexeme(),
|
||||
}));
|
||||
}
|
||||
|
||||
if self
|
||||
.assignments
|
||||
.get(variable)
|
||||
.get(assignment.name.lexeme())
|
||||
.map_or(true, |original| assignment.depth <= original.depth)
|
||||
{
|
||||
self.assignments.insert(assignment.clone());
|
||||
}
|
||||
|
||||
if unexports.contains(variable) {
|
||||
return Err(assignment.name.token.error(ExportUnexported { variable }));
|
||||
}
|
||||
}
|
||||
|
||||
AssignmentResolver::resolve_assignments(&self.assignments)?;
|
||||
@ -149,7 +138,7 @@ impl<'src> Analyzer<'src> {
|
||||
}
|
||||
}
|
||||
|
||||
let recipes = RecipeResolver::resolve_recipes(&self.assignments, &settings, recipe_table)?;
|
||||
let recipes = RecipeResolver::resolve_recipes(recipe_table, &self.assignments)?;
|
||||
|
||||
let mut aliases = Table::new();
|
||||
while let Some(alias) = self.aliases.pop() {
|
||||
@ -178,7 +167,6 @@ impl<'src> Analyzer<'src> {
|
||||
recipes,
|
||||
settings,
|
||||
source: root.into(),
|
||||
unexports,
|
||||
warnings,
|
||||
})
|
||||
}
|
||||
|
@ -1,403 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[allow(clippy::doc_markdown)]
|
||||
/// The argument parser is responsible for grouping positional arguments into
|
||||
/// argument groups, which consist of a path to a recipe and its arguments.
|
||||
///
|
||||
/// Argument parsing is substantially complicated by the fact that recipe paths
|
||||
/// can be given on the command line as multiple arguments, i.e., "foo" "bar"
|
||||
/// baz", or as a single "::"-separated argument.
|
||||
///
|
||||
/// Error messages produced by the argument parser should use the format of the
|
||||
/// recipe path as passed on the command line.
|
||||
///
|
||||
/// Additionally, if a recipe is specified with a "::"-separated path, extra
|
||||
/// components of that path after a valid recipe must not be used as arguments,
|
||||
/// whereas arguments after multiple argument path may be used as arguments. As
|
||||
/// an example, `foo bar baz` may refer to recipe `foo::bar` with argument
|
||||
/// `baz`, but `foo::bar::baz` is an error, since `bar` is a recipe, not a
|
||||
/// module.
|
||||
pub(crate) struct ArgumentParser<'src: 'run, 'run> {
|
||||
arguments: &'run [&'run str],
|
||||
next: usize,
|
||||
root: &'run Justfile<'src>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct ArgumentGroup<'run> {
|
||||
pub(crate) arguments: Vec<&'run str>,
|
||||
pub(crate) path: Vec<String>,
|
||||
}
|
||||
|
||||
impl<'src: 'run, 'run> ArgumentParser<'src, 'run> {
|
||||
pub(crate) fn parse_arguments(
|
||||
root: &'run Justfile<'src>,
|
||||
arguments: &'run [&'run str],
|
||||
) -> RunResult<'src, Vec<ArgumentGroup<'run>>> {
|
||||
let mut groups = Vec::new();
|
||||
|
||||
let mut invocation_parser = Self {
|
||||
arguments,
|
||||
next: 0,
|
||||
root,
|
||||
};
|
||||
|
||||
loop {
|
||||
groups.push(invocation_parser.parse_group()?);
|
||||
|
||||
if invocation_parser.next == arguments.len() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(groups)
|
||||
}
|
||||
|
||||
fn parse_group(&mut self) -> RunResult<'src, ArgumentGroup<'run>> {
|
||||
let (recipe, path) = if let Some(next) = self.next() {
|
||||
if next.contains(':') {
|
||||
let module_path =
|
||||
ModulePath::try_from([next].as_slice()).map_err(|()| Error::UnknownRecipe {
|
||||
recipe: next.into(),
|
||||
suggestion: None,
|
||||
})?;
|
||||
let (recipe, path, _) = self.resolve_recipe(true, &module_path.path)?;
|
||||
self.next += 1;
|
||||
(recipe, path)
|
||||
} else {
|
||||
let (recipe, path, consumed) = self.resolve_recipe(false, self.rest())?;
|
||||
self.next += consumed;
|
||||
(recipe, path)
|
||||
}
|
||||
} else {
|
||||
let (recipe, path, consumed) = self.resolve_recipe(false, self.rest())?;
|
||||
assert_eq!(consumed, 0);
|
||||
(recipe, path)
|
||||
};
|
||||
|
||||
let rest = self.rest();
|
||||
|
||||
let argument_range = recipe.argument_range();
|
||||
let argument_count = cmp::min(rest.len(), recipe.max_arguments());
|
||||
if !argument_range.range_contains(&argument_count) {
|
||||
return Err(Error::ArgumentCountMismatch {
|
||||
recipe: recipe.name(),
|
||||
parameters: recipe.parameters.clone(),
|
||||
found: rest.len(),
|
||||
min: recipe.min_arguments(),
|
||||
max: recipe.max_arguments(),
|
||||
});
|
||||
}
|
||||
|
||||
let arguments = rest[..argument_count].to_vec();
|
||||
|
||||
self.next += argument_count;
|
||||
|
||||
Ok(ArgumentGroup { arguments, path })
|
||||
}
|
||||
|
||||
fn resolve_recipe(
|
||||
&self,
|
||||
module_path: bool,
|
||||
args: &[impl AsRef<str>],
|
||||
) -> RunResult<'src, (&'run Recipe<'src>, Vec<String>, usize)> {
|
||||
let mut current = self.root;
|
||||
let mut path = Vec::new();
|
||||
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
let arg = arg.as_ref();
|
||||
|
||||
path.push(arg.to_string());
|
||||
|
||||
if let Some(module) = current.modules.get(arg) {
|
||||
current = module;
|
||||
} else if let Some(recipe) = current.get_recipe(arg) {
|
||||
if module_path && i + 1 < args.len() {
|
||||
return Err(Error::ExpectedSubmoduleButFoundRecipe {
|
||||
path: if module_path {
|
||||
path.join("::")
|
||||
} else {
|
||||
path.join(" ")
|
||||
},
|
||||
});
|
||||
}
|
||||
return Ok((recipe, path, i + 1));
|
||||
} else {
|
||||
if module_path && i + 1 < args.len() {
|
||||
return Err(Error::UnknownSubmodule {
|
||||
path: path.join("::"),
|
||||
});
|
||||
}
|
||||
|
||||
return Err(Error::UnknownRecipe {
|
||||
recipe: if module_path {
|
||||
path.join("::")
|
||||
} else {
|
||||
path.join(" ")
|
||||
},
|
||||
suggestion: current.suggest_recipe(arg),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(recipe) = ¤t.default {
|
||||
recipe.check_can_be_default_recipe()?;
|
||||
path.push(recipe.name().into());
|
||||
Ok((recipe, path, args.len()))
|
||||
} else if current.recipes.is_empty() {
|
||||
Err(Error::NoRecipes)
|
||||
} else {
|
||||
Err(Error::NoDefaultRecipe)
|
||||
}
|
||||
}
|
||||
|
||||
fn next(&self) -> Option<&'run str> {
|
||||
self.arguments.get(self.next).copied()
|
||||
}
|
||||
|
||||
fn rest(&self) -> &[&'run str] {
|
||||
&self.arguments[self.next..]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {super::*, tempfile::TempDir};
|
||||
|
||||
trait TempDirExt {
|
||||
fn write(&self, path: &str, content: &str);
|
||||
}
|
||||
|
||||
impl TempDirExt for TempDir {
|
||||
fn write(&self, path: &str, content: &str) {
|
||||
let path = self.path().join(path);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
fs::write(path, content).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_no_arguments() {
|
||||
let justfile = testing::compile("foo:");
|
||||
|
||||
assert_eq!(
|
||||
ArgumentParser::parse_arguments(&justfile, &["foo"]).unwrap(),
|
||||
vec![ArgumentGroup {
|
||||
path: vec!["foo".into()],
|
||||
arguments: Vec::new()
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_with_argument() {
|
||||
let justfile = testing::compile("foo bar:");
|
||||
|
||||
assert_eq!(
|
||||
ArgumentParser::parse_arguments(&justfile, &["foo", "baz"]).unwrap(),
|
||||
vec![ArgumentGroup {
|
||||
path: vec!["foo".into()],
|
||||
arguments: vec!["baz"],
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_argument_count_mismatch() {
|
||||
let justfile = testing::compile("foo bar:");
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&justfile, &["foo"]).unwrap_err(),
|
||||
Error::ArgumentCountMismatch {
|
||||
recipe: "foo",
|
||||
found: 0,
|
||||
min: 1,
|
||||
max: 1,
|
||||
..
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_unknown() {
|
||||
let justfile = testing::compile("foo:");
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&justfile, &["bar"]).unwrap_err(),
|
||||
Error::UnknownRecipe {
|
||||
recipe,
|
||||
suggestion: None
|
||||
} if recipe == "bar",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_unknown() {
|
||||
let justfile = testing::compile("foo:");
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&justfile, &["bar", "baz"]).unwrap_err(),
|
||||
Error::UnknownRecipe {
|
||||
recipe,
|
||||
suggestion: None
|
||||
} if recipe == "bar",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recipe_in_submodule() {
|
||||
let loader = Loader::new();
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
let path = tempdir.path().join("justfile");
|
||||
fs::write(&path, "mod foo").unwrap();
|
||||
fs::create_dir(tempdir.path().join("foo")).unwrap();
|
||||
fs::write(tempdir.path().join("foo/mod.just"), "bar:").unwrap();
|
||||
let compilation = Compiler::compile(true, &loader, &path).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &["foo", "bar"]).unwrap(),
|
||||
vec![ArgumentGroup {
|
||||
path: vec!["foo".into(), "bar".into()],
|
||||
arguments: Vec::new()
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recipe_in_submodule_unknown() {
|
||||
let loader = Loader::new();
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
let path = tempdir.path().join("justfile");
|
||||
fs::write(&path, "mod foo").unwrap();
|
||||
fs::create_dir(tempdir.path().join("foo")).unwrap();
|
||||
fs::write(tempdir.path().join("foo/mod.just"), "bar:").unwrap();
|
||||
let compilation = Compiler::compile(true, &loader, &path).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &["foo", "zzz"]).unwrap_err(),
|
||||
Error::UnknownRecipe {
|
||||
recipe,
|
||||
suggestion: None
|
||||
} if recipe == "foo zzz",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recipe_in_submodule_path_unknown() {
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
tempdir.write("justfile", "mod foo");
|
||||
tempdir.write("foo.just", "bar:");
|
||||
|
||||
let loader = Loader::new();
|
||||
let compilation = Compiler::compile(true, &loader, &tempdir.path().join("justfile")).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &["foo::zzz"]).unwrap_err(),
|
||||
Error::UnknownRecipe {
|
||||
recipe,
|
||||
suggestion: None
|
||||
} if recipe == "foo::zzz",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_path_not_consumed() {
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
tempdir.write("justfile", "mod foo");
|
||||
tempdir.write("foo.just", "bar:");
|
||||
|
||||
let loader = Loader::new();
|
||||
let compilation = Compiler::compile(true, &loader, &tempdir.path().join("justfile")).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &["foo::bar::baz"]).unwrap_err(),
|
||||
Error::ExpectedSubmoduleButFoundRecipe {
|
||||
path,
|
||||
} if path == "foo::bar",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_recipes() {
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
tempdir.write("justfile", "");
|
||||
|
||||
let loader = Loader::new();
|
||||
let compilation = Compiler::compile(true, &loader, &tempdir.path().join("justfile")).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &[]).unwrap_err(),
|
||||
Error::NoRecipes,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_recipe_requires_arguments() {
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
tempdir.write("justfile", "foo bar:");
|
||||
|
||||
let loader = Loader::new();
|
||||
let compilation = Compiler::compile(true, &loader, &tempdir.path().join("justfile")).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &[]).unwrap_err(),
|
||||
Error::DefaultRecipeRequiresArguments {
|
||||
recipe: "foo",
|
||||
min_arguments: 1,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_default_recipe() {
|
||||
let tempdir = tempfile::tempdir().unwrap();
|
||||
tempdir.write("justfile", "import 'foo.just'");
|
||||
tempdir.write("foo.just", "bar:");
|
||||
|
||||
let loader = Loader::new();
|
||||
let compilation = Compiler::compile(true, &loader, &tempdir.path().join("justfile")).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
ArgumentParser::parse_arguments(&compilation.justfile, &[]).unwrap_err(),
|
||||
Error::NoDefaultRecipe,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complex_grouping() {
|
||||
let justfile = testing::compile(
|
||||
"
|
||||
FOO A B='blarg':
|
||||
echo foo: {{A}} {{B}}
|
||||
|
||||
BAR X:
|
||||
echo bar: {{X}}
|
||||
|
||||
BAZ +Z:
|
||||
echo baz: {{Z}}
|
||||
",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
ArgumentParser::parse_arguments(
|
||||
&justfile,
|
||||
&["BAR", "0", "FOO", "1", "2", "BAZ", "3", "4", "5"]
|
||||
)
|
||||
.unwrap(),
|
||||
vec![
|
||||
ArgumentGroup {
|
||||
path: vec!["BAR".into()],
|
||||
arguments: vec!["0"],
|
||||
},
|
||||
ArgumentGroup {
|
||||
path: vec!["FOO".into()],
|
||||
arguments: vec!["1", "2"],
|
||||
},
|
||||
ArgumentGroup {
|
||||
path: vec!["BAZ".into()],
|
||||
arguments: vec!["3", "4", "5"],
|
||||
},
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ use super::*;
|
||||
pub(crate) type Assignment<'src> = Binding<'src, Expression<'src>>;
|
||||
|
||||
impl<'src> Display for Assignment<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
if self.export {
|
||||
write!(f, "export ")?;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub(crate) struct Ast<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Ast<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
let mut iter = self.items.iter().peekable();
|
||||
|
||||
while let Some(item) = iter.next() {
|
||||
|
@ -17,7 +17,6 @@ pub(crate) enum Attribute<'src> {
|
||||
NoCd,
|
||||
NoExitMessage,
|
||||
NoQuiet,
|
||||
PositionalArguments,
|
||||
Private,
|
||||
Unix,
|
||||
Windows,
|
||||
@ -33,7 +32,6 @@ impl AttributeDiscriminant {
|
||||
| Self::NoCd
|
||||
| Self::NoExitMessage
|
||||
| Self::NoQuiet
|
||||
| Self::PositionalArguments
|
||||
| Self::Private
|
||||
| Self::Unix
|
||||
| Self::Windows => 0..=0,
|
||||
@ -59,7 +57,9 @@ 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 {
|
||||
@ -80,7 +80,6 @@ impl<'src> Attribute<'src> {
|
||||
NoCd => Self::NoCd,
|
||||
NoExitMessage => Self::NoExitMessage,
|
||||
NoQuiet => Self::NoQuiet,
|
||||
PositionalArguments => Self::PositionalArguments,
|
||||
Private => Self::Private,
|
||||
Unix => Self::Unix,
|
||||
Windows => Self::Windows,
|
||||
@ -101,7 +100,6 @@ impl<'src> Attribute<'src> {
|
||||
| Self::NoCd
|
||||
| Self::NoExitMessage
|
||||
| Self::NoQuiet
|
||||
| Self::PositionalArguments
|
||||
| Self::Private
|
||||
| Self::Unix
|
||||
| Self::Windows => None,
|
||||
@ -110,7 +108,7 @@ impl<'src> Attribute<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Attribute<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "{}", self.name())?;
|
||||
if let Some(argument) = self.argument() {
|
||||
write!(f, "({argument})")?;
|
||||
|
10
src/color.rs
10
src/color.rs
@ -38,7 +38,6 @@ impl Color {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn always() -> Self {
|
||||
Self {
|
||||
use_color: UseColor::Always,
|
||||
@ -134,15 +133,6 @@ impl Color {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UseColor> for Color {
|
||||
fn from(value: UseColor) -> Self {
|
||||
Self {
|
||||
use_color: value,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Color {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
@ -1,41 +1,25 @@
|
||||
use super::*;
|
||||
|
||||
pub(crate) trait CommandExt {
|
||||
fn export(
|
||||
&mut self,
|
||||
settings: &Settings,
|
||||
dotenv: &BTreeMap<String, String>,
|
||||
scope: &Scope,
|
||||
unexports: &HashSet<String>,
|
||||
);
|
||||
fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope);
|
||||
|
||||
fn export_scope(&mut self, settings: &Settings, scope: &Scope, unexports: &HashSet<String>);
|
||||
fn export_scope(&mut self, settings: &Settings, scope: &Scope);
|
||||
}
|
||||
|
||||
impl CommandExt for Command {
|
||||
fn export(
|
||||
&mut self,
|
||||
settings: &Settings,
|
||||
dotenv: &BTreeMap<String, String>,
|
||||
scope: &Scope,
|
||||
unexports: &HashSet<String>,
|
||||
) {
|
||||
fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope) {
|
||||
for (name, value) in dotenv {
|
||||
self.env(name, value);
|
||||
}
|
||||
|
||||
if let Some(parent) = scope.parent() {
|
||||
self.export_scope(settings, parent, unexports);
|
||||
self.export_scope(settings, parent);
|
||||
}
|
||||
}
|
||||
|
||||
fn export_scope(&mut self, settings: &Settings, scope: &Scope, unexports: &HashSet<String>) {
|
||||
fn export_scope(&mut self, settings: &Settings, scope: &Scope) {
|
||||
if let Some(parent) = scope.parent() {
|
||||
self.export_scope(settings, parent, unexports);
|
||||
}
|
||||
|
||||
for unexport in unexports {
|
||||
self.env_remove(unexport);
|
||||
self.export_scope(settings, parent);
|
||||
}
|
||||
|
||||
for binding in scope.bindings() {
|
||||
|
@ -28,7 +28,7 @@ fn capitalize(s: &str) -> String {
|
||||
}
|
||||
|
||||
impl Display for CompileError<'_> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
use CompileErrorKind::*;
|
||||
|
||||
match &*self.kind {
|
||||
@ -131,9 +131,6 @@ impl Display for CompileError<'_> {
|
||||
DuplicateVariable { variable } => {
|
||||
write!(f, "Variable `{variable}` has multiple definitions")
|
||||
}
|
||||
DuplicateUnexport { variable } => {
|
||||
write!(f, "Variable `{variable}` is unexported multiple times")
|
||||
}
|
||||
ExpectedKeyword { expected, found } => {
|
||||
let expected = List::or_ticked(expected);
|
||||
if found.kind == TokenKind::Identifier {
|
||||
@ -146,9 +143,6 @@ impl Display for CompileError<'_> {
|
||||
write!(f, "Expected keyword {expected} but found `{}`", found.kind)
|
||||
}
|
||||
}
|
||||
ExportUnexported { variable } => {
|
||||
write!(f, "Variable {variable} is both exported and unexported")
|
||||
}
|
||||
ExtraLeadingWhitespace => write!(f, "Recipe line has extra leading whitespace"),
|
||||
FunctionArgumentCountMismatch {
|
||||
function,
|
||||
|
@ -52,16 +52,10 @@ pub(crate) enum CompileErrorKind<'src> {
|
||||
DuplicateVariable {
|
||||
variable: &'src str,
|
||||
},
|
||||
DuplicateUnexport {
|
||||
variable: &'src str,
|
||||
},
|
||||
ExpectedKeyword {
|
||||
expected: Vec<Keyword>,
|
||||
found: Token<'src>,
|
||||
},
|
||||
ExportUnexported {
|
||||
variable: &'src str,
|
||||
},
|
||||
ExtraLeadingWhitespace,
|
||||
FunctionArgumentCountMismatch {
|
||||
function: &'src str,
|
||||
|
@ -1,102 +1,4 @@
|
||||
use {super::*, clap::ValueEnum};
|
||||
|
||||
#[derive(ValueEnum, Debug, Clone, Copy, PartialEq)]
|
||||
pub(crate) enum Shell {
|
||||
Bash,
|
||||
Elvish,
|
||||
Fish,
|
||||
#[value(alias = "nu")]
|
||||
Nushell,
|
||||
Powershell,
|
||||
Zsh,
|
||||
}
|
||||
|
||||
impl Shell {
|
||||
pub(crate) fn script(self) -> RunResult<'static, String> {
|
||||
match self {
|
||||
Self::Bash => completions::clap(clap_complete::Shell::Bash),
|
||||
Self::Elvish => completions::clap(clap_complete::Shell::Elvish),
|
||||
Self::Fish => completions::clap(clap_complete::Shell::Fish),
|
||||
Self::Nushell => Ok(completions::NUSHELL_COMPLETION_SCRIPT.into()),
|
||||
Self::Powershell => completions::clap(clap_complete::Shell::PowerShell),
|
||||
Self::Zsh => completions::clap(clap_complete::Shell::Zsh),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn clap(shell: clap_complete::Shell) -> RunResult<'static, String> {
|
||||
fn replace(haystack: &mut String, needle: &str, replacement: &str) -> RunResult<'static, ()> {
|
||||
if let Some(index) = haystack.find(needle) {
|
||||
haystack.replace_range(index..index + needle.len(), replacement);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::internal(format!(
|
||||
"Failed to find text:\n{needle}\n…in completion script:\n{haystack}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
let mut script = {
|
||||
let mut tempfile = tempfile().map_err(|io_error| Error::TempfileIo { io_error })?;
|
||||
|
||||
clap_complete::generate(
|
||||
shell,
|
||||
&mut crate::config::Config::app(),
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&mut tempfile,
|
||||
);
|
||||
|
||||
tempfile
|
||||
.rewind()
|
||||
.map_err(|io_error| Error::TempfileIo { io_error })?;
|
||||
|
||||
let mut buffer = String::new();
|
||||
|
||||
tempfile
|
||||
.read_to_string(&mut buffer)
|
||||
.map_err(|io_error| Error::TempfileIo { io_error })?;
|
||||
|
||||
buffer
|
||||
};
|
||||
|
||||
match shell {
|
||||
clap_complete::Shell::Bash => {
|
||||
for (needle, replacement) in completions::BASH_COMPLETION_REPLACEMENTS {
|
||||
replace(&mut script, needle, replacement)?;
|
||||
}
|
||||
}
|
||||
clap_complete::Shell::Fish => {
|
||||
script.insert_str(0, completions::FISH_RECIPE_COMPLETIONS);
|
||||
}
|
||||
clap_complete::Shell::PowerShell => {
|
||||
for (needle, replacement) in completions::POWERSHELL_COMPLETION_REPLACEMENTS {
|
||||
replace(&mut script, needle, replacement)?;
|
||||
}
|
||||
}
|
||||
clap_complete::Shell::Zsh => {
|
||||
for (needle, replacement) in completions::ZSH_COMPLETION_REPLACEMENTS {
|
||||
replace(&mut script, needle, replacement)?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(script.trim().into())
|
||||
}
|
||||
|
||||
const NUSHELL_COMPLETION_SCRIPT: &str = r#"def "nu-complete just" [] {
|
||||
(^just --dump --unstable --dump-format json | from json).recipes | transpose recipe data | flatten | where {|row| $row.private == false } | select recipe doc parameters | rename value description
|
||||
}
|
||||
|
||||
# Just: A Command Runner
|
||||
export extern "just" [
|
||||
...recipe: string@"nu-complete just", # Recipe(s) to run, may be with argument(s)
|
||||
]"#;
|
||||
|
||||
const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes
|
||||
if string match -rq '(-f|--justfile)\s*=?(?<justfile>[^\s]+)' -- (string split -- ' -- ' (commandline -pc))[1]
|
||||
set -fx JUST_JUSTFILE "$justfile"
|
||||
end
|
||||
pub(crate) const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes
|
||||
just --list 2> /dev/null | tail -n +2 | awk '{
|
||||
command = $1;
|
||||
args = $0;
|
||||
@ -135,9 +37,9 @@ complete -c just -a '(__fish_just_complete_recipes)'
|
||||
# autogenerated completions
|
||||
"#;
|
||||
|
||||
const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
|
||||
pub(crate) const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
|
||||
(
|
||||
r#" _arguments "${_arguments_options[@]}" : \"#,
|
||||
r#" _arguments "${_arguments_options[@]}" \"#,
|
||||
r" local common=(",
|
||||
),
|
||||
(
|
||||
@ -249,7 +151,7 @@ _just "$@""#,
|
||||
),
|
||||
];
|
||||
|
||||
const POWERSHELL_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[(
|
||||
pub(crate) const POWERSHELL_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[(
|
||||
r#"$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
||||
Sort-Object -Property ListItemText"#,
|
||||
r#"function Get-JustFileRecipes([string[]]$CommandElements) {
|
||||
@ -276,7 +178,7 @@ const POWERSHELL_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[(
|
||||
Sort-Object -Property ListItemText"#,
|
||||
)];
|
||||
|
||||
const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
|
||||
pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
|
||||
(
|
||||
r#" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
|
@ -8,7 +8,7 @@ pub(crate) struct Condition<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Condition<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "{} {} {}", self.lhs, self.operator, self.rhs)
|
||||
}
|
||||
}
|
||||
|
428
src/config.rs
428
src/config.rs
@ -7,6 +7,18 @@ use {
|
||||
},
|
||||
};
|
||||
|
||||
const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary chooser. \
|
||||
If `--chooser` is not passed the chooser defaults to the \
|
||||
value of $JUST_CHOOSER, falling back to `fzf`";
|
||||
|
||||
pub(crate) fn chooser_default(justfile: &Path) -> OsString {
|
||||
let mut chooser = OsString::new();
|
||||
chooser.push("fzf --multi --preview 'just --unstable --color always --justfile \"");
|
||||
chooser.push(justfile);
|
||||
chooser.push("\" --show {}'");
|
||||
chooser
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct Config {
|
||||
pub(crate) check: bool,
|
||||
@ -20,7 +32,6 @@ pub(crate) struct Config {
|
||||
pub(crate) invocation_directory: PathBuf,
|
||||
pub(crate) list_heading: String,
|
||||
pub(crate) list_prefix: String,
|
||||
pub(crate) list_submodules: bool,
|
||||
pub(crate) load_dotenv: bool,
|
||||
pub(crate) no_aliases: bool,
|
||||
pub(crate) no_dependencies: bool,
|
||||
@ -86,12 +97,11 @@ mod arg {
|
||||
pub(crate) const DOTENV_PATH: &str = "DOTENV-PATH";
|
||||
pub(crate) const DRY_RUN: &str = "DRY-RUN";
|
||||
pub(crate) const DUMP_FORMAT: &str = "DUMP-FORMAT";
|
||||
pub(crate) const GLOBAL_JUSTFILE: &str = "GLOBAL-JUSTFILE";
|
||||
pub(crate) const GLOBAL_JUSTFILE: &str = "GLOBAL_JUSTFILE";
|
||||
pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT";
|
||||
pub(crate) const JUSTFILE: &str = "JUSTFILE";
|
||||
pub(crate) const LIST_HEADING: &str = "LIST-HEADING";
|
||||
pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX";
|
||||
pub(crate) const LIST_SUBMODULES: &str = "LIST-SUBMODULES";
|
||||
pub(crate) const NO_ALIASES: &str = "NO-ALIASES";
|
||||
pub(crate) const NO_DEPS: &str = "NO-DEPS";
|
||||
pub(crate) const NO_DOTENV: &str = "NO-DOTENV";
|
||||
@ -102,14 +112,17 @@ mod arg {
|
||||
pub(crate) const SHELL_ARG: &str = "SHELL-ARG";
|
||||
pub(crate) const SHELL_COMMAND: &str = "SHELL-COMMAND";
|
||||
pub(crate) const TIMESTAMP: &str = "TIMESTAMP";
|
||||
pub(crate) const TIMESTAMP_FORMAT: &str = "TIMESTAMP-FORMAT";
|
||||
pub(crate) const TIMESTAMP_FORMAT: &str = "TIMESTAMP_FORMAT";
|
||||
pub(crate) const UNSORTED: &str = "UNSORTED";
|
||||
pub(crate) const UNSTABLE: &str = "UNSTABLE";
|
||||
pub(crate) const VERBOSE: &str = "VERBOSE";
|
||||
pub(crate) const WORKING_DIRECTORY: &str = "WORKING-DIRECTORY";
|
||||
pub(crate) const YES: &str = "YES";
|
||||
|
||||
pub(crate) const COLOR_ALWAYS: &str = "always";
|
||||
pub(crate) const COLOR_AUTO: &str = "auto";
|
||||
pub(crate) const COLOR_NEVER: &str = "never";
|
||||
pub(crate) const COLOR_VALUES: &[&str] = &[COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER];
|
||||
|
||||
pub(crate) const COMMAND_COLOR_BLACK: &str = "black";
|
||||
pub(crate) const COMMAND_COLOR_BLUE: &str = "blue";
|
||||
@ -128,7 +141,9 @@ mod arg {
|
||||
COMMAND_COLOR_YELLOW,
|
||||
];
|
||||
|
||||
pub(crate) const DUMP_FORMAT_JSON: &str = "json";
|
||||
pub(crate) const DUMP_FORMAT_JUST: &str = "just";
|
||||
pub(crate) const DUMP_FORMAT_VALUES: &[&str] = &[DUMP_FORMAT_JUST, DUMP_FORMAT_JSON];
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@ -145,20 +160,17 @@ impl Config {
|
||||
.trailing_var_arg(true)
|
||||
.styles(
|
||||
Styles::styled()
|
||||
.header(AnsiColor::Yellow.on_default())
|
||||
.literal(AnsiColor::Green.on_default())
|
||||
.placeholder(AnsiColor::Green.on_default())
|
||||
.usage(AnsiColor::Yellow.on_default()),
|
||||
.header(AnsiColor::Yellow.on_default())
|
||||
.usage(AnsiColor::Yellow.on_default())
|
||||
.literal(AnsiColor::Green.on_default())
|
||||
.placeholder(AnsiColor::Green.on_default())
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::CHECK)
|
||||
.long("check")
|
||||
.action(ArgAction::SetTrue)
|
||||
.requires(cmd::FORMAT)
|
||||
.help(
|
||||
"Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly. \
|
||||
Exits with 1 and prints a diff if formatting is required.",
|
||||
),
|
||||
.help("Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::CHOOSER)
|
||||
@ -167,19 +179,12 @@ impl Config {
|
||||
.action(ArgAction::Set)
|
||||
.help("Override binary invoked by `--choose`"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::CLEAR_SHELL_ARGS)
|
||||
.long("clear-shell-args")
|
||||
.action(ArgAction::SetTrue)
|
||||
.overrides_with(arg::SHELL_ARG)
|
||||
.help("Clear shell arguments"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::COLOR)
|
||||
.long("color")
|
||||
.env("JUST_COLOR")
|
||||
.action(ArgAction::Set)
|
||||
.value_parser(clap::value_parser!(UseColor))
|
||||
.value_parser(PossibleValuesParser::new(arg::COLOR_VALUES))
|
||||
.default_value(arg::COLOR_AUTO)
|
||||
.help("Print colorful output"),
|
||||
)
|
||||
@ -191,21 +196,7 @@ impl Config {
|
||||
.value_parser(PossibleValuesParser::new(arg::COMMAND_COLOR_VALUES))
|
||||
.help("Echo recipe lines in <COMMAND-COLOR>"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::DOTENV_FILENAME)
|
||||
.long("dotenv-filename")
|
||||
.action(ArgAction::Set)
|
||||
.help("Search for environment file named <DOTENV-FILENAME> instead of `.env`")
|
||||
.conflicts_with(arg::DOTENV_PATH),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::DOTENV_PATH)
|
||||
.short('E')
|
||||
.long("dotenv-path")
|
||||
.action(ArgAction::Set)
|
||||
.value_parser(value_parser!(PathBuf))
|
||||
.help("Load <DOTENV-PATH> as environment file instead of searching for one"),
|
||||
)
|
||||
.arg(Arg::new(arg::YES).long("yes").action(ArgAction::SetTrue).help("Automatically confirm all recipes."))
|
||||
.arg(
|
||||
Arg::new(arg::DRY_RUN)
|
||||
.short('n')
|
||||
@ -218,30 +209,59 @@ impl Config {
|
||||
.arg(
|
||||
Arg::new(arg::DUMP_FORMAT)
|
||||
.long("dump-format")
|
||||
.env("JUST_DUMP_FORMAT")
|
||||
.action(ArgAction::Set)
|
||||
.value_parser(clap::value_parser!(DumpFormat))
|
||||
.value_parser(PossibleValuesParser::new(arg::DUMP_FORMAT_VALUES))
|
||||
.default_value(arg::DUMP_FORMAT_JUST)
|
||||
.value_name("FORMAT")
|
||||
.help("Dump justfile as <FORMAT>"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::GLOBAL_JUSTFILE)
|
||||
.action(ArgAction::SetTrue)
|
||||
.long("global-justfile")
|
||||
.short('g')
|
||||
.conflicts_with(arg::JUSTFILE)
|
||||
.conflicts_with(arg::WORKING_DIRECTORY)
|
||||
.help("Use global justfile"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::HIGHLIGHT)
|
||||
.long("highlight")
|
||||
.env("JUST_HIGHLIGHT")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Highlight echoed recipe lines in bold")
|
||||
.overrides_with(arg::NO_HIGHLIGHT),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::LIST_HEADING)
|
||||
.long("list-heading")
|
||||
.help("Print <TEXT> before list")
|
||||
.value_name("TEXT")
|
||||
.action(ArgAction::Set),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::LIST_PREFIX)
|
||||
.long("list-prefix")
|
||||
.help("Print <TEXT> before each list item")
|
||||
.value_name("TEXT")
|
||||
.action(ArgAction::Set),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_ALIASES)
|
||||
.long("no-aliases")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't show aliases in list"),
|
||||
)
|
||||
.arg (
|
||||
Arg::new(arg::NO_DEPS)
|
||||
.long("no-deps")
|
||||
.alias("no-dependencies")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't run recipe dependencies")
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_DOTENV)
|
||||
.long("no-dotenv")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't load `.env` file"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_HIGHLIGHT)
|
||||
.long("no-highlight")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't highlight echoed recipe lines in bold")
|
||||
.overrides_with(arg::HIGHLIGHT),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::JUSTFILE)
|
||||
.short('f')
|
||||
@ -251,60 +271,6 @@ impl Config {
|
||||
.value_parser(value_parser!(PathBuf))
|
||||
.help("Use <JUSTFILE> as justfile"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::LIST_HEADING)
|
||||
.long("list-heading")
|
||||
.env("JUST_LIST_HEADING")
|
||||
.help("Print <TEXT> before list")
|
||||
.value_name("TEXT")
|
||||
.action(ArgAction::Set),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::LIST_PREFIX)
|
||||
.long("list-prefix")
|
||||
.env("JUST_LIST_PREFIX")
|
||||
.help("Print <TEXT> before each list item")
|
||||
.value_name("TEXT")
|
||||
.action(ArgAction::Set),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::LIST_SUBMODULES)
|
||||
.long("list-submodules")
|
||||
.env("JUST_LIST_SUBMODULES")
|
||||
.help("List recipes in submodules")
|
||||
.action(ArgAction::SetTrue)
|
||||
.env("JUST_LIST_SUBMODULES"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_ALIASES)
|
||||
.long("no-aliases")
|
||||
.env("JUST_NO_ALIASES")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't show aliases in list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_DEPS)
|
||||
.long("no-deps")
|
||||
.env("JUST_NO_DEPS")
|
||||
.alias("no-dependencies")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't run recipe dependencies"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_DOTENV)
|
||||
.long("no-dotenv")
|
||||
.env("JUST_NO_DOTENV")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't load `.env` file"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::NO_HIGHLIGHT)
|
||||
.long("no-highlight")
|
||||
.env("JUST_NO_HIGHLIGHT")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Don't highlight echoed recipe lines in bold")
|
||||
.overrides_with(arg::HIGHLIGHT),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::QUIET)
|
||||
.short('q')
|
||||
@ -344,24 +310,15 @@ impl Config {
|
||||
.help("Invoke <COMMAND> with the shell used to run recipe lines and backticks"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::TIMESTAMP)
|
||||
Arg::new(arg::CLEAR_SHELL_ARGS)
|
||||
.long("clear-shell-args")
|
||||
.action(ArgAction::SetTrue)
|
||||
.long("timestamp")
|
||||
.env("JUST_TIMESTAMP")
|
||||
.help("Print recipe command timestamps"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::TIMESTAMP_FORMAT)
|
||||
.action(ArgAction::Set)
|
||||
.long("timestamp-format")
|
||||
.env("JUST_TIMESTAMP_FORMAT")
|
||||
.default_value("%H:%M:%S")
|
||||
.help("Timestamp format string"),
|
||||
.overrides_with(arg::SHELL_ARG)
|
||||
.help("Clear shell arguments"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::UNSORTED)
|
||||
.long("unsorted")
|
||||
.env("JUST_UNSORTED")
|
||||
.short('u')
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Return list and summary entries in source order"),
|
||||
@ -392,28 +349,13 @@ impl Config {
|
||||
.help("Use <WORKING-DIRECTORY> as working directory. --justfile must also be set")
|
||||
.requires(arg::JUSTFILE),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::YES)
|
||||
.long("yes")
|
||||
.env("JUST_YES")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Automatically confirm all recipes."),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(cmd::CHANGELOG)
|
||||
.long("changelog")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Print changelog"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(cmd::CHOOSE)
|
||||
.long("choose")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help(
|
||||
"Select one or more recipes to run using a binary chooser. If `--chooser` is not \
|
||||
passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`",
|
||||
),
|
||||
)
|
||||
.arg(Arg::new(cmd::CHOOSE).long("choose").action(ArgAction::SetTrue).help(CHOOSE_HELP))
|
||||
.arg(
|
||||
Arg::new(cmd::COMMAND)
|
||||
.long("command")
|
||||
@ -430,9 +372,10 @@ impl Config {
|
||||
.arg(
|
||||
Arg::new(cmd::COMPLETIONS)
|
||||
.long("completions")
|
||||
.action(ArgAction::Set)
|
||||
.action(ArgAction::Append)
|
||||
.num_args(1..)
|
||||
.value_name("SHELL")
|
||||
.value_parser(value_parser!(completions::Shell))
|
||||
.value_parser(value_parser!(clap_complete::Shell))
|
||||
.ignore_case(true)
|
||||
.help("Print shell completion script for <SHELL>"),
|
||||
)
|
||||
@ -452,7 +395,6 @@ impl Config {
|
||||
.arg(
|
||||
Arg::new(cmd::EVALUATE)
|
||||
.long("evaluate")
|
||||
.alias("eval")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help(
|
||||
"Evaluate and print all variables. If a variable name is given as an argument, only \
|
||||
@ -466,12 +408,6 @@ impl Config {
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Format and overwrite justfile"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(cmd::GROUPS)
|
||||
.long("groups")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("List recipe groups"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(cmd::INIT)
|
||||
.long("init")
|
||||
@ -489,6 +425,12 @@ impl Config {
|
||||
.conflicts_with(arg::ARGUMENTS)
|
||||
.help("List available recipes"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(cmd::GROUPS)
|
||||
.long("groups")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("List recipe groups")
|
||||
)
|
||||
.arg(
|
||||
Arg::new(cmd::MAN)
|
||||
.long("man")
|
||||
@ -517,6 +459,21 @@ impl Config {
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("List names of variables"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::DOTENV_FILENAME)
|
||||
.long("dotenv-filename")
|
||||
.action(ArgAction::Set)
|
||||
.help("Search for environment file named <DOTENV-FILENAME> instead of `.env`")
|
||||
.conflicts_with(arg::DOTENV_PATH),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::DOTENV_PATH)
|
||||
.short('E')
|
||||
.long("dotenv-path")
|
||||
.action(ArgAction::Set)
|
||||
.value_parser(value_parser!(PathBuf))
|
||||
.help("Load <DOTENV-PATH> as environment file instead of searching for one")
|
||||
)
|
||||
.group(ArgGroup::new("SUBCOMMAND").args(cmd::ALL))
|
||||
.arg(
|
||||
Arg::new(arg::ARGUMENTS)
|
||||
@ -524,6 +481,47 @@ impl Config {
|
||||
.action(ArgAction::Append)
|
||||
.help("Overrides and recipe(s) to run, defaulting to the first recipe in the justfile"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::GLOBAL_JUSTFILE)
|
||||
.action(ArgAction::SetTrue)
|
||||
.long("global-justfile")
|
||||
.short('g')
|
||||
.conflicts_with(arg::JUSTFILE)
|
||||
.conflicts_with(arg::WORKING_DIRECTORY)
|
||||
.help("Use global justfile")
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::TIMESTAMP)
|
||||
.action(ArgAction::SetTrue)
|
||||
.long("timestamp")
|
||||
.env("JUST_TIMESTAMP")
|
||||
.help("Print recipe command timestamps")
|
||||
)
|
||||
.arg(
|
||||
Arg::new(arg::TIMESTAMP_FORMAT)
|
||||
.action(ArgAction::Set)
|
||||
.long("timestamp-format")
|
||||
.env("JUST_TIMESTAMP_FORMAT")
|
||||
.default_value("%H:%M:%S")
|
||||
.help("Timestamp format string")
|
||||
)
|
||||
}
|
||||
|
||||
fn color_from_matches(matches: &ArgMatches) -> ConfigResult<Color> {
|
||||
let value = matches
|
||||
.get_one::<String>(arg::COLOR)
|
||||
.ok_or_else(|| ConfigError::Internal {
|
||||
message: "`--color` had no value".to_string(),
|
||||
})?;
|
||||
|
||||
match value.as_str() {
|
||||
arg::COLOR_AUTO => Ok(Color::auto()),
|
||||
arg::COLOR_ALWAYS => Ok(Color::always()),
|
||||
arg::COLOR_NEVER => Ok(Color::never()),
|
||||
_ => Err(ConfigError::Internal {
|
||||
message: format!("Invalid argument `{value}` to --color."),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn command_color_from_matches(matches: &ArgMatches) -> ConfigResult<Option<ansi_term::Color>> {
|
||||
@ -545,20 +543,32 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_module_path(values: ValuesRef<String>) -> ConfigResult<ModulePath> {
|
||||
let path = values.clone().map(|s| (*s).as_str()).collect::<Vec<&str>>();
|
||||
fn dump_format_from_matches(matches: &ArgMatches) -> ConfigResult<DumpFormat> {
|
||||
let value =
|
||||
matches
|
||||
.get_one::<String>(arg::DUMP_FORMAT)
|
||||
.ok_or_else(|| ConfigError::Internal {
|
||||
message: "`--dump-format` had no value".to_string(),
|
||||
})?;
|
||||
|
||||
let path = if path.len() == 1 && path[0].contains(' ') {
|
||||
path[0].split_whitespace().collect::<Vec<&str>>()
|
||||
} else {
|
||||
path
|
||||
};
|
||||
match value.as_str() {
|
||||
arg::DUMP_FORMAT_JSON => Ok(DumpFormat::Json),
|
||||
arg::DUMP_FORMAT_JUST => Ok(DumpFormat::Just),
|
||||
_ => Err(ConfigError::Internal {
|
||||
message: format!("Invalid argument `{value}` to --dump-format."),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_module_path(path: ValuesRef<String>) -> ConfigResult<ModulePath> {
|
||||
path
|
||||
.clone()
|
||||
.map(|s| (*s).as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.as_slice()
|
||||
.try_into()
|
||||
.map_err(|()| ConfigError::ModulePath {
|
||||
path: values.cloned().collect(),
|
||||
path: path.cloned().collect(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -596,6 +606,17 @@ impl Config {
|
||||
}
|
||||
|
||||
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
|
||||
let invocation_directory = env::current_dir().context(config_error::CurrentDirContext)?;
|
||||
|
||||
let verbosity = if matches.get_flag(arg::QUIET) {
|
||||
Verbosity::Quiet
|
||||
} else {
|
||||
Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE))
|
||||
};
|
||||
|
||||
let color = Self::color_from_matches(matches)?;
|
||||
let command_color = Self::command_color_from_matches(matches)?;
|
||||
|
||||
let mut overrides = BTreeMap::new();
|
||||
if let Some(mut values) = matches.get_many::<String>(arg::SET) {
|
||||
while let (Some(k), Some(v)) = (values.next(), values.next()) {
|
||||
@ -656,12 +677,30 @@ impl Config {
|
||||
arguments,
|
||||
overrides,
|
||||
}
|
||||
} else if let Some(&shell) = matches.get_one::<completions::Shell>(cmd::COMPLETIONS) {
|
||||
} else if let Some(&shell) = matches.get_one::<clap_complete::Shell>(cmd::COMPLETIONS) {
|
||||
Subcommand::Completions { shell }
|
||||
} else if matches.get_flag(cmd::DUMP) {
|
||||
Subcommand::Dump
|
||||
} else if matches.get_flag(cmd::EDIT) {
|
||||
Subcommand::Edit
|
||||
} else if matches.get_flag(cmd::SUMMARY) {
|
||||
Subcommand::Summary
|
||||
} else if matches.get_flag(cmd::DUMP) {
|
||||
Subcommand::Dump
|
||||
} else if matches.get_flag(cmd::FORMAT) {
|
||||
Subcommand::Format
|
||||
} else if matches.get_flag(cmd::INIT) {
|
||||
Subcommand::Init
|
||||
} else if let Some(path) = matches.get_many::<String>(cmd::LIST) {
|
||||
Subcommand::List {
|
||||
path: Self::parse_module_path(path)?,
|
||||
}
|
||||
} else if matches.get_flag(cmd::GROUPS) {
|
||||
Subcommand::Groups
|
||||
} else if matches.get_flag(cmd::MAN) {
|
||||
Subcommand::Man
|
||||
} else if let Some(path) = matches.get_many::<String>(cmd::SHOW) {
|
||||
Subcommand::Show {
|
||||
path: Self::parse_module_path(path)?,
|
||||
}
|
||||
} else if matches.get_flag(cmd::EVALUATE) {
|
||||
if positional.arguments.len() > 1 {
|
||||
return Err(ConfigError::SubcommandArguments {
|
||||
@ -678,24 +717,6 @@ impl Config {
|
||||
variable: positional.arguments.into_iter().next(),
|
||||
overrides,
|
||||
}
|
||||
} else if matches.get_flag(cmd::FORMAT) {
|
||||
Subcommand::Format
|
||||
} else if matches.get_flag(cmd::GROUPS) {
|
||||
Subcommand::Groups
|
||||
} else if matches.get_flag(cmd::INIT) {
|
||||
Subcommand::Init
|
||||
} else if let Some(path) = matches.get_many::<String>(cmd::LIST) {
|
||||
Subcommand::List {
|
||||
path: Self::parse_module_path(path)?,
|
||||
}
|
||||
} else if matches.get_flag(cmd::MAN) {
|
||||
Subcommand::Man
|
||||
} else if let Some(path) = matches.get_many::<String>(cmd::SHOW) {
|
||||
Subcommand::Show {
|
||||
path: Self::parse_module_path(path)?,
|
||||
}
|
||||
} else if matches.get_flag(cmd::SUMMARY) {
|
||||
Subcommand::Summary
|
||||
} else if matches.get_flag(cmd::VARIABLES) {
|
||||
Subcommand::Variables
|
||||
} else {
|
||||
@ -705,40 +726,40 @@ impl Config {
|
||||
}
|
||||
};
|
||||
|
||||
let shell_args = if matches.get_flag(arg::CLEAR_SHELL_ARGS) {
|
||||
Some(Vec::new())
|
||||
} else {
|
||||
matches
|
||||
.get_many::<String>(arg::SHELL_ARG)
|
||||
.map(|s| s.map(Into::into).collect())
|
||||
};
|
||||
|
||||
let unstable = matches.get_flag(arg::UNSTABLE);
|
||||
|
||||
Ok(Self {
|
||||
check: matches.get_flag(arg::CHECK),
|
||||
color: (*matches.get_one::<UseColor>(arg::COLOR).unwrap()).into(),
|
||||
command_color: Self::command_color_from_matches(matches)?,
|
||||
color,
|
||||
command_color,
|
||||
dotenv_filename: matches
|
||||
.get_one::<String>(arg::DOTENV_FILENAME)
|
||||
.map(Into::into),
|
||||
dotenv_path: matches.get_one::<PathBuf>(arg::DOTENV_PATH).map(Into::into),
|
||||
dry_run: matches.get_flag(arg::DRY_RUN),
|
||||
dump_format: matches
|
||||
.get_one::<DumpFormat>(arg::DUMP_FORMAT)
|
||||
.unwrap()
|
||||
.clone(),
|
||||
dump_format: Self::dump_format_from_matches(matches)?,
|
||||
highlight: !matches.get_flag(arg::NO_HIGHLIGHT),
|
||||
invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?,
|
||||
invocation_directory,
|
||||
list_heading: matches
|
||||
.get_one::<String>(arg::LIST_HEADING)
|
||||
.map_or_else(|| "Available recipes:\n".into(), Into::into),
|
||||
list_prefix: matches
|
||||
.get_one::<String>(arg::LIST_PREFIX)
|
||||
.map_or_else(|| " ".into(), Into::into),
|
||||
list_submodules: matches.get_flag(arg::LIST_SUBMODULES),
|
||||
load_dotenv: !matches.get_flag(arg::NO_DOTENV),
|
||||
no_aliases: matches.get_flag(arg::NO_ALIASES),
|
||||
no_dependencies: matches.get_flag(arg::NO_DEPS),
|
||||
search_config,
|
||||
shell: matches.get_one::<String>(arg::SHELL).map(Into::into),
|
||||
shell_args: if matches.get_flag(arg::CLEAR_SHELL_ARGS) {
|
||||
Some(Vec::new())
|
||||
} else {
|
||||
matches
|
||||
.get_many::<String>(arg::SHELL_ARG)
|
||||
.map(|s| s.map(Into::into).collect())
|
||||
},
|
||||
shell_args,
|
||||
shell_command: matches.get_flag(arg::SHELL_COMMAND),
|
||||
subcommand,
|
||||
timestamp: matches.get_flag(arg::TIMESTAMP),
|
||||
@ -747,17 +768,13 @@ impl Config {
|
||||
.unwrap()
|
||||
.into(),
|
||||
unsorted: matches.get_flag(arg::UNSORTED),
|
||||
unstable: matches.get_flag(arg::UNSTABLE),
|
||||
verbosity: if matches.get_flag(arg::QUIET) {
|
||||
Verbosity::Quiet
|
||||
} else {
|
||||
Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE))
|
||||
},
|
||||
unstable,
|
||||
verbosity,
|
||||
yes: matches.get_flag(arg::YES),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn require_unstable(&self, message: &str) -> RunResult<'static> {
|
||||
pub(crate) fn require_unstable(&self, message: &str) -> Result<(), Error<'static>> {
|
||||
if self.unstable {
|
||||
Ok(())
|
||||
} else {
|
||||
@ -767,7 +784,7 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn run(self, loader: &Loader) -> RunResult {
|
||||
pub(crate) fn run(self, loader: &Loader) -> Result<(), Error> {
|
||||
if let Err(error) = InterruptHandler::install(self.verbosity) {
|
||||
warn!("Failed to set CTRL-C handler: {error}");
|
||||
}
|
||||
@ -1228,13 +1245,13 @@ mod tests {
|
||||
test! {
|
||||
name: subcommand_completions,
|
||||
args: ["--completions", "bash"],
|
||||
subcommand: Subcommand::Completions{ shell: completions::Shell::Bash },
|
||||
subcommand: Subcommand::Completions{ shell: clap_complete::Shell::Bash },
|
||||
}
|
||||
|
||||
test! {
|
||||
name: subcommand_completions_uppercase,
|
||||
args: ["--completions", "BASH"],
|
||||
subcommand: Subcommand::Completions{ shell: completions::Shell::Bash },
|
||||
subcommand: Subcommand::Completions{ shell: clap_complete::Shell::Bash },
|
||||
}
|
||||
|
||||
error! {
|
||||
@ -1517,30 +1534,15 @@ mod tests {
|
||||
}
|
||||
|
||||
error_matches! {
|
||||
name: completions_argument,
|
||||
args: ["--completions", "foo"],
|
||||
name: completions_arguments,
|
||||
args: ["--completions", "zsh", "foo"],
|
||||
error: error,
|
||||
check: {
|
||||
assert_eq!(error.kind(), clap::error::ErrorKind::InvalidValue);
|
||||
assert_eq!(error.context().collect::<Vec<_>>(), vec![
|
||||
(
|
||||
ContextKind::InvalidArg,
|
||||
&ContextValue::String("--completions <SHELL>".into())),
|
||||
(
|
||||
ContextKind::InvalidValue,
|
||||
&ContextValue::String("foo".into()),
|
||||
),
|
||||
(
|
||||
ContextKind::ValidValue,
|
||||
&ContextValue::Strings([
|
||||
"bash".into(),
|
||||
"elvish".into(),
|
||||
"fish".into(),
|
||||
"nushell".into(),
|
||||
"powershell".into(),
|
||||
"zsh".into()].into()
|
||||
),
|
||||
),
|
||||
(ContextKind::InvalidArg, &ContextValue::String("--completions <SHELL>...".into())),
|
||||
(ContextKind::InvalidValue, &ContextValue::String("foo".into())),
|
||||
(ContextKind::ValidValue, &ContextValue::Strings(["bash".into(), "elvish".into(), "fish".into(), "powershell".into(), "zsh".into()].into())),
|
||||
]);
|
||||
},
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ pub(crate) struct Dependency<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Dependency<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
if self.arguments.is_empty() {
|
||||
write!(f, "{}", self.recipe.name())
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#[derive(Debug, PartialEq, Clone, clap::ValueEnum)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) enum DumpFormat {
|
||||
Json,
|
||||
Just,
|
||||
|
30
src/error.rs
30
src/error.rs
@ -20,7 +20,7 @@ pub(crate) enum Error<'src> {
|
||||
token: Token<'src>,
|
||||
output_error: OutputError,
|
||||
},
|
||||
RuntimeDirIo {
|
||||
CacheDirIo {
|
||||
io_error: io::Error,
|
||||
path: PathBuf,
|
||||
},
|
||||
@ -79,7 +79,6 @@ pub(crate) enum Error<'src> {
|
||||
Dotenv {
|
||||
dotenv_error: dotenvy::Error,
|
||||
},
|
||||
DotenvRequired,
|
||||
DumpJson {
|
||||
serde_json_error: serde_json::Error,
|
||||
},
|
||||
@ -95,9 +94,6 @@ pub(crate) enum Error<'src> {
|
||||
variable: String,
|
||||
suggestion: Option<Suggestion<'src>>,
|
||||
},
|
||||
ExpectedSubmoduleButFoundRecipe {
|
||||
path: String,
|
||||
},
|
||||
FormatCheckFoundDiff,
|
||||
FunctionCall {
|
||||
function: Name<'src>,
|
||||
@ -165,13 +161,13 @@ pub(crate) enum Error<'src> {
|
||||
line_number: Option<usize>,
|
||||
},
|
||||
UnknownSubmodule {
|
||||
path: String,
|
||||
path: ModulePath,
|
||||
},
|
||||
UnknownOverrides {
|
||||
overrides: Vec<String>,
|
||||
},
|
||||
UnknownRecipe {
|
||||
recipe: String,
|
||||
UnknownRecipes {
|
||||
recipes: Vec<String>,
|
||||
suggestion: Option<Suggestion<'src>>,
|
||||
},
|
||||
Unstable {
|
||||
@ -290,6 +286,9 @@ impl<'src> ColorDisplay for Error<'src> {
|
||||
}?,
|
||||
OutputError::Utf8(utf8_error) => write!(f, "Backtick succeeded but stdout was not utf8: {utf8_error}")?,
|
||||
}
|
||||
CacheDirIo { io_error, path } => {
|
||||
write!(f, "I/O error in cache dir `{}`: {io_error}", path.display())?;
|
||||
}
|
||||
ChooserInvoke { shell_binary, shell_arguments, chooser, io_error} => {
|
||||
let chooser = chooser.to_string_lossy();
|
||||
write!(f, "Chooser `{shell_binary} {shell_arguments} {chooser}` invocation failed: {io_error}")?;
|
||||
@ -348,9 +347,6 @@ impl<'src> ColorDisplay for Error<'src> {
|
||||
Dotenv { dotenv_error } => {
|
||||
write!(f, "Failed to load environment file: {dotenv_error}")?;
|
||||
}
|
||||
DotenvRequired => {
|
||||
write!(f, "Dotenv file not found")?;
|
||||
}
|
||||
DumpJson { serde_json_error } => {
|
||||
write!(f, "Failed to dump JSON to stdout: {serde_json_error}")?;
|
||||
}
|
||||
@ -368,9 +364,6 @@ impl<'src> ColorDisplay for Error<'src> {
|
||||
write!(f, "\n{suggestion}")?;
|
||||
}
|
||||
}
|
||||
ExpectedSubmoduleButFoundRecipe { path } => {
|
||||
write!(f, "Expected submodule at `{path}` but found recipe.")?;
|
||||
},
|
||||
FormatCheckFoundDiff => {
|
||||
write!(f, "Formatted justfile differs from original.")?;
|
||||
}
|
||||
@ -410,9 +403,6 @@ impl<'src> ColorDisplay for Error<'src> {
|
||||
write!(f, "Recipe `{recipe}` was not confirmed")?;
|
||||
}
|
||||
RegexCompile { source } => write!(f, "{source}")?,
|
||||
RuntimeDirIo { io_error, path } => {
|
||||
write!(f, "I/O error in runtime dir `{}`: {io_error}", path.display())?;
|
||||
}
|
||||
Search { search_error } => Display::fmt(search_error, f)?,
|
||||
Shebang { recipe, command, argument, io_error} => {
|
||||
if let Some(argument) = argument {
|
||||
@ -453,8 +443,10 @@ impl<'src> ColorDisplay for Error<'src> {
|
||||
let overrides = List::and_ticked(overrides);
|
||||
write!(f, "{count} {overrides} overridden on the command line but not present in justfile")?;
|
||||
}
|
||||
UnknownRecipe { recipe, suggestion } => {
|
||||
write!(f, "Justfile does not contain recipe `{recipe}`.")?;
|
||||
UnknownRecipes { recipes, suggestion } => {
|
||||
let count = Count("recipe", recipes.len());
|
||||
let recipes = List::or_ticked(recipes);
|
||||
write!(f, "Justfile does not contain {count} {recipes}.")?;
|
||||
if let Some(suggestion) = suggestion {
|
||||
write!(f, "\n{suggestion}")?;
|
||||
}
|
||||
|
114
src/evaluator.rs
114
src/evaluator.rs
@ -2,58 +2,35 @@ use super::*;
|
||||
|
||||
pub(crate) struct Evaluator<'src: 'run, 'run> {
|
||||
pub(crate) assignments: Option<&'run Table<'src, Assignment<'src>>>,
|
||||
pub(crate) context: ExecutionContext<'src, 'run>,
|
||||
pub(crate) is_dependency: bool,
|
||||
pub(crate) config: &'run Config,
|
||||
pub(crate) dotenv: &'run BTreeMap<String, String>,
|
||||
pub(crate) module_source: &'run Path,
|
||||
pub(crate) scope: Scope<'src, 'run>,
|
||||
pub(crate) search: &'run Search,
|
||||
pub(crate) settings: &'run Settings<'run>,
|
||||
}
|
||||
|
||||
impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
pub(crate) fn evaluate_assignments(
|
||||
assignments: &'run Table<'src, Assignment<'src>>,
|
||||
config: &'run Config,
|
||||
dotenv: &'run BTreeMap<String, String>,
|
||||
module: &'run Justfile<'src>,
|
||||
overrides: &BTreeMap<String, String>,
|
||||
parent: &'run Scope<'src, 'run>,
|
||||
module_source: &'run Path,
|
||||
scope: Scope<'src, 'run>,
|
||||
search: &'run Search,
|
||||
) -> RunResult<'src, Scope<'src, 'run>>
|
||||
where
|
||||
'src: 'run,
|
||||
{
|
||||
let context = ExecutionContext {
|
||||
settings: &'run Settings<'run>,
|
||||
) -> RunResult<'src, Scope<'src, 'run>> {
|
||||
let mut evaluator = Self {
|
||||
assignments: Some(assignments),
|
||||
config,
|
||||
dotenv,
|
||||
module_source: &module.source,
|
||||
scope: parent,
|
||||
search,
|
||||
settings: &module.settings,
|
||||
unexports: &module.unexports,
|
||||
};
|
||||
|
||||
let mut scope = context.scope.child();
|
||||
let mut unknown_overrides = Vec::new();
|
||||
|
||||
for (name, value) in overrides {
|
||||
if let Some(assignment) = module.assignments.get(name) {
|
||||
scope.bind(assignment.export, assignment.name, value.clone());
|
||||
} else {
|
||||
unknown_overrides.push(name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if !unknown_overrides.is_empty() {
|
||||
return Err(Error::UnknownOverrides {
|
||||
overrides: unknown_overrides,
|
||||
});
|
||||
}
|
||||
|
||||
let mut evaluator = Self {
|
||||
context,
|
||||
assignments: Some(&module.assignments),
|
||||
module_source,
|
||||
scope,
|
||||
is_dependency: false,
|
||||
search,
|
||||
settings,
|
||||
};
|
||||
|
||||
for assignment in module.assignments.values() {
|
||||
for assignment in assignments.values() {
|
||||
evaluator.evaluate_assignment(assignment)?;
|
||||
}
|
||||
|
||||
@ -175,7 +152,7 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
}
|
||||
Expression::StringLiteral { string_literal } => Ok(string_literal.cooked.clone()),
|
||||
Expression::Backtick { contents, token } => {
|
||||
if self.context.config.dry_run {
|
||||
if self.config.dry_run {
|
||||
Ok(format!("`{contents}`"))
|
||||
} else {
|
||||
Ok(self.run_backtick(contents, token)?)
|
||||
@ -236,18 +213,13 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
}
|
||||
|
||||
pub(crate) fn run_command(&self, command: &str, args: &[&str]) -> Result<String, OutputError> {
|
||||
let mut cmd = self.context.settings.shell_command(self.context.config);
|
||||
let mut cmd = self.settings.shell_command(self.config);
|
||||
cmd.arg(command);
|
||||
cmd.args(args);
|
||||
cmd.current_dir(&self.context.search.working_directory);
|
||||
cmd.export(
|
||||
self.context.settings,
|
||||
self.context.dotenv,
|
||||
&self.scope,
|
||||
self.context.unexports,
|
||||
);
|
||||
cmd.current_dir(&self.search.working_directory);
|
||||
cmd.export(self.settings, self.dotenv, &self.scope);
|
||||
cmd.stdin(Stdio::inherit());
|
||||
cmd.stderr(if self.context.config.verbosity.quiet() {
|
||||
cmd.stderr(if self.config.verbosity.quiet() {
|
||||
Stdio::null()
|
||||
} else {
|
||||
Stdio::inherit()
|
||||
@ -281,12 +253,26 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
}
|
||||
|
||||
pub(crate) fn evaluate_parameters(
|
||||
context: &ExecutionContext<'src, 'run>,
|
||||
is_dependency: bool,
|
||||
arguments: &[String],
|
||||
config: &'run Config,
|
||||
dotenv: &'run BTreeMap<String, String>,
|
||||
module_source: &'run Path,
|
||||
parameters: &[Parameter<'src>],
|
||||
scope: &'run Scope<'src, 'run>,
|
||||
search: &'run Search,
|
||||
settings: &'run Settings,
|
||||
) -> RunResult<'src, (Scope<'src, 'run>, Vec<String>)> {
|
||||
let mut evaluator = Self::new(context, is_dependency, context.scope);
|
||||
let mut evaluator = Self {
|
||||
assignments: None,
|
||||
config,
|
||||
dotenv,
|
||||
module_source,
|
||||
scope: scope.child(),
|
||||
search,
|
||||
settings,
|
||||
};
|
||||
|
||||
let mut scope = scope.child();
|
||||
|
||||
let mut positional = Vec::new();
|
||||
|
||||
@ -317,24 +303,28 @@ impl<'src, 'run> Evaluator<'src, 'run> {
|
||||
rest = &rest[1..];
|
||||
value
|
||||
};
|
||||
evaluator
|
||||
.scope
|
||||
.bind(parameter.export, parameter.name, value);
|
||||
scope.bind(parameter.export, parameter.name, value);
|
||||
}
|
||||
|
||||
Ok((evaluator.scope, positional))
|
||||
Ok((scope, positional))
|
||||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
context: &ExecutionContext<'src, 'run>,
|
||||
is_dependency: bool,
|
||||
pub(crate) fn recipe_evaluator(
|
||||
config: &'run Config,
|
||||
dotenv: &'run BTreeMap<String, String>,
|
||||
module_source: &'run Path,
|
||||
scope: &'run Scope<'src, 'run>,
|
||||
search: &'run Search,
|
||||
settings: &'run Settings,
|
||||
) -> Self {
|
||||
Self {
|
||||
assignments: None,
|
||||
context: *context,
|
||||
is_dependency,
|
||||
scope: scope.child(),
|
||||
config,
|
||||
dotenv,
|
||||
module_source,
|
||||
scope: Scope::child(scope),
|
||||
search,
|
||||
settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ impl<'src> Expression<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Expression<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
match self {
|
||||
Self::Assert { condition, error } => write!(f, "assert({condition}, {error})"),
|
||||
Self::Backtick { token, .. } => write!(f, "{}", token.lexeme()),
|
||||
|
227
src/function.rs
227
src/function.rs
@ -11,13 +11,13 @@ use {
|
||||
};
|
||||
|
||||
pub(crate) enum Function {
|
||||
Nullary(fn(Context) -> FunctionResult),
|
||||
Unary(fn(Context, &str) -> FunctionResult),
|
||||
UnaryOpt(fn(Context, &str, Option<&str>) -> FunctionResult),
|
||||
UnaryPlus(fn(Context, &str, &[String]) -> FunctionResult),
|
||||
Binary(fn(Context, &str, &str) -> FunctionResult),
|
||||
BinaryPlus(fn(Context, &str, &str, &[String]) -> FunctionResult),
|
||||
Ternary(fn(Context, &str, &str, &str) -> FunctionResult),
|
||||
Nullary(fn(Context) -> Result<String, String>),
|
||||
Unary(fn(Context, &str) -> Result<String, String>),
|
||||
UnaryOpt(fn(Context, &str, Option<&str>) -> Result<String, String>),
|
||||
UnaryPlus(fn(Context, &str, &[String]) -> Result<String, String>),
|
||||
Binary(fn(Context, &str, &str) -> Result<String, String>),
|
||||
BinaryPlus(fn(Context, &str, &str, &[String]) -> Result<String, String>),
|
||||
Ternary(fn(Context, &str, &str, &str) -> Result<String, String>),
|
||||
}
|
||||
|
||||
pub(crate) struct Context<'src: 'run, 'run> {
|
||||
@ -47,8 +47,6 @@ pub(crate) fn get(name: &str) -> Option<Function> {
|
||||
"config_local_directory" => Nullary(|_| dir("local config", dirs::config_local_dir)),
|
||||
"data_directory" => Nullary(|_| dir("data", dirs::data_dir)),
|
||||
"data_local_directory" => Nullary(|_| dir("local data", dirs::data_local_dir)),
|
||||
"datetime" => Unary(datetime),
|
||||
"datetime_utc" => Unary(datetime_utc),
|
||||
"encode_uri_component" => Unary(encode_uri_component),
|
||||
"env" => UnaryOpt(env),
|
||||
"env_var" => Unary(env_var),
|
||||
@ -61,7 +59,6 @@ pub(crate) fn get(name: &str) -> Option<Function> {
|
||||
"home_directory" => Nullary(|_| dir("home", dirs::home_dir)),
|
||||
"invocation_directory" => Nullary(invocation_directory),
|
||||
"invocation_directory_native" => Nullary(invocation_directory_native),
|
||||
"is_dependency" => Nullary(is_dependency),
|
||||
"join" => BinaryPlus(join),
|
||||
"just_executable" => Nullary(just_executable),
|
||||
"just_pid" => Nullary(just_pid),
|
||||
@ -121,10 +118,9 @@ impl Function {
|
||||
}
|
||||
}
|
||||
|
||||
fn absolute_path(context: Context, path: &str) -> FunctionResult {
|
||||
fn absolute_path(context: Context, path: &str) -> Result<String, String> {
|
||||
let abs_path_unchecked = context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.working_directory
|
||||
.join(path)
|
||||
@ -133,12 +129,12 @@ fn absolute_path(context: Context, path: &str) -> FunctionResult {
|
||||
Some(absolute_path) => Ok(absolute_path.to_owned()),
|
||||
None => Err(format!(
|
||||
"Working directory is not valid unicode: {}",
|
||||
context.evaluator.context.search.working_directory.display()
|
||||
context.evaluator.search.working_directory.display()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn append(_context: Context, suffix: &str, s: &str) -> FunctionResult {
|
||||
fn append(_context: Context, suffix: &str, s: &str) -> Result<String, String> {
|
||||
Ok(
|
||||
s.split_whitespace()
|
||||
.map(|s| format!("{s}{suffix}"))
|
||||
@ -147,21 +143,16 @@ fn append(_context: Context, suffix: &str, s: &str) -> FunctionResult {
|
||||
)
|
||||
}
|
||||
|
||||
fn arch(_context: Context) -> FunctionResult {
|
||||
fn arch(_context: Context) -> Result<String, String> {
|
||||
Ok(target::arch().to_owned())
|
||||
}
|
||||
|
||||
fn blake3(_context: Context, s: &str) -> FunctionResult {
|
||||
fn blake3(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(blake3::hash(s.as_bytes()).to_string())
|
||||
}
|
||||
|
||||
fn blake3_file(context: Context, path: &str) -> FunctionResult {
|
||||
let path = context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.working_directory
|
||||
.join(path);
|
||||
fn blake3_file(context: Context, path: &str) -> Result<String, String> {
|
||||
let path = context.evaluator.search.working_directory.join(path);
|
||||
let mut hasher = blake3::Hasher::new();
|
||||
hasher
|
||||
.update_mmap_rayon(&path)
|
||||
@ -169,7 +160,7 @@ fn blake3_file(context: Context, path: &str) -> FunctionResult {
|
||||
Ok(hasher.finalize().to_string())
|
||||
}
|
||||
|
||||
fn canonicalize(_context: Context, path: &str) -> FunctionResult {
|
||||
fn canonicalize(_context: Context, path: &str) -> Result<String, String> {
|
||||
let canonical =
|
||||
std::fs::canonicalize(path).map_err(|err| format!("I/O error canonicalizing path: {err}"))?;
|
||||
|
||||
@ -181,7 +172,7 @@ fn canonicalize(_context: Context, path: &str) -> FunctionResult {
|
||||
})
|
||||
}
|
||||
|
||||
fn capitalize(_context: Context, s: &str) -> FunctionResult {
|
||||
fn capitalize(_context: Context, s: &str) -> Result<String, String> {
|
||||
let mut capitalized = String::new();
|
||||
for (i, c) in s.chars().enumerate() {
|
||||
if i == 0 {
|
||||
@ -193,7 +184,7 @@ fn capitalize(_context: Context, s: &str) -> FunctionResult {
|
||||
Ok(capitalized)
|
||||
}
|
||||
|
||||
fn choose(_context: Context, n: &str, alphabet: &str) -> FunctionResult {
|
||||
fn choose(_context: Context, n: &str, alphabet: &str) -> Result<String, String> {
|
||||
if alphabet.is_empty() {
|
||||
return Err("empty alphabet".into());
|
||||
}
|
||||
@ -217,11 +208,11 @@ fn choose(_context: Context, n: &str, alphabet: &str) -> FunctionResult {
|
||||
Ok((0..n).map(|_| alphabet.choose(&mut rng).unwrap()).collect())
|
||||
}
|
||||
|
||||
fn clean(_context: Context, path: &str) -> FunctionResult {
|
||||
fn clean(_context: Context, path: &str) -> Result<String, String> {
|
||||
Ok(Path::new(path).lexiclean().to_str().unwrap().to_owned())
|
||||
}
|
||||
|
||||
fn dir(name: &'static str, f: fn() -> Option<PathBuf>) -> FunctionResult {
|
||||
fn dir(name: &'static str, f: fn() -> Option<PathBuf>) -> Result<String, String> {
|
||||
match f() {
|
||||
Some(path) => path
|
||||
.as_os_str()
|
||||
@ -237,15 +228,7 @@ fn dir(name: &'static str, f: fn() -> Option<PathBuf>) -> FunctionResult {
|
||||
}
|
||||
}
|
||||
|
||||
fn datetime(_context: Context, format: &str) -> FunctionResult {
|
||||
Ok(chrono::Local::now().format(format).to_string())
|
||||
}
|
||||
|
||||
fn datetime_utc(_context: Context, format: &str) -> FunctionResult {
|
||||
Ok(chrono::Utc::now().format(format).to_string())
|
||||
}
|
||||
|
||||
fn encode_uri_component(_context: Context, s: &str) -> FunctionResult {
|
||||
fn encode_uri_component(_context: Context, s: &str) -> Result<String, String> {
|
||||
static PERCENT_ENCODE: percent_encoding::AsciiSet = percent_encoding::NON_ALPHANUMERIC
|
||||
.remove(b'-')
|
||||
.remove(b'_')
|
||||
@ -259,10 +242,10 @@ fn encode_uri_component(_context: Context, s: &str) -> FunctionResult {
|
||||
Ok(percent_encoding::utf8_percent_encode(s, &PERCENT_ENCODE).to_string())
|
||||
}
|
||||
|
||||
fn env_var(context: Context, key: &str) -> FunctionResult {
|
||||
fn env_var(context: Context, key: &str) -> Result<String, String> {
|
||||
use std::env::VarError::*;
|
||||
|
||||
if let Some(value) = context.evaluator.context.dotenv.get(key) {
|
||||
if let Some(value) = context.evaluator.dotenv.get(key) {
|
||||
return Ok(value.clone());
|
||||
}
|
||||
|
||||
@ -275,10 +258,10 @@ fn env_var(context: Context, key: &str) -> FunctionResult {
|
||||
}
|
||||
}
|
||||
|
||||
fn env_var_or_default(context: Context, key: &str, default: &str) -> FunctionResult {
|
||||
fn env_var_or_default(context: Context, key: &str, default: &str) -> Result<String, String> {
|
||||
use std::env::VarError::*;
|
||||
|
||||
if let Some(value) = context.evaluator.context.dotenv.get(key) {
|
||||
if let Some(value) = context.evaluator.dotenv.get(key) {
|
||||
return Ok(value.clone());
|
||||
}
|
||||
|
||||
@ -291,50 +274,49 @@ fn env_var_or_default(context: Context, key: &str, default: &str) -> FunctionRes
|
||||
}
|
||||
}
|
||||
|
||||
fn env(context: Context, key: &str, default: Option<&str>) -> FunctionResult {
|
||||
fn env(context: Context, key: &str, default: Option<&str>) -> Result<String, String> {
|
||||
match default {
|
||||
Some(val) => env_var_or_default(context, key, val),
|
||||
None => env_var(context, key),
|
||||
}
|
||||
}
|
||||
|
||||
fn error(_context: Context, message: &str) -> FunctionResult {
|
||||
fn error(_context: Context, message: &str) -> Result<String, String> {
|
||||
Err(message.to_owned())
|
||||
}
|
||||
|
||||
fn extension(_context: Context, path: &str) -> FunctionResult {
|
||||
fn extension(_context: Context, path: &str) -> Result<String, String> {
|
||||
Utf8Path::new(path)
|
||||
.extension()
|
||||
.map(str::to_owned)
|
||||
.ok_or_else(|| format!("Could not extract extension from `{path}`"))
|
||||
}
|
||||
|
||||
fn file_name(_context: Context, path: &str) -> FunctionResult {
|
||||
fn file_name(_context: Context, path: &str) -> Result<String, String> {
|
||||
Utf8Path::new(path)
|
||||
.file_name()
|
||||
.map(str::to_owned)
|
||||
.ok_or_else(|| format!("Could not extract file name from `{path}`"))
|
||||
}
|
||||
|
||||
fn file_stem(_context: Context, path: &str) -> FunctionResult {
|
||||
fn file_stem(_context: Context, path: &str) -> Result<String, String> {
|
||||
Utf8Path::new(path)
|
||||
.file_stem()
|
||||
.map(str::to_owned)
|
||||
.ok_or_else(|| format!("Could not extract file stem from `{path}`"))
|
||||
}
|
||||
|
||||
fn invocation_directory(context: Context) -> FunctionResult {
|
||||
fn invocation_directory(context: Context) -> Result<String, String> {
|
||||
Platform::convert_native_path(
|
||||
&context.evaluator.context.search.working_directory,
|
||||
&context.evaluator.context.config.invocation_directory,
|
||||
&context.evaluator.search.working_directory,
|
||||
&context.evaluator.config.invocation_directory,
|
||||
)
|
||||
.map_err(|e| format!("Error getting shell path: {e}"))
|
||||
}
|
||||
|
||||
fn invocation_directory_native(context: Context) -> FunctionResult {
|
||||
fn invocation_directory_native(context: Context) -> Result<String, String> {
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.config
|
||||
.invocation_directory
|
||||
.to_str()
|
||||
@ -342,21 +324,12 @@ fn invocation_directory_native(context: Context) -> FunctionResult {
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"Invocation directory is not valid unicode: {}",
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.config
|
||||
.invocation_directory
|
||||
.display()
|
||||
context.evaluator.config.invocation_directory.display()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn is_dependency(context: Context) -> FunctionResult {
|
||||
Ok(context.evaluator.is_dependency.to_string())
|
||||
}
|
||||
|
||||
fn prepend(_context: Context, prefix: &str, s: &str) -> FunctionResult {
|
||||
fn prepend(_context: Context, prefix: &str, s: &str) -> Result<String, String> {
|
||||
Ok(
|
||||
s.split_whitespace()
|
||||
.map(|s| format!("{prefix}{s}"))
|
||||
@ -365,7 +338,7 @@ fn prepend(_context: Context, prefix: &str, s: &str) -> FunctionResult {
|
||||
)
|
||||
}
|
||||
|
||||
fn join(_context: Context, base: &str, with: &str, and: &[String]) -> FunctionResult {
|
||||
fn join(_context: Context, base: &str, with: &str, and: &[String]) -> Result<String, String> {
|
||||
let mut result = Utf8Path::new(base).join(with);
|
||||
for arg in and {
|
||||
result.push(arg);
|
||||
@ -373,7 +346,7 @@ fn join(_context: Context, base: &str, with: &str, and: &[String]) -> FunctionRe
|
||||
Ok(result.to_string())
|
||||
}
|
||||
|
||||
fn just_executable(_context: Context) -> FunctionResult {
|
||||
fn just_executable(_context: Context) -> Result<String, String> {
|
||||
let exe_path =
|
||||
env::current_exe().map_err(|e| format!("Error getting current executable: {e}"))?;
|
||||
|
||||
@ -385,14 +358,13 @@ fn just_executable(_context: Context) -> FunctionResult {
|
||||
})
|
||||
}
|
||||
|
||||
fn just_pid(_context: Context) -> FunctionResult {
|
||||
fn just_pid(_context: Context) -> Result<String, String> {
|
||||
Ok(std::process::id().to_string())
|
||||
}
|
||||
|
||||
fn justfile(context: Context) -> FunctionResult {
|
||||
fn justfile(context: Context) -> Result<String, String> {
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.justfile
|
||||
.to_str()
|
||||
@ -400,24 +372,18 @@ fn justfile(context: Context) -> FunctionResult {
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"Justfile path is not valid unicode: {}",
|
||||
context.evaluator.context.search.justfile.display()
|
||||
context.evaluator.search.justfile.display()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn justfile_directory(context: Context) -> FunctionResult {
|
||||
let justfile_directory = context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.justfile
|
||||
.parent()
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"Could not resolve justfile directory. Justfile `{}` had no parent.",
|
||||
context.evaluator.context.search.justfile.display()
|
||||
)
|
||||
})?;
|
||||
fn justfile_directory(context: Context) -> Result<String, String> {
|
||||
let justfile_directory = context.evaluator.search.justfile.parent().ok_or_else(|| {
|
||||
format!(
|
||||
"Could not resolve justfile directory. Justfile `{}` had no parent.",
|
||||
context.evaluator.search.justfile.display()
|
||||
)
|
||||
})?;
|
||||
|
||||
justfile_directory
|
||||
.to_str()
|
||||
@ -430,27 +396,26 @@ fn justfile_directory(context: Context) -> FunctionResult {
|
||||
})
|
||||
}
|
||||
|
||||
fn kebabcase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn kebabcase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_kebab_case())
|
||||
}
|
||||
|
||||
fn lowercamelcase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn lowercamelcase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_lower_camel_case())
|
||||
}
|
||||
|
||||
fn lowercase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn lowercase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_lowercase())
|
||||
}
|
||||
|
||||
fn module_directory(context: Context) -> FunctionResult {
|
||||
fn module_directory(context: Context) -> Result<String, String> {
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.justfile
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join(context.evaluator.context.module_source)
|
||||
.join(context.evaluator.module_source)
|
||||
.parent()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
@ -458,61 +423,53 @@ fn module_directory(context: Context) -> FunctionResult {
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"Module directory is not valid unicode: {}",
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.module_source
|
||||
.parent()
|
||||
.unwrap()
|
||||
.display(),
|
||||
context.evaluator.module_source.parent().unwrap().display(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn module_file(context: Context) -> FunctionResult {
|
||||
fn module_file(context: Context) -> Result<String, String> {
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.justfile
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join(context.evaluator.context.module_source)
|
||||
.join(context.evaluator.module_source)
|
||||
.to_str()
|
||||
.map(str::to_owned)
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"Module file path is not valid unicode: {}",
|
||||
context.evaluator.context.module_source.display(),
|
||||
context.evaluator.module_source.display(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn num_cpus(_context: Context) -> FunctionResult {
|
||||
fn num_cpus(_context: Context) -> Result<String, String> {
|
||||
let num = num_cpus::get();
|
||||
Ok(num.to_string())
|
||||
}
|
||||
|
||||
fn os(_context: Context) -> FunctionResult {
|
||||
fn os(_context: Context) -> Result<String, String> {
|
||||
Ok(target::os().to_owned())
|
||||
}
|
||||
|
||||
fn os_family(_context: Context) -> FunctionResult {
|
||||
fn os_family(_context: Context) -> Result<String, String> {
|
||||
Ok(target::family().to_owned())
|
||||
}
|
||||
|
||||
fn parent_directory(_context: Context, path: &str) -> FunctionResult {
|
||||
fn parent_directory(_context: Context, path: &str) -> Result<String, String> {
|
||||
Utf8Path::new(path)
|
||||
.parent()
|
||||
.map(Utf8Path::to_string)
|
||||
.ok_or_else(|| format!("Could not extract parent directory from `{path}`"))
|
||||
}
|
||||
|
||||
fn path_exists(context: Context, path: &str) -> FunctionResult {
|
||||
fn path_exists(context: Context, path: &str) -> Result<String, String> {
|
||||
Ok(
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.working_directory
|
||||
.join(path)
|
||||
@ -521,15 +478,20 @@ fn path_exists(context: Context, path: &str) -> FunctionResult {
|
||||
)
|
||||
}
|
||||
|
||||
fn quote(_context: Context, s: &str) -> FunctionResult {
|
||||
fn quote(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(format!("'{}'", s.replace('\'', "'\\''")))
|
||||
}
|
||||
|
||||
fn replace(_context: Context, s: &str, from: &str, to: &str) -> FunctionResult {
|
||||
fn replace(_context: Context, s: &str, from: &str, to: &str) -> Result<String, String> {
|
||||
Ok(s.replace(from, to))
|
||||
}
|
||||
|
||||
fn replace_regex(_context: Context, s: &str, regex: &str, replacement: &str) -> FunctionResult {
|
||||
fn replace_regex(
|
||||
_context: Context,
|
||||
s: &str,
|
||||
regex: &str,
|
||||
replacement: &str,
|
||||
) -> Result<String, String> {
|
||||
Ok(
|
||||
Regex::new(regex)
|
||||
.map_err(|err| err.to_string())?
|
||||
@ -538,7 +500,7 @@ fn replace_regex(_context: Context, s: &str, regex: &str, replacement: &str) ->
|
||||
)
|
||||
}
|
||||
|
||||
fn sha256(_context: Context, s: &str) -> FunctionResult {
|
||||
fn sha256(_context: Context, s: &str) -> Result<String, String> {
|
||||
use sha2::{Digest, Sha256};
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(s);
|
||||
@ -546,14 +508,9 @@ fn sha256(_context: Context, s: &str) -> FunctionResult {
|
||||
Ok(format!("{hash:x}"))
|
||||
}
|
||||
|
||||
fn sha256_file(context: Context, path: &str) -> FunctionResult {
|
||||
fn sha256_file(context: Context, path: &str) -> Result<String, String> {
|
||||
use sha2::{Digest, Sha256};
|
||||
let path = context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.working_directory
|
||||
.join(path);
|
||||
let path = context.evaluator.search.working_directory.join(path);
|
||||
let mut hasher = Sha256::new();
|
||||
let mut file =
|
||||
fs::File::open(&path).map_err(|err| format!("Failed to open `{}`: {err}", path.display()))?;
|
||||
@ -563,7 +520,7 @@ fn sha256_file(context: Context, path: &str) -> FunctionResult {
|
||||
Ok(format!("{hash:x}"))
|
||||
}
|
||||
|
||||
fn shell(context: Context, command: &str, args: &[String]) -> FunctionResult {
|
||||
fn shell(context: Context, command: &str, args: &[String]) -> Result<String, String> {
|
||||
let args = iter::once(command)
|
||||
.chain(args.iter().map(String::as_str))
|
||||
.collect::<Vec<&str>>();
|
||||
@ -574,22 +531,21 @@ fn shell(context: Context, command: &str, args: &[String]) -> FunctionResult {
|
||||
.map_err(|output_error| output_error.to_string())
|
||||
}
|
||||
|
||||
fn shoutykebabcase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn shoutykebabcase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_shouty_kebab_case())
|
||||
}
|
||||
|
||||
fn shoutysnakecase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn shoutysnakecase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_shouty_snake_case())
|
||||
}
|
||||
|
||||
fn snakecase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn snakecase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_snake_case())
|
||||
}
|
||||
|
||||
fn source_directory(context: Context) -> FunctionResult {
|
||||
fn source_directory(context: Context) -> Result<String, String> {
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.justfile
|
||||
.parent()
|
||||
@ -607,10 +563,9 @@ fn source_directory(context: Context) -> FunctionResult {
|
||||
})
|
||||
}
|
||||
|
||||
fn source_file(context: Context) -> FunctionResult {
|
||||
fn source_file(context: Context) -> Result<String, String> {
|
||||
context
|
||||
.evaluator
|
||||
.context
|
||||
.search
|
||||
.justfile
|
||||
.parent()
|
||||
@ -626,51 +581,51 @@ fn source_file(context: Context) -> FunctionResult {
|
||||
})
|
||||
}
|
||||
|
||||
fn titlecase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn titlecase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_title_case())
|
||||
}
|
||||
|
||||
fn trim(_context: Context, s: &str) -> FunctionResult {
|
||||
fn trim(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.trim().to_owned())
|
||||
}
|
||||
|
||||
fn trim_end(_context: Context, s: &str) -> FunctionResult {
|
||||
fn trim_end(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.trim_end().to_owned())
|
||||
}
|
||||
|
||||
fn trim_end_match(_context: Context, s: &str, pat: &str) -> FunctionResult {
|
||||
fn trim_end_match(_context: Context, s: &str, pat: &str) -> Result<String, String> {
|
||||
Ok(s.strip_suffix(pat).unwrap_or(s).to_owned())
|
||||
}
|
||||
|
||||
fn trim_end_matches(_context: Context, s: &str, pat: &str) -> FunctionResult {
|
||||
fn trim_end_matches(_context: Context, s: &str, pat: &str) -> Result<String, String> {
|
||||
Ok(s.trim_end_matches(pat).to_owned())
|
||||
}
|
||||
|
||||
fn trim_start(_context: Context, s: &str) -> FunctionResult {
|
||||
fn trim_start(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.trim_start().to_owned())
|
||||
}
|
||||
|
||||
fn trim_start_match(_context: Context, s: &str, pat: &str) -> FunctionResult {
|
||||
fn trim_start_match(_context: Context, s: &str, pat: &str) -> Result<String, String> {
|
||||
Ok(s.strip_prefix(pat).unwrap_or(s).to_owned())
|
||||
}
|
||||
|
||||
fn trim_start_matches(_context: Context, s: &str, pat: &str) -> FunctionResult {
|
||||
fn trim_start_matches(_context: Context, s: &str, pat: &str) -> Result<String, String> {
|
||||
Ok(s.trim_start_matches(pat).to_owned())
|
||||
}
|
||||
|
||||
fn uppercamelcase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn uppercamelcase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_upper_camel_case())
|
||||
}
|
||||
|
||||
fn uppercase(_context: Context, s: &str) -> FunctionResult {
|
||||
fn uppercase(_context: Context, s: &str) -> Result<String, String> {
|
||||
Ok(s.to_uppercase())
|
||||
}
|
||||
|
||||
fn uuid(_context: Context) -> FunctionResult {
|
||||
fn uuid(_context: Context) -> Result<String, String> {
|
||||
Ok(uuid::Uuid::new_v4().to_string())
|
||||
}
|
||||
|
||||
fn without_extension(_context: Context, path: &str) -> FunctionResult {
|
||||
fn without_extension(_context: Context, path: &str) -> Result<String, String> {
|
||||
let parent = Utf8Path::new(path)
|
||||
.parent()
|
||||
.ok_or_else(|| format!("Could not extract parent from `{path}`"))?;
|
||||
@ -684,7 +639,7 @@ fn without_extension(_context: Context, path: &str) -> FunctionResult {
|
||||
|
||||
/// Check whether a string processes properly as semver (e.x. "0.1.0")
|
||||
/// and matches a given semver requirement (e.x. ">=0.1.0")
|
||||
fn semver_matches(_context: Context, version: &str, requirement: &str) -> FunctionResult {
|
||||
fn semver_matches(_context: Context, version: &str, requirement: &str) -> Result<String, String> {
|
||||
Ok(
|
||||
requirement
|
||||
.parse::<VersionReq>()
|
||||
|
@ -20,9 +20,6 @@ pub(crate) enum Item<'src> {
|
||||
},
|
||||
Recipe(UnresolvedRecipe<'src>),
|
||||
Set(Set<'src>),
|
||||
Unexport {
|
||||
name: Name<'src>,
|
||||
},
|
||||
}
|
||||
|
||||
impl<'src> Display for Item<'src> {
|
||||
@ -64,7 +61,6 @@ impl<'src> Display for Item<'src> {
|
||||
}
|
||||
Self::Recipe(recipe) => write!(f, "{}", recipe.color_display(Color::never())),
|
||||
Self::Set(set) => write!(f, "{set}"),
|
||||
Self::Unexport { name } => write!(f, "unexport {name}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
339
src/justfile.rs
339
src/justfile.rs
@ -24,7 +24,6 @@ pub(crate) struct Justfile<'src> {
|
||||
pub(crate) settings: Settings<'src>,
|
||||
#[serde(skip)]
|
||||
pub(crate) source: PathBuf,
|
||||
pub(crate) unexports: HashSet<String>,
|
||||
pub(crate) warnings: Vec<Warning>,
|
||||
}
|
||||
|
||||
@ -78,6 +77,45 @@ impl<'src> Justfile<'src> {
|
||||
.next()
|
||||
}
|
||||
|
||||
fn scope<'run>(
|
||||
&'run self,
|
||||
config: &'run Config,
|
||||
dotenv: &'run BTreeMap<String, String>,
|
||||
search: &'run Search,
|
||||
overrides: &BTreeMap<String, String>,
|
||||
parent: &'run Scope<'src, 'run>,
|
||||
) -> RunResult<'src, Scope<'src, 'run>>
|
||||
where
|
||||
'src: 'run,
|
||||
{
|
||||
let mut scope = parent.child();
|
||||
let mut unknown_overrides = Vec::new();
|
||||
|
||||
for (name, value) in overrides {
|
||||
if let Some(assignment) = self.assignments.get(name) {
|
||||
scope.bind(assignment.export, assignment.name, value.clone());
|
||||
} else {
|
||||
unknown_overrides.push(name.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if !unknown_overrides.is_empty() {
|
||||
return Err(Error::UnknownOverrides {
|
||||
overrides: unknown_overrides,
|
||||
});
|
||||
}
|
||||
|
||||
Evaluator::evaluate_assignments(
|
||||
&self.assignments,
|
||||
config,
|
||||
dotenv,
|
||||
&self.source,
|
||||
scope,
|
||||
search,
|
||||
&self.settings,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn run(
|
||||
&self,
|
||||
config: &Config,
|
||||
@ -105,7 +143,7 @@ impl<'src> Justfile<'src> {
|
||||
|
||||
let root = Scope::root();
|
||||
|
||||
let scope = Evaluator::evaluate_assignments(config, &dotenv, self, overrides, &root, search)?;
|
||||
let scope = self.scope(config, &dotenv, search, overrides, &root)?;
|
||||
|
||||
match &config.subcommand {
|
||||
Subcommand::Command {
|
||||
@ -125,7 +163,7 @@ impl<'src> Justfile<'src> {
|
||||
|
||||
let scope = scope.child();
|
||||
|
||||
command.export(&self.settings, &dotenv, &scope, &self.unexports);
|
||||
command.export(&self.settings, &dotenv, &scope);
|
||||
|
||||
let status = InterruptHandler::guard(|| command.status()).map_err(|io_error| {
|
||||
Error::CommandInvoke {
|
||||
@ -156,7 +194,11 @@ impl<'src> Justfile<'src> {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let width = scope.names().fold(0, |max, name| name.len().max(max));
|
||||
let mut width = 0;
|
||||
|
||||
for name in scope.names() {
|
||||
width = cmp::max(name.len(), width);
|
||||
}
|
||||
|
||||
for binding in scope.bindings() {
|
||||
println!(
|
||||
@ -173,38 +215,77 @@ impl<'src> Justfile<'src> {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let arguments = arguments.iter().map(String::as_str).collect::<Vec<&str>>();
|
||||
let mut remaining: Vec<&str> = if !arguments.is_empty() {
|
||||
arguments.iter().map(String::as_str).collect()
|
||||
} else if let Some(recipe) = &self.default {
|
||||
recipe.check_can_be_default_recipe()?;
|
||||
vec![recipe.name()]
|
||||
} else if self.recipes.is_empty() {
|
||||
return Err(Error::NoRecipes);
|
||||
} else {
|
||||
return Err(Error::NoDefaultRecipe);
|
||||
};
|
||||
|
||||
let groups = ArgumentParser::parse_arguments(self, &arguments)?;
|
||||
|
||||
let arena: Arena<Scope> = Arena::new();
|
||||
let mut invocations = Vec::<Invocation>::new();
|
||||
let mut missing = Vec::new();
|
||||
let mut invocations = Vec::new();
|
||||
let mut scopes = BTreeMap::new();
|
||||
let arena: Arena<Scope> = Arena::new();
|
||||
|
||||
for group in &groups {
|
||||
invocations.push(self.invocation(
|
||||
while let Some(first) = remaining.first().copied() {
|
||||
if first.contains("::")
|
||||
&& !(first.starts_with(':') || first.ends_with(':') || first.contains(":::"))
|
||||
{
|
||||
remaining = first
|
||||
.split("::")
|
||||
.chain(remaining[1..].iter().copied())
|
||||
.collect();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
let rest = &remaining[1..];
|
||||
|
||||
if let Some((invocation, consumed)) = self.invocation(
|
||||
0,
|
||||
&mut Vec::new(),
|
||||
&arena,
|
||||
&group.arguments,
|
||||
&mut scopes,
|
||||
config,
|
||||
&dotenv,
|
||||
&scope,
|
||||
&group.path,
|
||||
0,
|
||||
&mut scopes,
|
||||
search,
|
||||
)?);
|
||||
&scope,
|
||||
first,
|
||||
rest,
|
||||
)? {
|
||||
remaining = rest[consumed..].to_vec();
|
||||
invocations.push(invocation);
|
||||
} else {
|
||||
missing.push(first.to_string());
|
||||
remaining = rest.to_vec();
|
||||
}
|
||||
}
|
||||
|
||||
if !missing.is_empty() {
|
||||
let suggestion = if missing.len() == 1 {
|
||||
self.suggest_recipe(missing.first().unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return Err(Error::UnknownRecipes {
|
||||
recipes: missing,
|
||||
suggestion,
|
||||
});
|
||||
}
|
||||
|
||||
let mut ran = Ran::default();
|
||||
for invocation in invocations {
|
||||
let context = ExecutionContext {
|
||||
let context = RecipeContext {
|
||||
config,
|
||||
dotenv: &dotenv,
|
||||
module_source: invocation.module_source,
|
||||
scope: invocation.scope,
|
||||
search,
|
||||
settings: invocation.settings,
|
||||
unexports: &self.unexports,
|
||||
};
|
||||
|
||||
Self::run_recipe(
|
||||
@ -217,7 +298,7 @@ impl<'src> Justfile<'src> {
|
||||
&context,
|
||||
&mut ran,
|
||||
invocation.recipe,
|
||||
false,
|
||||
search,
|
||||
)?;
|
||||
}
|
||||
|
||||
@ -238,55 +319,95 @@ impl<'src> Justfile<'src> {
|
||||
|
||||
fn invocation<'run>(
|
||||
&'run self,
|
||||
depth: usize,
|
||||
path: &mut Vec<&'run str>,
|
||||
arena: &'run Arena<Scope<'src, 'run>>,
|
||||
arguments: &[&'run str],
|
||||
scopes: &mut BTreeMap<Vec<&'run str>, &'run Scope<'src, 'run>>,
|
||||
config: &'run Config,
|
||||
dotenv: &'run BTreeMap<String, String>,
|
||||
parent: &'run Scope<'src, 'run>,
|
||||
path: &'run [String],
|
||||
position: usize,
|
||||
scopes: &mut BTreeMap<&'run [String], &'run Scope<'src, 'run>>,
|
||||
search: &'run Search,
|
||||
) -> RunResult<'src, Invocation<'src, 'run>> {
|
||||
if position + 1 == path.len() {
|
||||
let recipe = self.get_recipe(&path[position]).unwrap();
|
||||
Ok(Invocation {
|
||||
recipe,
|
||||
module_source: &self.source,
|
||||
arguments: arguments.into(),
|
||||
settings: &self.settings,
|
||||
scope: parent,
|
||||
})
|
||||
} else {
|
||||
let module = self.modules.get(&path[position]).unwrap();
|
||||
parent: &'run Scope<'src, 'run>,
|
||||
first: &'run str,
|
||||
rest: &[&'run str],
|
||||
) -> RunResult<'src, Option<(Invocation<'src, 'run>, usize)>> {
|
||||
if let Some(module) = self.modules.get(first) {
|
||||
path.push(first);
|
||||
|
||||
let scope = if let Some(scope) = scopes.get(&path[..position]) {
|
||||
let scope = if let Some(scope) = scopes.get(path) {
|
||||
scope
|
||||
} else {
|
||||
let scope = Evaluator::evaluate_assignments(
|
||||
config,
|
||||
dotenv,
|
||||
module,
|
||||
&BTreeMap::new(),
|
||||
parent,
|
||||
search,
|
||||
)?;
|
||||
let scope = module.scope(config, dotenv, search, &BTreeMap::new(), parent)?;
|
||||
let scope = arena.alloc(scope);
|
||||
scopes.insert(path, scope);
|
||||
scopes.insert(path.clone(), scope);
|
||||
scopes.get(path).unwrap()
|
||||
};
|
||||
|
||||
module.invocation(
|
||||
arena,
|
||||
arguments,
|
||||
config,
|
||||
dotenv,
|
||||
scope,
|
||||
path,
|
||||
position + 1,
|
||||
scopes,
|
||||
search,
|
||||
)
|
||||
if rest.is_empty() {
|
||||
if let Some(recipe) = &module.default {
|
||||
recipe.check_can_be_default_recipe()?;
|
||||
return Ok(Some((
|
||||
Invocation {
|
||||
settings: &module.settings,
|
||||
recipe,
|
||||
arguments: Vec::new(),
|
||||
scope,
|
||||
module_source: &self.source,
|
||||
},
|
||||
depth,
|
||||
)));
|
||||
}
|
||||
Err(Error::NoDefaultRecipe)
|
||||
} else {
|
||||
module.invocation(
|
||||
depth + 1,
|
||||
path,
|
||||
arena,
|
||||
scopes,
|
||||
config,
|
||||
dotenv,
|
||||
search,
|
||||
scope,
|
||||
rest[0],
|
||||
&rest[1..],
|
||||
)
|
||||
}
|
||||
} else if let Some(recipe) = self.get_recipe(first) {
|
||||
if recipe.parameters.is_empty() {
|
||||
Ok(Some((
|
||||
Invocation {
|
||||
arguments: Vec::new(),
|
||||
recipe,
|
||||
scope: parent,
|
||||
settings: &self.settings,
|
||||
module_source: &self.source,
|
||||
},
|
||||
depth,
|
||||
)))
|
||||
} else {
|
||||
let argument_range = recipe.argument_range();
|
||||
let argument_count = cmp::min(rest.len(), recipe.max_arguments());
|
||||
if !argument_range.range_contains(&argument_count) {
|
||||
return Err(Error::ArgumentCountMismatch {
|
||||
recipe: recipe.name(),
|
||||
parameters: recipe.parameters.clone(),
|
||||
found: rest.len(),
|
||||
min: recipe.min_arguments(),
|
||||
max: recipe.max_arguments(),
|
||||
});
|
||||
}
|
||||
Ok(Some((
|
||||
Invocation {
|
||||
arguments: rest[..argument_count].to_vec(),
|
||||
recipe,
|
||||
scope: parent,
|
||||
settings: &self.settings,
|
||||
module_source: &self.source,
|
||||
},
|
||||
depth + argument_count,
|
||||
)))
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,10 +417,10 @@ impl<'src> Justfile<'src> {
|
||||
|
||||
fn run_recipe(
|
||||
arguments: &[String],
|
||||
context: &ExecutionContext<'src, '_>,
|
||||
context: &RecipeContext<'src, '_>,
|
||||
ran: &mut Ran<'src>,
|
||||
recipe: &Recipe<'src>,
|
||||
is_dependency: bool,
|
||||
search: &Search,
|
||||
) -> RunResult<'src> {
|
||||
if ran.has_run(&recipe.namepath, arguments) {
|
||||
return Ok(());
|
||||
@ -311,12 +432,27 @@ impl<'src> Justfile<'src> {
|
||||
});
|
||||
}
|
||||
|
||||
let (outer, positional) =
|
||||
Evaluator::evaluate_parameters(context, is_dependency, arguments, &recipe.parameters)?;
|
||||
let (outer, positional) = Evaluator::evaluate_parameters(
|
||||
arguments,
|
||||
context.config,
|
||||
context.dotenv,
|
||||
context.module_source,
|
||||
&recipe.parameters,
|
||||
context.scope,
|
||||
search,
|
||||
context.settings,
|
||||
)?;
|
||||
|
||||
let scope = outer.child();
|
||||
|
||||
let mut evaluator = Evaluator::new(context, true, &scope);
|
||||
let mut evaluator = Evaluator::recipe_evaluator(
|
||||
context.config,
|
||||
context.dotenv,
|
||||
context.module_source,
|
||||
&scope,
|
||||
search,
|
||||
context.settings,
|
||||
);
|
||||
|
||||
if !context.config.no_dependencies {
|
||||
for Dependency { recipe, arguments } in recipe.dependencies.iter().take(recipe.priors) {
|
||||
@ -325,11 +461,11 @@ impl<'src> Justfile<'src> {
|
||||
.map(|argument| evaluator.evaluate_expression(argument))
|
||||
.collect::<RunResult<Vec<String>>>()?;
|
||||
|
||||
Self::run_recipe(&arguments, context, ran, recipe, true)?;
|
||||
Self::run_recipe(&arguments, context, ran, recipe, search)?;
|
||||
}
|
||||
}
|
||||
|
||||
recipe.run(context, &scope, &positional, is_dependency)?;
|
||||
recipe.run(context, &scope, &positional)?;
|
||||
|
||||
if !context.config.no_dependencies {
|
||||
let mut ran = Ran::default();
|
||||
@ -341,7 +477,7 @@ impl<'src> Justfile<'src> {
|
||||
evaluated.push(evaluator.evaluate_expression(argument)?);
|
||||
}
|
||||
|
||||
Self::run_recipe(&evaluated, context, &mut ran, recipe, true)?;
|
||||
Self::run_recipe(&evaluated, context, &mut ran, recipe, search)?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -365,13 +501,13 @@ impl<'src> Justfile<'src> {
|
||||
modules
|
||||
}
|
||||
|
||||
pub(crate) fn public_recipes(&self, config: &Config) -> Vec<&Recipe> {
|
||||
pub(crate) fn public_recipes(&self, config: &Config) -> Vec<&Recipe<'src, Dependency>> {
|
||||
let mut recipes = self
|
||||
.recipes
|
||||
.values()
|
||||
.map(AsRef::as_ref)
|
||||
.filter(|recipe| recipe.is_public())
|
||||
.collect::<Vec<&Recipe>>();
|
||||
.collect::<Vec<&Recipe<Dependency>>>();
|
||||
|
||||
if config.unsorted {
|
||||
recipes.sort_by_key(|recipe| (&recipe.import_offsets, recipe.name.offset));
|
||||
@ -380,33 +516,19 @@ impl<'src> Justfile<'src> {
|
||||
recipes
|
||||
}
|
||||
|
||||
pub(crate) fn public_groups(&self, config: &Config) -> Vec<String> {
|
||||
let mut groups = Vec::new();
|
||||
|
||||
for recipe in self.recipes.values() {
|
||||
if recipe.is_public() {
|
||||
for group in recipe.groups() {
|
||||
groups.push((&recipe.import_offsets, recipe.name.offset, group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if config.unsorted {
|
||||
groups.sort();
|
||||
} else {
|
||||
groups.sort_by(|(_, _, a), (_, _, b)| a.cmp(b));
|
||||
}
|
||||
|
||||
let mut seen = HashSet::new();
|
||||
|
||||
groups.retain(|(_, _, group)| seen.insert(group.clone()));
|
||||
|
||||
groups.into_iter().map(|(_, _, group)| group).collect()
|
||||
pub(crate) fn public_groups(&self) -> BTreeSet<String> {
|
||||
self
|
||||
.recipes
|
||||
.values()
|
||||
.map(AsRef::as_ref)
|
||||
.filter(|recipe| recipe.is_public())
|
||||
.flat_map(Recipe::groups)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'src> ColorDisplay for Justfile<'src> {
|
||||
fn fmt(&self, f: &mut Formatter, color: Color) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter, color: Color) -> Result<(), fmt::Error> {
|
||||
let mut items = self.recipes.len() + self.assignments.len() + self.aliases.len();
|
||||
for (name, assignment) in &self.assignments {
|
||||
if assignment.export {
|
||||
@ -450,38 +572,21 @@ mod tests {
|
||||
use Error::*;
|
||||
|
||||
run_error! {
|
||||
name: unknown_recipe_no_suggestion,
|
||||
name: unknown_recipes,
|
||||
src: "a:\nb:\nc:",
|
||||
args: ["a", "xyz", "y", "z"],
|
||||
error: UnknownRecipe {
|
||||
recipe,
|
||||
args: ["a", "x", "y", "z"],
|
||||
error: UnknownRecipes {
|
||||
recipes,
|
||||
suggestion,
|
||||
},
|
||||
check: {
|
||||
assert_eq!(recipe, "xyz");
|
||||
assert_eq!(recipes, &["x", "y", "z"]);
|
||||
assert_eq!(suggestion, None);
|
||||
}
|
||||
}
|
||||
|
||||
run_error! {
|
||||
name: unknown_recipe_with_suggestion,
|
||||
src: "a:\nb:\nc:",
|
||||
args: ["a", "x", "y", "z"],
|
||||
error: UnknownRecipe {
|
||||
recipe,
|
||||
suggestion,
|
||||
},
|
||||
check: {
|
||||
assert_eq!(recipe, "x");
|
||||
assert_eq!(suggestion, Some(Suggestion {
|
||||
name: "a",
|
||||
target: None,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
run_error! {
|
||||
name: unknown_recipe_show_alias_suggestion,
|
||||
name: unknown_recipes_show_alias_suggestion,
|
||||
src: "
|
||||
foo:
|
||||
echo foo
|
||||
@ -489,12 +594,12 @@ mod tests {
|
||||
alias z := foo
|
||||
",
|
||||
args: ["zz"],
|
||||
error: UnknownRecipe {
|
||||
recipe,
|
||||
error: UnknownRecipes {
|
||||
recipes,
|
||||
suggestion,
|
||||
},
|
||||
check: {
|
||||
assert_eq!(recipe, "zz");
|
||||
assert_eq!(recipes, &["zz"]);
|
||||
assert_eq!(suggestion, Some(Suggestion {
|
||||
name: "z",
|
||||
target: Some("foo"),
|
||||
|
@ -10,7 +10,6 @@ pub(crate) enum Keyword {
|
||||
DotenvFilename,
|
||||
DotenvLoad,
|
||||
DotenvPath,
|
||||
DotenvRequired,
|
||||
Else,
|
||||
Export,
|
||||
Fallback,
|
||||
@ -25,7 +24,6 @@ pub(crate) enum Keyword {
|
||||
Shell,
|
||||
Tempdir,
|
||||
True,
|
||||
Unexport,
|
||||
WindowsPowershell,
|
||||
WindowsShell,
|
||||
X,
|
||||
|
73
src/lib.rs
73
src/lib.rs
@ -13,29 +13,23 @@
|
||||
overlapping_range_endpoints
|
||||
)]
|
||||
|
||||
//! `just` is primarily used as a command-line binary, but does provide a
|
||||
//! limited public library interface.
|
||||
//!
|
||||
//! Please keep in mind that there are no semantic version guarantees for the
|
||||
//! library interface. It may break or change at any time.
|
||||
|
||||
pub(crate) use {
|
||||
crate::{
|
||||
alias::Alias, analyzer::Analyzer, argument_parser::ArgumentParser, assignment::Assignment,
|
||||
alias::Alias, analyzer::Analyzer, assignment::Assignment,
|
||||
assignment_resolver::AssignmentResolver, ast::Ast, attribute::Attribute, binding::Binding,
|
||||
color::Color, color_display::ColorDisplay, command_ext::CommandExt, compilation::Compilation,
|
||||
compile_error::CompileError, compile_error_kind::CompileErrorKind, compiler::Compiler,
|
||||
condition::Condition, conditional_operator::ConditionalOperator, config::Config,
|
||||
config_error::ConfigError, constants::constants, count::Count, delimiter::Delimiter,
|
||||
dependency::Dependency, dump_format::DumpFormat, enclosure::Enclosure, error::Error,
|
||||
evaluator::Evaluator, execution_context::ExecutionContext, expression::Expression,
|
||||
fragment::Fragment, function::Function, interrupt_guard::InterruptGuard,
|
||||
interrupt_handler::InterruptHandler, item::Item, justfile::Justfile, keyed::Keyed,
|
||||
keyword::Keyword, lexer::Lexer, line::Line, list::List, load_dotenv::load_dotenv,
|
||||
loader::Loader, module_path::ModulePath, name::Name, namepath::Namepath, ordinal::Ordinal,
|
||||
output::output, output_error::OutputError, parameter::Parameter, parameter_kind::ParameterKind,
|
||||
parser::Parser, platform::Platform, platform_interface::PlatformInterface, position::Position,
|
||||
positional::Positional, ran::Ran, range_ext::RangeExt, recipe::Recipe,
|
||||
evaluator::Evaluator, expression::Expression, fragment::Fragment, function::Function,
|
||||
interrupt_guard::InterruptGuard, interrupt_handler::InterruptHandler, item::Item,
|
||||
justfile::Justfile, keyed::Keyed, keyword::Keyword, lexer::Lexer, line::Line, list::List,
|
||||
load_dotenv::load_dotenv, loader::Loader, module_path::ModulePath, name::Name,
|
||||
namepath::Namepath, ordinal::Ordinal, output::output, output_error::OutputError,
|
||||
parameter::Parameter, parameter_kind::ParameterKind, parser::Parser, platform::Platform,
|
||||
platform_interface::PlatformInterface, position::Position, positional::Positional, ran::Ran,
|
||||
range_ext::RangeExt, recipe::Recipe, recipe_context::RecipeContext,
|
||||
recipe_resolver::RecipeResolver, recipe_signature::RecipeSignature, scope::Scope,
|
||||
search::Search, search_config::SearchConfig, search_error::SearchError, set::Set,
|
||||
setting::Setting, settings::Settings, shebang::Shebang, shell::Shell,
|
||||
@ -45,27 +39,15 @@ pub(crate) use {
|
||||
unresolved_recipe::UnresolvedRecipe, use_color::UseColor, variables::Variables,
|
||||
verbosity::Verbosity, warning::Warning,
|
||||
},
|
||||
camino::Utf8Path,
|
||||
derivative::Derivative,
|
||||
edit_distance::edit_distance,
|
||||
lexiclean::Lexiclean,
|
||||
libc::EXIT_FAILURE,
|
||||
log::{info, warn},
|
||||
regex::Regex,
|
||||
serde::{
|
||||
ser::{SerializeMap, SerializeSeq},
|
||||
Serialize, Serializer,
|
||||
},
|
||||
snafu::{ResultExt, Snafu},
|
||||
std::{
|
||||
borrow::Cow,
|
||||
cmp,
|
||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
collections::{BTreeMap, BTreeSet, HashMap},
|
||||
env,
|
||||
ffi::OsString,
|
||||
fmt::{self, Debug, Display, Formatter},
|
||||
fs,
|
||||
io::{self, Read, Seek, Write},
|
||||
io::{self, Write},
|
||||
iter::{self, FromIterator},
|
||||
mem,
|
||||
ops::Deref,
|
||||
@ -77,10 +59,23 @@ pub(crate) use {
|
||||
sync::{Mutex, MutexGuard, OnceLock},
|
||||
vec,
|
||||
},
|
||||
strum::{Display, EnumDiscriminants, EnumString, IntoStaticStr},
|
||||
tempfile::tempfile,
|
||||
typed_arena::Arena,
|
||||
unicode_width::{UnicodeWidthChar, UnicodeWidthStr},
|
||||
{
|
||||
camino::Utf8Path,
|
||||
derivative::Derivative,
|
||||
edit_distance::edit_distance,
|
||||
lexiclean::Lexiclean,
|
||||
libc::EXIT_FAILURE,
|
||||
log::{info, warn},
|
||||
regex::Regex,
|
||||
serde::{
|
||||
ser::{SerializeMap, SerializeSeq},
|
||||
Serialize, Serializer,
|
||||
},
|
||||
snafu::{ResultExt, Snafu},
|
||||
strum::{Display, EnumDiscriminants, EnumString, IntoStaticStr},
|
||||
typed_arena::Arena,
|
||||
unicode_width::{UnicodeWidthChar, UnicodeWidthStr},
|
||||
},
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
@ -92,11 +87,10 @@ pub use crate::run::run;
|
||||
#[doc(hidden)]
|
||||
pub use unindent::unindent;
|
||||
|
||||
type CompileResult<'a, T = ()> = Result<T, CompileError<'a>>;
|
||||
type ConfigResult<T> = Result<T, ConfigError>;
|
||||
type FunctionResult = Result<String, String>;
|
||||
type RunResult<'a, T = ()> = Result<T, Error<'a>>;
|
||||
type SearchResult<T> = Result<T, SearchError>;
|
||||
pub(crate) type CompileResult<'a, T = ()> = Result<T, CompileError<'a>>;
|
||||
pub(crate) type ConfigResult<T> = Result<T, ConfigError>;
|
||||
pub(crate) type RunResult<'a, T = ()> = Result<T, Error<'a>>;
|
||||
pub(crate) type SearchResult<T> = Result<T, SearchError>;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
@ -120,7 +114,6 @@ pub mod summary;
|
||||
|
||||
mod alias;
|
||||
mod analyzer;
|
||||
mod argument_parser;
|
||||
mod assignment;
|
||||
mod assignment_resolver;
|
||||
mod ast;
|
||||
@ -146,7 +139,6 @@ mod dump_format;
|
||||
mod enclosure;
|
||||
mod error;
|
||||
mod evaluator;
|
||||
mod execution_context;
|
||||
mod expression;
|
||||
mod fragment;
|
||||
mod function;
|
||||
@ -177,6 +169,7 @@ mod positional;
|
||||
mod ran;
|
||||
mod range_ext;
|
||||
mod recipe;
|
||||
mod recipe_context;
|
||||
mod recipe_resolver;
|
||||
mod recipe_signature;
|
||||
mod run;
|
||||
|
@ -1,5 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
const DEFAULT_DOTENV_FILENAME: &str = ".env";
|
||||
|
||||
pub(crate) fn load_dotenv(
|
||||
config: &Config,
|
||||
settings: &Settings,
|
||||
@ -15,22 +17,16 @@ pub(crate) fn load_dotenv(
|
||||
.as_ref()
|
||||
.or(settings.dotenv_path.as_ref());
|
||||
|
||||
if !settings.dotenv_load
|
||||
&& dotenv_filename.is_none()
|
||||
&& dotenv_path.is_none()
|
||||
&& !settings.dotenv_required
|
||||
if !settings.dotenv_load.unwrap_or_default() && dotenv_filename.is_none() && dotenv_path.is_none()
|
||||
{
|
||||
return Ok(BTreeMap::new());
|
||||
}
|
||||
|
||||
if let Some(path) = dotenv_path {
|
||||
let path = working_directory.join(path);
|
||||
if path.is_file() {
|
||||
return load_from_file(&path);
|
||||
}
|
||||
return load_from_file(&working_directory.join(path));
|
||||
}
|
||||
|
||||
let filename = dotenv_filename.map_or(".env", |s| s.as_str());
|
||||
let filename = dotenv_filename.map_or(DEFAULT_DOTENV_FILENAME, |s| s.as_str());
|
||||
|
||||
for directory in working_directory.ancestors() {
|
||||
let path = directory.join(filename);
|
||||
@ -39,11 +35,7 @@ pub(crate) fn load_dotenv(
|
||||
}
|
||||
}
|
||||
|
||||
if settings.dotenv_required {
|
||||
Err(Error::DotenvRequired)
|
||||
} else {
|
||||
Ok(BTreeMap::new())
|
||||
}
|
||||
Ok(BTreeMap::new())
|
||||
}
|
||||
|
||||
fn load_from_file(path: &Path) -> RunResult<'static, BTreeMap<String, String>> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn main() {
|
||||
if let Err(code) = just::run(std::env::args_os()) {
|
||||
if let Err(code) = just::run() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,6 @@ impl<'src> Namepath<'src> {
|
||||
pub(crate) fn join(&self, name: Name<'src>) -> Self {
|
||||
Self(self.0.iter().copied().chain(iter::once(name)).collect())
|
||||
}
|
||||
|
||||
pub(crate) fn spaced(&self) -> ModulePath {
|
||||
ModulePath {
|
||||
path: self.0.iter().map(|name| name.lexeme().into()).collect(),
|
||||
spaced: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'src> Display for Namepath<'src> {
|
||||
|
@ -54,11 +54,6 @@ impl<'src> Node<'src> for Item<'src> {
|
||||
}
|
||||
Self::Recipe(recipe) => recipe.tree(),
|
||||
Self::Set(set) => set.tree(),
|
||||
Self::Unexport { name } => {
|
||||
let mut unexport = Tree::atom(Keyword::Unexport.lexeme());
|
||||
unexport.push_mut(name.lexeme().replace('-', "_"));
|
||||
unexport
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -289,7 +284,6 @@ impl<'src> Node<'src> for Set<'src> {
|
||||
Setting::AllowDuplicateRecipes(value)
|
||||
| Setting::AllowDuplicateVariables(value)
|
||||
| Setting::DotenvLoad(value)
|
||||
| Setting::DotenvRequired(value)
|
||||
| Setting::Export(value)
|
||||
| Setting::Fallback(value)
|
||||
| Setting::PositionalArguments(value)
|
||||
|
@ -15,7 +15,7 @@ pub(crate) enum OutputError {
|
||||
}
|
||||
|
||||
impl Display for OutputError {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
Self::Code(code) => write!(f, "Process exited with status code {code}"),
|
||||
Self::Io(ref io_error) => write!(f, "Error executing process: {io_error}"),
|
||||
|
@ -14,7 +14,7 @@ pub(crate) struct Parameter<'src> {
|
||||
}
|
||||
|
||||
impl<'src> ColorDisplay for Parameter<'src> {
|
||||
fn fmt(&self, f: &mut Formatter, color: Color) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter, color: Color) -> Result<(), fmt::Error> {
|
||||
if let Some(prefix) = self.kind.prefix() {
|
||||
write!(f, "{}", color.annotation().paint(prefix))?;
|
||||
}
|
||||
|
@ -340,15 +340,6 @@ impl<'run, 'src> Parser<'run, 'src> {
|
||||
self.presume_keyword(Keyword::Export)?;
|
||||
items.push(Item::Assignment(self.parse_assignment(true)?));
|
||||
}
|
||||
Some(Keyword::Unexport)
|
||||
if self.next_are(&[Identifier, Identifier, Eof])
|
||||
|| self.next_are(&[Identifier, Identifier, Eol]) =>
|
||||
{
|
||||
self.presume_keyword(Keyword::Unexport)?;
|
||||
let name = self.parse_name()?;
|
||||
self.expect_eol()?;
|
||||
items.push(Item::Unexport { name });
|
||||
}
|
||||
Some(Keyword::Import)
|
||||
if self.next_are(&[Identifier, StringToken])
|
||||
|| self.next_are(&[Identifier, Identifier, StringToken])
|
||||
@ -926,7 +917,6 @@ impl<'run, 'src> Parser<'run, 'src> {
|
||||
Some(Setting::AllowDuplicateVariables(self.parse_set_bool()?))
|
||||
}
|
||||
Keyword::DotenvLoad => Some(Setting::DotenvLoad(self.parse_set_bool()?)),
|
||||
Keyword::DotenvRequired => Some(Setting::DotenvRequired(self.parse_set_bool()?)),
|
||||
Keyword::Export => Some(Setting::Export(self.parse_set_bool()?)),
|
||||
Keyword::Fallback => Some(Setting::Fallback(self.parse_set_bool()?)),
|
||||
Keyword::IgnoreComments => Some(Setting::IgnoreComments(self.parse_set_bool()?)),
|
||||
@ -991,18 +981,15 @@ impl<'run, 'src> Parser<'run, 'src> {
|
||||
loop {
|
||||
let name = self.parse_name()?;
|
||||
|
||||
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()?;
|
||||
let argument = if self.accepted(ParenL)? {
|
||||
let argument = self.parse_string_literal()?;
|
||||
self.expect(ParenR)?;
|
||||
Some(arg)
|
||||
Some(argument)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let attribute = Attribute::new(name, maybe_argument)?;
|
||||
let attribute = Attribute::new(name, argument)?;
|
||||
|
||||
if let Some(line) = attributes.get(&attribute) {
|
||||
return Err(name.error(CompileErrorKind::DuplicateAttribute {
|
||||
@ -1165,18 +1152,6 @@ 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",
|
||||
|
@ -19,7 +19,7 @@ impl PlatformInterface for Platform {
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
fn set_execute_permission(path: &Path) -> io::Result<()> {
|
||||
fn set_execute_permission(path: &Path) -> Result<(), io::Error> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
// get current permissions
|
||||
@ -38,7 +38,7 @@ impl PlatformInterface for Platform {
|
||||
exit_status.signal()
|
||||
}
|
||||
|
||||
fn convert_native_path(_working_directory: &Path, path: &Path) -> FunctionResult {
|
||||
fn convert_native_path(_working_directory: &Path, path: &Path) -> Result<String, String> {
|
||||
path
|
||||
.to_str()
|
||||
.map(str::to_string)
|
||||
@ -85,7 +85,7 @@ impl PlatformInterface for Platform {
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
fn set_execute_permission(_path: &Path) -> io::Result<()> {
|
||||
fn set_execute_permission(_path: &Path) -> Result<(), io::Error> {
|
||||
// it is not necessary to set an execute permission on a script on windows, so
|
||||
// this is a nop
|
||||
Ok(())
|
||||
@ -97,7 +97,7 @@ impl PlatformInterface for Platform {
|
||||
None
|
||||
}
|
||||
|
||||
fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult {
|
||||
fn convert_native_path(working_directory: &Path, path: &Path) -> Result<String, String> {
|
||||
// Translate path from windows style to unix style
|
||||
let mut cygpath = Command::new("cygpath");
|
||||
cygpath.current_dir(working_directory);
|
||||
|
@ -10,12 +10,12 @@ pub(crate) trait PlatformInterface {
|
||||
) -> Result<Command, OutputError>;
|
||||
|
||||
/// Set the execute permission on the file pointed to by `path`
|
||||
fn set_execute_permission(path: &Path) -> io::Result<()>;
|
||||
fn set_execute_permission(path: &Path) -> Result<(), io::Error>;
|
||||
|
||||
/// Extract the signal from a process exit status, if it was terminated by a
|
||||
/// signal
|
||||
fn signal_from_exit_status(exit_status: ExitStatus) -> Option<i32>;
|
||||
|
||||
/// Translate a path from a "native" path to a path the interpreter expects
|
||||
fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult;
|
||||
fn convert_native_path(working_directory: &Path, path: &Path) -> Result<String, String>;
|
||||
}
|
||||
|
@ -106,10 +106,6 @@ impl<'src, D> Recipe<'src, D> {
|
||||
!self.private && !self.attributes.contains(&Attribute::Private)
|
||||
}
|
||||
|
||||
pub(crate) fn takes_positional_arguments(&self, settings: &Settings) -> bool {
|
||||
settings.positional_arguments || self.attributes.contains(&Attribute::PositionalArguments)
|
||||
}
|
||||
|
||||
pub(crate) fn change_directory(&self) -> bool {
|
||||
!self.attributes.contains(&Attribute::NoCd)
|
||||
}
|
||||
@ -150,10 +146,9 @@ impl<'src, D> Recipe<'src, D> {
|
||||
|
||||
pub(crate) fn run<'run>(
|
||||
&self,
|
||||
context: &ExecutionContext<'src, 'run>,
|
||||
context: &RecipeContext<'src, 'run>,
|
||||
scope: &Scope<'src, 'run>,
|
||||
positional: &[String],
|
||||
is_dependency: bool,
|
||||
) -> RunResult<'src, ()> {
|
||||
let config = &context.config;
|
||||
|
||||
@ -167,7 +162,14 @@ impl<'src, D> Recipe<'src, D> {
|
||||
);
|
||||
}
|
||||
|
||||
let evaluator = Evaluator::new(context, is_dependency, scope);
|
||||
let evaluator = Evaluator::recipe_evaluator(
|
||||
context.config,
|
||||
context.dotenv,
|
||||
context.module_source,
|
||||
scope,
|
||||
context.search,
|
||||
context.settings,
|
||||
);
|
||||
|
||||
if self.shebang {
|
||||
self.run_shebang(context, scope, positional, config, evaluator)
|
||||
@ -178,7 +180,7 @@ impl<'src, D> Recipe<'src, D> {
|
||||
|
||||
fn run_linewise<'run>(
|
||||
&self,
|
||||
context: &ExecutionContext<'src, 'run>,
|
||||
context: &RecipeContext<'src, 'run>,
|
||||
scope: &Scope<'src, 'run>,
|
||||
positional: &[String],
|
||||
config: &Config,
|
||||
@ -267,7 +269,7 @@ impl<'src, D> Recipe<'src, D> {
|
||||
|
||||
cmd.arg(command);
|
||||
|
||||
if self.takes_positional_arguments(context.settings) {
|
||||
if context.settings.positional_arguments {
|
||||
cmd.arg(self.name.lexeme());
|
||||
cmd.args(positional);
|
||||
}
|
||||
@ -277,7 +279,7 @@ impl<'src, D> Recipe<'src, D> {
|
||||
cmd.stdout(Stdio::null());
|
||||
}
|
||||
|
||||
cmd.export(context.settings, context.dotenv, scope, context.unexports);
|
||||
cmd.export(context.settings, context.dotenv, scope);
|
||||
|
||||
match InterruptHandler::guard(|| cmd.status()) {
|
||||
Ok(exit_status) => {
|
||||
@ -310,7 +312,7 @@ impl<'src, D> Recipe<'src, D> {
|
||||
|
||||
pub(crate) fn run_shebang<'run>(
|
||||
&self,
|
||||
context: &ExecutionContext<'src, 'run>,
|
||||
context: &RecipeContext<'src, 'run>,
|
||||
scope: &Scope<'src, 'run>,
|
||||
positional: &[String],
|
||||
config: &Config,
|
||||
@ -351,9 +353,9 @@ impl<'src, D> Recipe<'src, D> {
|
||||
let tempdir = match &context.settings.tempdir {
|
||||
Some(tempdir) => tempdir_builder.tempdir_in(context.search.working_directory.join(tempdir)),
|
||||
None => {
|
||||
if let Some(runtime_dir) = dirs::runtime_dir() {
|
||||
let path = runtime_dir.join("just");
|
||||
fs::create_dir_all(&path).map_err(|io_error| Error::RuntimeDirIo {
|
||||
if let Some(cache_dir) = dirs::cache_dir() {
|
||||
let path = cache_dir.join("just");
|
||||
fs::create_dir_all(&path).map_err(|io_error| Error::CacheDirIo {
|
||||
io_error,
|
||||
path: path.clone(),
|
||||
})?;
|
||||
@ -419,11 +421,11 @@ impl<'src, D> Recipe<'src, D> {
|
||||
output_error,
|
||||
})?;
|
||||
|
||||
if self.takes_positional_arguments(context.settings) {
|
||||
if context.settings.positional_arguments {
|
||||
command.args(positional);
|
||||
}
|
||||
|
||||
command.export(context.settings, context.dotenv, scope, context.unexports);
|
||||
command.export(context.settings, context.dotenv, scope);
|
||||
|
||||
// run it!
|
||||
match InterruptHandler::guard(|| command.status()) {
|
||||
@ -476,7 +478,7 @@ impl<'src, D> Recipe<'src, D> {
|
||||
}
|
||||
|
||||
impl<'src, D: Display> ColorDisplay for Recipe<'src, D> {
|
||||
fn fmt(&self, f: &mut Formatter, color: Color) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter, color: Color) -> Result<(), fmt::Error> {
|
||||
if let Some(doc) = self.doc {
|
||||
writeln!(f, "# {doc}")?;
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub(crate) struct ExecutionContext<'src: 'run, 'run> {
|
||||
pub(crate) struct RecipeContext<'src: 'run, 'run> {
|
||||
pub(crate) config: &'run Config,
|
||||
pub(crate) dotenv: &'run BTreeMap<String, String>,
|
||||
pub(crate) module_source: &'run Path,
|
||||
pub(crate) scope: &'run Scope<'src, 'run>,
|
||||
pub(crate) search: &'run Search,
|
||||
pub(crate) settings: &'run Settings<'src>,
|
||||
pub(crate) unexports: &'run HashSet<String>,
|
||||
}
|
@ -8,9 +8,8 @@ pub(crate) struct RecipeResolver<'src: 'run, 'run> {
|
||||
|
||||
impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
|
||||
pub(crate) fn resolve_recipes(
|
||||
assignments: &'run Table<'src, Assignment<'src>>,
|
||||
settings: &Settings,
|
||||
unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>,
|
||||
assignments: &'run Table<'src, Assignment<'src>>,
|
||||
) -> CompileResult<'src, Table<'src, Rc<Recipe<'src>>>> {
|
||||
let mut resolver = Self {
|
||||
resolved_recipes: Table::new(),
|
||||
@ -40,10 +39,6 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
|
||||
}
|
||||
|
||||
for line in &recipe.body {
|
||||
if line.is_comment() && settings.ignore_comments {
|
||||
continue;
|
||||
}
|
||||
|
||||
for fragment in &line.fragments {
|
||||
if let Fragment::Interpolation { expression, .. } = fragment {
|
||||
for variable in expression.variables() {
|
||||
|
12
src/run.rs
12
src/run.rs
@ -1,8 +1,8 @@
|
||||
use super::*;
|
||||
|
||||
/// Main entry point into `just`. Parse arguments from `args` and run.
|
||||
/// Main entry point into just binary.
|
||||
#[allow(clippy::missing_errors_doc)]
|
||||
pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<(), i32> {
|
||||
pub fn run() -> Result<(), i32> {
|
||||
#[cfg(windows)]
|
||||
ansi_term::enable_ansi_support().ok();
|
||||
|
||||
@ -11,16 +11,12 @@ pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<()
|
||||
.filter("JUST_LOG")
|
||||
.write_style("JUST_LOG_STYLE"),
|
||||
)
|
||||
.try_init()
|
||||
.ok();
|
||||
.init();
|
||||
|
||||
let app = Config::app();
|
||||
|
||||
info!("Parsing command line arguments…");
|
||||
let matches = app.try_get_matches_from(args).map_err(|err| {
|
||||
err.print().ok();
|
||||
err.exit_code()
|
||||
})?;
|
||||
let matches = app.get_matches();
|
||||
|
||||
let config = Config::from_matches(&matches).map_err(Error::from);
|
||||
|
||||
|
@ -13,7 +13,7 @@ impl<'src> Keyed<'src> for Set<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Set<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "set {} := {}", self.name, self.value)
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ pub(crate) enum Setting<'src> {
|
||||
DotenvFilename(String),
|
||||
DotenvLoad(bool),
|
||||
DotenvPath(String),
|
||||
DotenvRequired(bool),
|
||||
Export(bool),
|
||||
Fallback(bool),
|
||||
IgnoreComments(bool),
|
||||
@ -20,12 +19,11 @@ pub(crate) enum Setting<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Setting<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
match self {
|
||||
Self::AllowDuplicateRecipes(value)
|
||||
| Self::AllowDuplicateVariables(value)
|
||||
| Self::DotenvLoad(value)
|
||||
| Self::DotenvRequired(value)
|
||||
| Self::Export(value)
|
||||
| Self::Fallback(value)
|
||||
| Self::IgnoreComments(value)
|
||||
|
@ -10,9 +10,8 @@ pub(crate) struct Settings<'src> {
|
||||
pub(crate) allow_duplicate_recipes: bool,
|
||||
pub(crate) allow_duplicate_variables: bool,
|
||||
pub(crate) dotenv_filename: Option<String>,
|
||||
pub(crate) dotenv_load: bool,
|
||||
pub(crate) dotenv_load: Option<bool>,
|
||||
pub(crate) dotenv_path: Option<PathBuf>,
|
||||
pub(crate) dotenv_required: bool,
|
||||
pub(crate) export: bool,
|
||||
pub(crate) fallback: bool,
|
||||
pub(crate) ignore_comments: bool,
|
||||
@ -40,14 +39,11 @@ impl<'src> Settings<'src> {
|
||||
settings.dotenv_filename = Some(filename);
|
||||
}
|
||||
Setting::DotenvLoad(dotenv_load) => {
|
||||
settings.dotenv_load = dotenv_load;
|
||||
settings.dotenv_load = Some(dotenv_load);
|
||||
}
|
||||
Setting::DotenvPath(path) => {
|
||||
settings.dotenv_path = Some(PathBuf::from(path));
|
||||
}
|
||||
Setting::DotenvRequired(dotenv_required) => {
|
||||
settings.dotenv_required = dotenv_required;
|
||||
}
|
||||
Setting::Export(export) => {
|
||||
settings.export = export;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub(crate) struct Shell<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for Shell<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "[{}", self.command)?;
|
||||
|
||||
for argument in &self.arguments {
|
||||
|
@ -1,4 +1,9 @@
|
||||
use {super::*, clap_mangen::Man};
|
||||
use {
|
||||
super::*,
|
||||
clap_mangen::Man,
|
||||
std::io::{Read, Seek},
|
||||
tempfile::tempfile,
|
||||
};
|
||||
|
||||
const INIT_JUSTFILE: &str = "default:\n echo 'Hello, world!'\n";
|
||||
|
||||
@ -15,7 +20,7 @@ pub(crate) enum Subcommand {
|
||||
overrides: BTreeMap<String, String>,
|
||||
},
|
||||
Completions {
|
||||
shell: completions::Shell,
|
||||
shell: clap_complete::Shell,
|
||||
},
|
||||
Dump,
|
||||
Edit,
|
||||
@ -42,7 +47,11 @@ pub(crate) enum Subcommand {
|
||||
}
|
||||
|
||||
impl Subcommand {
|
||||
pub(crate) fn execute<'src>(&self, config: &Config, loader: &'src Loader) -> RunResult<'src> {
|
||||
pub(crate) fn execute<'src>(
|
||||
&self,
|
||||
config: &Config,
|
||||
loader: &'src Loader,
|
||||
) -> Result<(), Error<'src>> {
|
||||
use Subcommand::*;
|
||||
|
||||
match self {
|
||||
@ -93,7 +102,7 @@ impl Subcommand {
|
||||
|
||||
fn groups(config: &Config, justfile: &Justfile) {
|
||||
println!("Recipe groups:");
|
||||
for group in justfile.public_groups(config) {
|
||||
for group in justfile.public_groups() {
|
||||
println!("{}{group}", config.list_prefix);
|
||||
}
|
||||
}
|
||||
@ -103,7 +112,7 @@ impl Subcommand {
|
||||
loader: &'src Loader,
|
||||
arguments: &[String],
|
||||
overrides: &BTreeMap<String, String>,
|
||||
) -> RunResult<'src> {
|
||||
) -> Result<(), Error<'src>> {
|
||||
if matches!(
|
||||
config.search_config,
|
||||
SearchConfig::FromInvocationDirectory | SearchConfig::FromSearchDirectory { .. }
|
||||
@ -146,7 +155,7 @@ impl Subcommand {
|
||||
};
|
||||
|
||||
match Self::run_inner(config, loader, arguments, overrides, &search) {
|
||||
Err((err @ Error::UnknownRecipe { .. }, true)) => {
|
||||
Err((err @ Error::UnknownRecipes { .. }, true)) => {
|
||||
match search.justfile.parent().unwrap().parent() {
|
||||
Some(parent) => {
|
||||
unknown_recipes_errors.get_or_insert(err);
|
||||
@ -188,7 +197,7 @@ impl Subcommand {
|
||||
config: &Config,
|
||||
loader: &'src Loader,
|
||||
search: &Search,
|
||||
) -> RunResult<'src, Compilation<'src>> {
|
||||
) -> Result<Compilation<'src>, Error<'src>> {
|
||||
let compilation = Compiler::compile(config.unstable, loader, &search.justfile)?;
|
||||
|
||||
if config.verbosity.loud() {
|
||||
@ -210,8 +219,8 @@ impl Subcommand {
|
||||
search: &Search,
|
||||
overrides: &BTreeMap<String, String>,
|
||||
chooser: Option<&str>,
|
||||
) -> RunResult<'src> {
|
||||
let mut recipes = Vec::<&Recipe>::new();
|
||||
) -> Result<(), Error<'src>> {
|
||||
let mut recipes = Vec::<&Recipe<Dependency>>::new();
|
||||
let mut stack = vec![justfile];
|
||||
while let Some(module) = stack.pop() {
|
||||
recipes.extend(
|
||||
@ -227,15 +236,7 @@ impl Subcommand {
|
||||
return Err(Error::NoChoosableRecipes);
|
||||
}
|
||||
|
||||
let chooser = if let Some(chooser) = chooser {
|
||||
OsString::from(chooser)
|
||||
} else {
|
||||
let mut chooser = OsString::new();
|
||||
chooser.push("fzf --multi --preview 'just --unstable --color always --justfile \"");
|
||||
chooser.push(&search.justfile);
|
||||
chooser.push("\" --show {}'");
|
||||
chooser
|
||||
};
|
||||
let chooser = chooser.map_or_else(|| config::chooser_default(&search.justfile), From::from);
|
||||
|
||||
let result = justfile
|
||||
.settings
|
||||
@ -260,15 +261,14 @@ impl Subcommand {
|
||||
};
|
||||
|
||||
for recipe in recipes {
|
||||
writeln!(
|
||||
child.stdin.as_mut().unwrap(),
|
||||
"{}",
|
||||
recipe.namepath.spaced()
|
||||
)
|
||||
.map_err(|io_error| Error::ChooserWrite {
|
||||
io_error,
|
||||
chooser: chooser.clone(),
|
||||
})?;
|
||||
if let Err(io_error) = child
|
||||
.stdin
|
||||
.as_mut()
|
||||
.expect("Child was created with piped stdio")
|
||||
.write_all(format!("{}\n", recipe.namepath).as_bytes())
|
||||
{
|
||||
return Err(Error::ChooserWrite { io_error, chooser });
|
||||
}
|
||||
}
|
||||
|
||||
let output = match child.wait_with_output() {
|
||||
@ -295,12 +295,72 @@ impl Subcommand {
|
||||
justfile.run(config, search, overrides, &recipes)
|
||||
}
|
||||
|
||||
fn completions(shell: completions::Shell) -> RunResult<'static, ()> {
|
||||
println!("{}", shell.script()?);
|
||||
fn completions(shell: clap_complete::Shell) -> RunResult<'static, ()> {
|
||||
use clap_complete::Shell;
|
||||
|
||||
fn replace(haystack: &mut String, needle: &str, replacement: &str) -> RunResult<'static, ()> {
|
||||
if let Some(index) = haystack.find(needle) {
|
||||
haystack.replace_range(index..index + needle.len(), replacement);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::internal(format!(
|
||||
"Failed to find text:\n{needle}\n…in completion script:\n{haystack}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
let mut script = {
|
||||
let mut tempfile = tempfile().map_err(|io_error| Error::TempfileIo { io_error })?;
|
||||
|
||||
clap_complete::generate(
|
||||
shell,
|
||||
&mut crate::config::Config::app(),
|
||||
env!("CARGO_PKG_NAME"),
|
||||
&mut tempfile,
|
||||
);
|
||||
|
||||
tempfile
|
||||
.rewind()
|
||||
.map_err(|io_error| Error::TempfileIo { io_error })?;
|
||||
|
||||
let mut buffer = String::new();
|
||||
|
||||
tempfile
|
||||
.read_to_string(&mut buffer)
|
||||
.map_err(|io_error| Error::TempfileIo { io_error })?;
|
||||
|
||||
buffer
|
||||
};
|
||||
|
||||
match shell {
|
||||
Shell::Bash => {
|
||||
for (needle, replacement) in completions::BASH_COMPLETION_REPLACEMENTS {
|
||||
replace(&mut script, needle, replacement)?;
|
||||
}
|
||||
}
|
||||
Shell::Fish => {
|
||||
script.insert_str(0, completions::FISH_RECIPE_COMPLETIONS);
|
||||
}
|
||||
Shell::PowerShell => {
|
||||
for (needle, replacement) in completions::POWERSHELL_COMPLETION_REPLACEMENTS {
|
||||
replace(&mut script, needle, replacement)?;
|
||||
}
|
||||
}
|
||||
|
||||
Shell::Zsh => {
|
||||
for (needle, replacement) in completions::ZSH_COMPLETION_REPLACEMENTS {
|
||||
replace(&mut script, needle, replacement)?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
println!("{}", script.trim());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn dump(config: &Config, ast: &Ast, justfile: &Justfile) -> RunResult<'static> {
|
||||
fn dump(config: &Config, ast: &Ast, justfile: &Justfile) -> Result<(), Error<'static>> {
|
||||
match config.dump_format {
|
||||
DumpFormat::Json => {
|
||||
serde_json::to_writer(io::stdout(), justfile)
|
||||
@ -312,7 +372,7 @@ impl Subcommand {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn edit(search: &Search) -> RunResult<'static> {
|
||||
fn edit(search: &Search) -> Result<(), Error<'static>> {
|
||||
let editor = env::var_os("VISUAL")
|
||||
.or_else(|| env::var_os("EDITOR"))
|
||||
.unwrap_or_else(|| "vim".into());
|
||||
@ -334,7 +394,7 @@ impl Subcommand {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format(config: &Config, search: &Search, src: &str, ast: &Ast) -> RunResult<'static> {
|
||||
fn format(config: &Config, search: &Search, src: &str, ast: &Ast) -> Result<(), Error<'static>> {
|
||||
config.require_unstable("The `--fmt` command is currently unstable.")?;
|
||||
|
||||
let formatted = ast.to_string();
|
||||
@ -379,7 +439,7 @@ impl Subcommand {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init(config: &Config) -> RunResult<'static> {
|
||||
fn init(config: &Config) -> Result<(), Error<'static>> {
|
||||
let search = Search::init(&config.search_config, &config.invocation_directory)?;
|
||||
|
||||
if search.justfile.is_file() {
|
||||
@ -399,7 +459,7 @@ impl Subcommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn man() -> RunResult<'static> {
|
||||
fn man() -> Result<(), Error<'static>> {
|
||||
let mut buffer = Vec::<u8>::new();
|
||||
|
||||
Man::new(Config::app())
|
||||
@ -419,22 +479,14 @@ impl Subcommand {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list(config: &Config, mut module: &Justfile, path: &ModulePath) -> RunResult<'static> {
|
||||
fn list(config: &Config, mut module: &Justfile, path: &ModulePath) -> Result<(), Error<'static>> {
|
||||
for name in &path.path {
|
||||
module = module
|
||||
.modules
|
||||
.get(name)
|
||||
.ok_or_else(|| Error::UnknownSubmodule {
|
||||
path: path.to_string(),
|
||||
})?;
|
||||
.ok_or_else(|| Error::UnknownSubmodule { path: path.clone() })?;
|
||||
}
|
||||
|
||||
Self::list_module(config, module, 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_module(config: &Config, module: &Justfile, depth: usize) {
|
||||
let aliases = if config.no_aliases {
|
||||
BTreeMap::new()
|
||||
} else {
|
||||
@ -479,11 +531,7 @@ impl Subcommand {
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
let list_prefix = config.list_prefix.repeat(depth + 1);
|
||||
|
||||
if depth == 0 {
|
||||
print!("{}", config.list_heading);
|
||||
}
|
||||
print!("{}", config.list_heading);
|
||||
|
||||
let groups = {
|
||||
let mut groups = BTreeMap::<Option<String>, Vec<&Recipe>>::new();
|
||||
@ -500,17 +548,7 @@ impl Subcommand {
|
||||
groups
|
||||
};
|
||||
|
||||
let mut ordered = module
|
||||
.public_groups(config)
|
||||
.into_iter()
|
||||
.map(Some)
|
||||
.collect::<Vec<Option<String>>>();
|
||||
|
||||
if groups.contains_key(&None) {
|
||||
ordered.insert(0, None);
|
||||
}
|
||||
|
||||
for (i, group) in ordered.into_iter().enumerate() {
|
||||
for (i, (group, recipes)) in groups.iter().enumerate() {
|
||||
if i > 0 {
|
||||
println!();
|
||||
}
|
||||
@ -518,15 +556,15 @@ impl Subcommand {
|
||||
let no_groups = groups.contains_key(&None) && groups.len() == 1;
|
||||
|
||||
if !no_groups {
|
||||
print!("{list_prefix}");
|
||||
if let Some(group) = &group {
|
||||
println!("[{group}]");
|
||||
print!("{}", config.list_prefix);
|
||||
if let Some(group_name) = group {
|
||||
println!("[{group_name}]");
|
||||
} else {
|
||||
println!("(no group)");
|
||||
}
|
||||
}
|
||||
|
||||
for recipe in groups.get(&group).unwrap() {
|
||||
for recipe in recipes {
|
||||
for (i, name) in iter::once(&recipe.name())
|
||||
.chain(aliases.get(recipe.name()).unwrap_or(&Vec::new()))
|
||||
.enumerate()
|
||||
@ -541,7 +579,8 @@ impl Subcommand {
|
||||
if doc.lines().count() > 1 {
|
||||
for line in doc.lines() {
|
||||
println!(
|
||||
"{list_prefix}{} {}",
|
||||
"{}{} {}",
|
||||
config.list_prefix,
|
||||
config.color.stdout().doc().paint("#"),
|
||||
config.color.stdout().doc().paint(line),
|
||||
);
|
||||
@ -550,7 +589,8 @@ impl Subcommand {
|
||||
}
|
||||
|
||||
print!(
|
||||
"{list_prefix}{}",
|
||||
"{}{}",
|
||||
config.list_prefix,
|
||||
RecipeSignature { name, recipe }.color_display(config.color.stdout())
|
||||
);
|
||||
|
||||
@ -570,35 +610,23 @@ impl Subcommand {
|
||||
}
|
||||
}
|
||||
|
||||
if config.list_submodules {
|
||||
for (i, submodule) in module.modules(config).into_iter().enumerate() {
|
||||
if i + groups.len() > 0 {
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("{list_prefix}{}:", submodule.name());
|
||||
|
||||
Self::list_module(config, submodule, depth + 1);
|
||||
}
|
||||
} else {
|
||||
for submodule in module.modules(config) {
|
||||
println!("{list_prefix}{} ...", submodule.name(),);
|
||||
}
|
||||
for submodule in module.modules(config) {
|
||||
println!("{}{} ...", config.list_prefix, submodule.name(),);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn show<'src>(
|
||||
config: &Config,
|
||||
mut module: &Justfile<'src>,
|
||||
path: &ModulePath,
|
||||
) -> RunResult<'src> {
|
||||
) -> Result<(), Error<'src>> {
|
||||
for name in &path.path[0..path.path.len() - 1] {
|
||||
module = module
|
||||
.modules
|
||||
.get(name)
|
||||
.ok_or_else(|| Error::UnknownSubmodule {
|
||||
path: path.to_string(),
|
||||
})?;
|
||||
.ok_or_else(|| Error::UnknownSubmodule { path: path.clone() })?;
|
||||
}
|
||||
|
||||
let name = path.path.last().unwrap();
|
||||
@ -612,8 +640,8 @@ impl Subcommand {
|
||||
println!("{}", recipe.color_display(config.color.stdout()));
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::UnknownRecipe {
|
||||
recipe: name.to_owned(),
|
||||
Err(Error::UnknownRecipes {
|
||||
recipes: vec![name.to_owned()],
|
||||
suggestion: module.suggest_recipe(name),
|
||||
})
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ mod full {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn summary(path: &Path) -> io::Result<Result<Summary, String>> {
|
||||
pub fn summary(path: &Path) -> Result<Result<Summary, String>, io::Error> {
|
||||
let loader = Loader::new();
|
||||
|
||||
match Compiler::compile(false, &loader, path) {
|
||||
|
@ -131,7 +131,7 @@ macro_rules! run_error {
|
||||
}
|
||||
|
||||
macro_rules! assert_matches {
|
||||
($expression:expr, $( $pattern:pat_param )|+ $( if $guard:expr )? $(,)?) => {
|
||||
($expression:expr, $( $pattern:pat_param )|+ $( if $guard:expr )?) => {
|
||||
match $expression {
|
||||
$( $pattern )|+ $( if $guard )? => {}
|
||||
left => panic!(
|
||||
|
14
src/thunk.rs
14
src/thunk.rs
@ -6,42 +6,42 @@ pub(crate) enum Thunk<'src> {
|
||||
Nullary {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context) -> FunctionResult,
|
||||
function: fn(function::Context) -> Result<String, String>,
|
||||
},
|
||||
Unary {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context, &str) -> FunctionResult,
|
||||
function: fn(function::Context, &str) -> Result<String, String>,
|
||||
arg: Box<Expression<'src>>,
|
||||
},
|
||||
UnaryOpt {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context, &str, Option<&str>) -> FunctionResult,
|
||||
function: fn(function::Context, &str, Option<&str>) -> Result<String, String>,
|
||||
args: (Box<Expression<'src>>, Box<Option<Expression<'src>>>),
|
||||
},
|
||||
UnaryPlus {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context, &str, &[String]) -> FunctionResult,
|
||||
function: fn(function::Context, &str, &[String]) -> Result<String, String>,
|
||||
args: (Box<Expression<'src>>, Vec<Expression<'src>>),
|
||||
},
|
||||
Binary {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context, &str, &str) -> FunctionResult,
|
||||
function: fn(function::Context, &str, &str) -> Result<String, String>,
|
||||
args: [Box<Expression<'src>>; 2],
|
||||
},
|
||||
BinaryPlus {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context, &str, &str, &[String]) -> FunctionResult,
|
||||
function: fn(function::Context, &str, &str, &[String]) -> Result<String, String>,
|
||||
args: ([Box<Expression<'src>>; 2], Vec<Expression<'src>>),
|
||||
},
|
||||
Ternary {
|
||||
name: Name<'src>,
|
||||
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||
function: fn(function::Context, &str, &str, &str) -> FunctionResult,
|
||||
function: fn(function::Context, &str, &str, &str) -> Result<String, String>,
|
||||
args: [Box<Expression<'src>>; 3],
|
||||
},
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub(crate) enum TokenKind {
|
||||
}
|
||||
|
||||
impl Display for TokenKind {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
use TokenKind::*;
|
||||
write!(
|
||||
f,
|
||||
|
@ -7,7 +7,7 @@ pub(crate) struct UnresolvedDependency<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Display for UnresolvedDependency<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
if self.arguments.is_empty() {
|
||||
write!(f, "{}", self.recipe)
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#[derive(Copy, Clone, Debug, PartialEq, clap::ValueEnum)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub(crate) enum UseColor {
|
||||
Auto,
|
||||
Always,
|
||||
|
@ -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]
|
||||
|
@ -185,13 +185,7 @@ fn status_error() {
|
||||
"exit-2": "#!/usr/bin/env bash\nexit 2\n",
|
||||
};
|
||||
|
||||
let output = Command::new("chmod")
|
||||
.arg("+x")
|
||||
.arg(tmp.path().join("exit-2"))
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(output.status.success());
|
||||
("chmod", "+x", tmp.path().join("exit-2")).run();
|
||||
|
||||
let path = env::join_paths(
|
||||
iter::once(tmp.path().to_owned()).chain(env::split_paths(&env::var_os("PATH").unwrap())),
|
||||
|
@ -47,21 +47,16 @@ test! {
|
||||
status: 2,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn env_is_loaded() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
test! {
|
||||
name: env_is_loaded,
|
||||
justfile: "
|
||||
set dotenv-load
|
||||
|
||||
x:
|
||||
echo XYZ
|
||||
",
|
||||
)
|
||||
.args(["--command", "sh", "-c", "printf $DOTENV_KEY"])
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value")
|
||||
.run();
|
||||
x:
|
||||
echo XYZ
|
||||
",
|
||||
args: ("--command", "sh", "-c", "printf $DOTENV_KEY"),
|
||||
stdout: "dotenv-value",
|
||||
}
|
||||
|
||||
test! {
|
||||
|
@ -1,42 +1,19 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn bash() {
|
||||
fn output() {
|
||||
let tempdir = tempdir();
|
||||
|
||||
let output = Command::new(executable_path("just"))
|
||||
.args(["--completions", "bash"])
|
||||
.arg("--completions")
|
||||
.arg("bash")
|
||||
.current_dir(tempdir.path())
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(output.status.success());
|
||||
|
||||
let script = str::from_utf8(&output.stdout).unwrap();
|
||||
let text = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
let tempdir = tempdir();
|
||||
|
||||
let path = tempdir.path().join("just.bash");
|
||||
|
||||
fs::write(&path, script).unwrap();
|
||||
|
||||
let status = Command::new("./tests/completions/just.bash")
|
||||
.arg(path)
|
||||
.status()
|
||||
.unwrap();
|
||||
|
||||
assert!(status.success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replacements() {
|
||||
for shell in ["bash", "elvish", "fish", "nushell", "powershell", "zsh"] {
|
||||
let output = Command::new(executable_path("just"))
|
||||
.args(["--completions", shell])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"shell completion generation for {shell} failed: {}",
|
||||
output.status
|
||||
);
|
||||
}
|
||||
assert!(text.starts_with("_just() {"));
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ reply_equals() {
|
||||
}
|
||||
|
||||
# --- Initial Setup ---
|
||||
source "$1"
|
||||
source ./completions/just.bash
|
||||
cd tests/completions
|
||||
cargo build
|
||||
PATH="$(git rev-parse --show-toplevel)/target/debug:$PATH"
|
||||
|
@ -1,27 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn datetime() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
x := datetime('%Y-%m-%d %z')
|
||||
",
|
||||
)
|
||||
.args(["--eval", "x"])
|
||||
.stdout_regex(r"\d\d\d\d-\d\d-\d\d [+-]\d\d\d\d")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datetime_utc() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
x := datetime_utc('%Y-%m-%d %Z')
|
||||
",
|
||||
)
|
||||
.args(["--eval", "x"])
|
||||
.stdout_regex(r"\d\d\d\d-\d\d-\d\d UTC")
|
||||
.run();
|
||||
}
|
242
tests/dotenv.rs
242
tests/dotenv.rs
@ -12,54 +12,40 @@ fn dotenv() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_false() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
r#"
|
||||
set dotenv-load := false
|
||||
test! {
|
||||
name: set_false,
|
||||
justfile: r#"
|
||||
set dotenv-load := false
|
||||
|
||||
@foo:
|
||||
if [ -n "${DOTENV_KEY+1}" ]; then echo defined; else echo undefined; fi
|
||||
"#,
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("undefined\n")
|
||||
.run();
|
||||
foo:
|
||||
if [ -n "${DOTENV_KEY+1}" ]; then echo defined; else echo undefined; fi
|
||||
"#,
|
||||
stdout: "undefined\n",
|
||||
stderr: "if [ -n \"${DOTENV_KEY+1}\" ]; then echo defined; else echo undefined; fi\n",
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_implicit() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
test! {
|
||||
name: set_implicit,
|
||||
justfile: r#"
|
||||
set dotenv-load
|
||||
|
||||
foo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\n")
|
||||
.stderr("echo $DOTENV_KEY\n")
|
||||
.run();
|
||||
foo:
|
||||
echo $DOTENV_KEY
|
||||
"#,
|
||||
stdout: "dotenv-value\n",
|
||||
stderr: "echo $DOTENV_KEY\n",
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_true() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load := true
|
||||
test! {
|
||||
name: set_true,
|
||||
justfile: r#"
|
||||
set dotenv-load := true
|
||||
|
||||
foo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\n")
|
||||
.stderr("echo $DOTENV_KEY\n")
|
||||
.run();
|
||||
foo:
|
||||
echo $DOTENV_KEY
|
||||
"#,
|
||||
stdout: "dotenv-value\n",
|
||||
stderr: "echo $DOTENV_KEY\n",
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -67,28 +53,32 @@ fn no_warning() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
foo:
|
||||
echo ${DOTENV_KEY:-unset}
|
||||
",
|
||||
foo:
|
||||
echo ${DOTENV_KEY:-unset}
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("unset\n")
|
||||
.stderr("echo ${DOTENV_KEY:-unset}\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_required() {
|
||||
fn path_not_found() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-required
|
||||
|
||||
foo:
|
||||
",
|
||||
foo:
|
||||
echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
)
|
||||
.stderr("error: Dotenv file not found\n")
|
||||
.status(1)
|
||||
.args(["--dotenv-path", ".env.prod"])
|
||||
.stderr(if cfg!(windows) {
|
||||
"error: Failed to load environment file: The system cannot find the file specified. (os \
|
||||
error 2)\n"
|
||||
} else {
|
||||
"error: Failed to load environment file: No such file or directory (os error 2)\n"
|
||||
})
|
||||
.status(EXIT_FAILURE)
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -97,9 +87,9 @@ fn path_resolves() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
)
|
||||
.tree(tree! {
|
||||
subdir: {
|
||||
@ -117,9 +107,9 @@ fn filename_resolves() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
)
|
||||
.tree(tree! {
|
||||
".env.special": "JUST_TEST_VARIABLE=bar"
|
||||
@ -155,11 +145,11 @@ fn path_flag_overwrites_no_load() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load := false
|
||||
set dotenv-load := false
|
||||
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
)
|
||||
.tree(tree! {
|
||||
subdir: {
|
||||
@ -237,12 +227,12 @@ fn program_argument_has_priority_for_dotenv_filename() {
|
||||
fn program_argument_has_priority_for_dotenv_path() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-path := 'subdir/.env'
|
||||
r#"
|
||||
set dotenv-path := "subdir/.env"
|
||||
|
||||
foo:
|
||||
@echo $JUST_TEST_VARIABLE
|
||||
",
|
||||
"#,
|
||||
)
|
||||
.tree(tree! {
|
||||
subdir: {
|
||||
@ -267,130 +257,8 @@ fn dotenv_path_is_relative_to_working_directory() {
|
||||
@echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.tree(tree! { subdir: { } })
|
||||
.current_dir("subdir")
|
||||
.stdout("dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_variable_in_recipe() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
|
||||
echo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\n")
|
||||
.stderr("echo $DOTENV_KEY\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_variable_in_backtick() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
X:=`echo $DOTENV_KEY`
|
||||
echo:
|
||||
echo {{X}}
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\n")
|
||||
.stderr("echo dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_variable_in_function_in_recipe() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
echo:
|
||||
echo {{env_var_or_default('DOTENV_KEY', 'foo')}}
|
||||
echo {{env_var('DOTENV_KEY')}}
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\ndotenv-value\n")
|
||||
.stderr("echo dotenv-value\necho dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_variable_in_function_in_backtick() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
X:=env_var_or_default('DOTENV_KEY', 'foo')
|
||||
Y:=env_var('DOTENV_KEY')
|
||||
echo:
|
||||
echo {{X}}
|
||||
echo {{Y}}
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\ndotenv-value\n")
|
||||
.stderr("echo dotenv-value\necho dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_dotenv() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
X:=env_var_or_default('DOTENV_KEY', 'DEFAULT')
|
||||
echo:
|
||||
echo {{X}}
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.arg("--no-dotenv")
|
||||
.stdout("DEFAULT\n")
|
||||
.stderr("echo DEFAULT\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_env_var_override() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
echo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.env("DOTENV_KEY", "not-the-dotenv-value")
|
||||
.stdout("not-the-dotenv-value\n")
|
||||
.stderr("echo $DOTENV_KEY\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotenv_path_usable_from_subdir() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-path := '.custom-env'
|
||||
|
||||
@echo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.create_dir("sub")
|
||||
.current_dir("sub")
|
||||
.write(".custom-env", "DOTENV_KEY=dotenv-value")
|
||||
.stdout("dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
|
@ -64,13 +64,7 @@ fn status_error() {
|
||||
"exit-2": "#!/usr/bin/env bash\nexit 2\n",
|
||||
};
|
||||
|
||||
let output = Command::new("chmod")
|
||||
.arg("+x")
|
||||
.arg(tmp.path().join("exit-2"))
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(output.status.success());
|
||||
("chmod", "+x", tmp.path().join("exit-2")).run();
|
||||
|
||||
let path = env::join_paths(
|
||||
iter::once(tmp.path().to_owned()).chain(env::split_paths(&env::var_os("PATH").unwrap())),
|
||||
|
@ -126,13 +126,7 @@ fn write_error() {
|
||||
|
||||
let justfile_path = test.justfile_path();
|
||||
|
||||
let output = Command::new("chmod")
|
||||
.arg("400")
|
||||
.arg(&justfile_path)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
assert!(output.status.success());
|
||||
("chmod", "400", &justfile_path).run();
|
||||
|
||||
let _tempdir = test.run();
|
||||
|
||||
|
@ -1027,26 +1027,3 @@ import
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_dependency() {
|
||||
let justfile = "
|
||||
alpha: beta
|
||||
@echo 'alpha {{is_dependency()}}'
|
||||
beta: && gamma
|
||||
@echo 'beta {{is_dependency()}}'
|
||||
gamma:
|
||||
@echo 'gamma {{is_dependency()}}'
|
||||
";
|
||||
Test::new()
|
||||
.args(["alpha"])
|
||||
.justfile(justfile)
|
||||
.stdout("beta true\ngamma true\nalpha false\n")
|
||||
.run();
|
||||
|
||||
Test::new()
|
||||
.args(["beta"])
|
||||
.justfile(justfile)
|
||||
.stdout("beta false\ngamma true\n")
|
||||
.run();
|
||||
}
|
||||
|
141
tests/groups.rs
141
tests/groups.rs
@ -96,47 +96,6 @@ fn list_with_groups_unsorted() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_with_groups_unsorted_group_order() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
[group('y')]
|
||||
[group('x')]
|
||||
f:
|
||||
|
||||
[group('b')]
|
||||
b:
|
||||
|
||||
[group('a')]
|
||||
e:
|
||||
|
||||
c:
|
||||
",
|
||||
)
|
||||
.args(["--list", "--unsorted"])
|
||||
.stdout(
|
||||
"
|
||||
Available recipes:
|
||||
(no group)
|
||||
c
|
||||
|
||||
[x]
|
||||
f
|
||||
|
||||
[y]
|
||||
f
|
||||
|
||||
[b]
|
||||
b
|
||||
|
||||
[a]
|
||||
e
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_groups() {
|
||||
Test::new()
|
||||
@ -185,103 +144,3 @@ 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:
|
||||
",
|
||||
)
|
||||
.arg("--groups")
|
||||
.stdout(
|
||||
"
|
||||
Recipe groups:
|
||||
A
|
||||
B
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_groups_unsorted() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
[group: 'Z']
|
||||
baz:
|
||||
|
||||
[group: 'B']
|
||||
foo:
|
||||
|
||||
[group: 'A', group: 'B']
|
||||
bar:
|
||||
",
|
||||
)
|
||||
.args(["--groups", "--unsorted"])
|
||||
.stdout(
|
||||
"
|
||||
Recipe groups:
|
||||
Z
|
||||
B
|
||||
A
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_groups_private_unsorted() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
[private]
|
||||
[group: 'A']
|
||||
foo:
|
||||
|
||||
[group: 'B']
|
||||
bar:
|
||||
|
||||
[group: 'A']
|
||||
baz:
|
||||
",
|
||||
)
|
||||
.args(["--groups", "--unsorted"])
|
||||
.stdout(
|
||||
"
|
||||
Recipe groups:
|
||||
B
|
||||
A
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_groups_private() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
[private]
|
||||
[group: 'A']
|
||||
foo:
|
||||
|
||||
[group: 'B']
|
||||
bar:
|
||||
",
|
||||
)
|
||||
.args(["--groups", "--unsorted"])
|
||||
.stdout(
|
||||
"
|
||||
Recipe groups:
|
||||
B
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
@ -97,41 +97,3 @@ fn dont_evaluate_comments() {
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dont_analyze_comments() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set ignore-comments
|
||||
|
||||
some_recipe:
|
||||
# {{ bar }}
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comments_still_must_be_parsable_when_ignored() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
set ignore-comments
|
||||
|
||||
some_recipe:
|
||||
# {{ foo bar }}
|
||||
",
|
||||
)
|
||||
.stderr(
|
||||
"
|
||||
error: Expected '}}', '(', '+', or '/', but found identifier
|
||||
——▶ justfile:4:12
|
||||
│
|
||||
4 │ # {{ foo bar }}
|
||||
│ ^^^
|
||||
",
|
||||
)
|
||||
.status(EXIT_FAILURE)
|
||||
.run();
|
||||
}
|
||||
|
@ -46,9 +46,8 @@ fn alias() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"positional_arguments": false,
|
||||
@ -59,7 +58,6 @@ fn alias() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -86,9 +84,8 @@ fn assignment() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -99,7 +96,6 @@ fn assignment() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -140,9 +136,8 @@ fn body() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -153,7 +148,6 @@ fn body() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -206,9 +200,8 @@ fn dependencies() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -219,7 +212,6 @@ fn dependencies() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -310,9 +302,8 @@ fn dependency_argument() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -323,7 +314,6 @@ fn dependency_argument() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -376,9 +366,8 @@ fn duplicate_recipes() {
|
||||
"allow_duplicate_recipes": true,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -389,7 +378,6 @@ fn duplicate_recipes() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -420,9 +408,8 @@ fn duplicate_variables() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": true,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -433,7 +420,6 @@ fn duplicate_variables() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -467,9 +453,8 @@ fn doc_comment() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -480,7 +465,6 @@ fn doc_comment() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -500,9 +484,8 @@ fn empty_justfile() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -513,7 +496,6 @@ fn empty_justfile() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -654,9 +636,8 @@ fn parameters() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -667,7 +648,6 @@ fn parameters() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -741,9 +721,8 @@ fn priors() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -754,7 +733,6 @@ fn priors() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -788,9 +766,8 @@ fn private() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -801,7 +778,6 @@ fn private() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -835,9 +811,8 @@ fn quiet() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -848,7 +823,6 @@ fn quiet() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -896,7 +870,6 @@ fn settings() {
|
||||
"dotenv_filename": "filename",
|
||||
"dotenv_load": true,
|
||||
"dotenv_path": "path",
|
||||
"dotenv_required": false,
|
||||
"export": true,
|
||||
"fallback": true,
|
||||
"ignore_comments": true,
|
||||
@ -910,7 +883,6 @@ fn settings() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -947,9 +919,8 @@ fn shebang() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -960,7 +931,6 @@ fn shebang() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -994,9 +964,8 @@ fn simple() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"ignore_comments": false,
|
||||
@ -1007,7 +976,6 @@ fn simple() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -1044,9 +1012,8 @@ fn attribute() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"positional_arguments": false,
|
||||
@ -1057,7 +1024,6 @@ fn attribute() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}),
|
||||
);
|
||||
@ -1107,9 +1073,8 @@ fn module() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"positional_arguments": false,
|
||||
@ -1120,7 +1085,6 @@ fn module() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
},
|
||||
},
|
||||
@ -1129,9 +1093,8 @@ fn module() {
|
||||
"allow_duplicate_recipes": false,
|
||||
"allow_duplicate_variables": false,
|
||||
"dotenv_filename": null,
|
||||
"dotenv_load": false,
|
||||
"dotenv_load": null,
|
||||
"dotenv_path": null,
|
||||
"dotenv_required": false,
|
||||
"export": false,
|
||||
"fallback": false,
|
||||
"positional_arguments": false,
|
||||
@ -1142,7 +1105,6 @@ fn module() {
|
||||
"windows_powershell": false,
|
||||
"windows_shell": null,
|
||||
},
|
||||
"unexports": [],
|
||||
"warnings": [],
|
||||
}))
|
||||
.unwrap()
|
||||
|
@ -5,6 +5,7 @@ pub(crate) use {
|
||||
tempdir::tempdir,
|
||||
test::{assert_eval_eq, Output, Test},
|
||||
},
|
||||
cradle::input::Input,
|
||||
executable_path::executable_path,
|
||||
just::unindent,
|
||||
libc::{EXIT_FAILURE, EXIT_SUCCESS},
|
||||
@ -46,7 +47,6 @@ mod completions;
|
||||
mod conditional;
|
||||
mod confirm;
|
||||
mod constants;
|
||||
mod datetime;
|
||||
mod delimiters;
|
||||
mod directories;
|
||||
mod dotenv;
|
||||
@ -104,10 +104,7 @@ mod summary;
|
||||
mod tempdir;
|
||||
mod timestamps;
|
||||
mod undefined_variables;
|
||||
mod unexport;
|
||||
mod unstable;
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
#[cfg(target_family = "windows")]
|
||||
mod windows_shell;
|
||||
mod working_directory;
|
||||
|
130
tests/list.rs
130
tests/list.rs
@ -223,133 +223,3 @@ fn list_unknown_submodule() {
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_with_groups_in_modules() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
[group('FOO')]
|
||||
foo:
|
||||
|
||||
mod bar
|
||||
",
|
||||
)
|
||||
.write("bar.just", "[group('BAZ')]\nbaz:")
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "--list", "--list-submodules"])
|
||||
.stdout(
|
||||
"
|
||||
Available recipes:
|
||||
[FOO]
|
||||
foo
|
||||
|
||||
bar:
|
||||
[BAZ]
|
||||
baz
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_displays_recipes_in_submodules() {
|
||||
Test::new()
|
||||
.write("foo.just", "bar:\n @echo FOO")
|
||||
.justfile(
|
||||
"
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "--list", "--list-submodules"])
|
||||
.stdout(
|
||||
"
|
||||
Available recipes:
|
||||
foo:
|
||||
bar
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modules_are_space_separated_in_output() {
|
||||
Test::new()
|
||||
.write("foo.just", "foo:")
|
||||
.write("bar.just", "bar:")
|
||||
.justfile(
|
||||
"
|
||||
mod foo
|
||||
|
||||
mod bar
|
||||
",
|
||||
)
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "--list", "--list-submodules"])
|
||||
.stdout(
|
||||
"
|
||||
Available recipes:
|
||||
bar:
|
||||
bar
|
||||
|
||||
foo:
|
||||
foo
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_recipe_list_alignment_ignores_private_recipes() {
|
||||
Test::new()
|
||||
.write(
|
||||
"foo.just",
|
||||
"
|
||||
# foos
|
||||
foo:
|
||||
@echo FOO
|
||||
|
||||
[private]
|
||||
barbarbar:
|
||||
@echo BAR
|
||||
|
||||
@_bazbazbaz:
|
||||
@echo BAZ
|
||||
",
|
||||
)
|
||||
.justfile("mod foo")
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "--list", "--list-submodules"])
|
||||
.stdout(
|
||||
"
|
||||
Available recipes:
|
||||
foo:
|
||||
foo # foos
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_modules_are_properly_indented() {
|
||||
Test::new()
|
||||
.write("foo.just", "mod bar")
|
||||
.write("bar.just", "baz:\n @echo FOO")
|
||||
.justfile(
|
||||
"
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "--list", "--list-submodules"])
|
||||
.stdout(
|
||||
"
|
||||
Available recipes:
|
||||
foo:
|
||||
bar:
|
||||
baz
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ test! {
|
||||
justfile: "hello:",
|
||||
args: ("foo", "bar"),
|
||||
stdout: "",
|
||||
stderr: "error: Justfile does not contain recipe `foo`.\n",
|
||||
stderr: "error: Justfile does not contain recipes `foo` or `bar`.\n",
|
||||
status: EXIT_FAILURE,
|
||||
}
|
||||
|
||||
@ -884,7 +884,7 @@ _private-recipe:
|
||||
args: ("--list"),
|
||||
stdout: r#"
|
||||
Available recipes:
|
||||
a Z="\t z" # something else
|
||||
a Z="\t z" # something else
|
||||
hello a b='B ' c='C' # this does a thing
|
||||
"#,
|
||||
}
|
||||
@ -1589,6 +1589,84 @@ echo:
|
||||
stderr: "echo 1\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: dotenv_variable_in_recipe,
|
||||
justfile: "
|
||||
#
|
||||
set dotenv-load
|
||||
|
||||
echo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
stdout: "dotenv-value\n",
|
||||
stderr: "echo $DOTENV_KEY\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: dotenv_variable_in_backtick,
|
||||
justfile: "
|
||||
#
|
||||
set dotenv-load
|
||||
X:=`echo $DOTENV_KEY`
|
||||
echo:
|
||||
echo {{X}}
|
||||
",
|
||||
stdout: "dotenv-value\n",
|
||||
stderr: "echo dotenv-value\n",
|
||||
}
|
||||
test! {
|
||||
name: dotenv_variable_in_function_in_recipe,
|
||||
justfile: "
|
||||
#
|
||||
set dotenv-load
|
||||
echo:
|
||||
echo {{env_var_or_default('DOTENV_KEY', 'foo')}}
|
||||
echo {{env_var('DOTENV_KEY')}}
|
||||
",
|
||||
stdout: "dotenv-value\ndotenv-value\n",
|
||||
stderr: "echo dotenv-value\necho dotenv-value\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: dotenv_variable_in_function_in_backtick,
|
||||
justfile: "
|
||||
#
|
||||
set dotenv-load
|
||||
X:=env_var_or_default('DOTENV_KEY', 'foo')
|
||||
Y:=env_var('DOTENV_KEY')
|
||||
echo:
|
||||
echo {{X}}
|
||||
echo {{Y}}
|
||||
",
|
||||
stdout: "dotenv-value\ndotenv-value\n",
|
||||
stderr: "echo dotenv-value\necho dotenv-value\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: no_dotenv,
|
||||
justfile: "
|
||||
#
|
||||
X:=env_var_or_default('DOTENV_KEY', 'DEFAULT')
|
||||
echo:
|
||||
echo {{X}}
|
||||
",
|
||||
args: ("--no-dotenv"),
|
||||
stdout: "DEFAULT\n",
|
||||
stderr: "echo DEFAULT\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: dotenv_env_var_override,
|
||||
justfile: "
|
||||
#
|
||||
echo:
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
env: {"DOTENV_KEY": "not-the-dotenv-value",},
|
||||
stdout: "not-the-dotenv-value\n",
|
||||
stderr: "echo $DOTENV_KEY\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: invalid_escape_sequence_message,
|
||||
justfile: r#"
|
||||
|
113
tests/modules.rs
113
tests/modules.rs
@ -115,7 +115,7 @@ fn missing_recipe_after_invalid_path() {
|
||||
.test_round_trip(false)
|
||||
.arg(":foo::foo")
|
||||
.arg("bar")
|
||||
.stderr("error: Justfile does not contain recipe `:foo::foo`.\n")
|
||||
.stderr("error: Justfile does not contain recipes `:foo::foo` or `bar`.\n")
|
||||
.status(EXIT_FAILURE)
|
||||
.run();
|
||||
}
|
||||
@ -515,6 +515,7 @@ fn missing_optional_modules_do_not_conflict() {
|
||||
#[test]
|
||||
fn root_dotenv_is_available_to_submodules() {
|
||||
Test::new()
|
||||
.write("foo.just", "foo:\n @echo $DOTENV_KEY")
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
@ -522,10 +523,10 @@ fn root_dotenv_is_available_to_submodules() {
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.write("foo.just", "foo:\n @echo $DOTENV_KEY")
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "foo", "foo"])
|
||||
.arg("--unstable")
|
||||
.arg("foo")
|
||||
.arg("foo")
|
||||
.stdout("dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
@ -533,6 +534,10 @@ fn root_dotenv_is_available_to_submodules() {
|
||||
#[test]
|
||||
fn dotenv_settings_in_submodule_are_ignored() {
|
||||
Test::new()
|
||||
.write(
|
||||
"foo.just",
|
||||
"set dotenv-load := false\nfoo:\n @echo $DOTENV_KEY",
|
||||
)
|
||||
.justfile(
|
||||
"
|
||||
set dotenv-load
|
||||
@ -540,13 +545,10 @@ fn dotenv_settings_in_submodule_are_ignored() {
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.write(
|
||||
"foo.just",
|
||||
"set dotenv-load := false\nfoo:\n @echo $DOTENV_KEY",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "foo", "foo"])
|
||||
.arg("--unstable")
|
||||
.arg("foo")
|
||||
.arg("foo")
|
||||
.stdout("dotenv-value\n")
|
||||
.run();
|
||||
}
|
||||
@ -690,94 +692,3 @@ fn recipes_with_same_name_are_both_run() {
|
||||
.stdout("MODULE\nROOT\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn submodule_recipe_not_found_error_message() {
|
||||
Test::new()
|
||||
.args(["--unstable", "foo::bar"])
|
||||
.stderr("error: Justfile does not contain submodule `foo`\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn submodule_recipe_not_found_spaced_error_message() {
|
||||
Test::new()
|
||||
.write("foo.just", "bar:\n @echo MODULE")
|
||||
.justfile(
|
||||
"
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "foo", "baz"])
|
||||
.stderr("error: Justfile does not contain recipe `foo baz`.\nDid you mean `bar`?\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn submodule_recipe_not_found_colon_separated_error_message() {
|
||||
Test::new()
|
||||
.write("foo.just", "bar:\n @echo MODULE")
|
||||
.justfile(
|
||||
"
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "foo::baz"])
|
||||
.stderr("error: Justfile does not contain recipe `foo::baz`.\nDid you mean `bar`?\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colon_separated_path_does_not_run_recipes() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
foo:
|
||||
@echo FOO
|
||||
|
||||
bar:
|
||||
@echo BAR
|
||||
",
|
||||
)
|
||||
.args(["--unstable", "foo::bar"])
|
||||
.stderr("error: Expected submodule at `foo` but found recipe.\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expected_submodule_but_found_recipe_in_root_error() {
|
||||
Test::new()
|
||||
.justfile("foo:")
|
||||
.arg("foo::baz")
|
||||
.stderr("error: Expected submodule at `foo` but found recipe.\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expected_submodule_but_found_recipe_in_submodule_error() {
|
||||
Test::new()
|
||||
.justfile("mod foo")
|
||||
.write("foo.just", "bar:")
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "foo::bar::baz"])
|
||||
.stderr("error: Expected submodule at `foo::bar` but found recipe.\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colon_separated_path_components_are_not_used_as_arguments() {
|
||||
Test::new()
|
||||
.justfile("foo bar:")
|
||||
.args(["foo::bar"])
|
||||
.stderr("error: Expected submodule at `foo` but found recipe.\n")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
@ -24,31 +24,6 @@ test! {
|
||||
"#,
|
||||
}
|
||||
|
||||
test! {
|
||||
name: linewise_with_attribute,
|
||||
justfile: r#"
|
||||
[positional-arguments]
|
||||
foo bar baz:
|
||||
echo $0
|
||||
echo $1
|
||||
echo $2
|
||||
echo "$@"
|
||||
"#,
|
||||
args: ("foo", "hello", "goodbye"),
|
||||
stdout: "
|
||||
foo
|
||||
hello
|
||||
goodbye
|
||||
hello goodbye
|
||||
",
|
||||
stderr: r#"
|
||||
echo $0
|
||||
echo $1
|
||||
echo $2
|
||||
echo "$@"
|
||||
"#,
|
||||
}
|
||||
|
||||
test! {
|
||||
name: variadic_linewise,
|
||||
justfile: r#"
|
||||
@ -76,18 +51,6 @@ test! {
|
||||
stdout: "hello\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: shebang_with_attribute,
|
||||
justfile: "
|
||||
[positional-arguments]
|
||||
foo bar:
|
||||
#!/bin/sh
|
||||
echo $1
|
||||
",
|
||||
args: ("foo", "hello"),
|
||||
stdout: "hello\n",
|
||||
}
|
||||
|
||||
test! {
|
||||
name: variadic_shebang,
|
||||
justfile: r#"
|
||||
|
@ -151,39 +151,3 @@ test! {
|
||||
stderr: "echo bar\necho foo\n",
|
||||
shell: false,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recipe_shell_not_found_error_message() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
foo:
|
||||
@echo bar
|
||||
",
|
||||
)
|
||||
.shell(false)
|
||||
.args(["--shell", "NOT_A_REAL_SHELL"])
|
||||
.stderr_regex(
|
||||
"error: Recipe `foo` could not be run because just could not find the shell: .*\n",
|
||||
)
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backtick_recipe_shell_not_found_error_message() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
bar := `echo bar`
|
||||
|
||||
foo:
|
||||
echo {{bar}}
|
||||
",
|
||||
)
|
||||
.shell(false)
|
||||
.args(["--shell", "NOT_A_REAL_SHELL"])
|
||||
.stderr_regex("(?s)error: Backtick could not be run because just could not find the shell:.*")
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ fn shell_expanded_strings_can_be_used_in_settings() {
|
||||
echo $DOTENV_KEY
|
||||
",
|
||||
)
|
||||
.write(".env", "DOTENV_KEY=dotenv-value")
|
||||
.env("JUST_TEST_VARIABLE", ".env")
|
||||
.stdout("dotenv-value\n")
|
||||
.run();
|
||||
|
@ -124,18 +124,3 @@ fn show_invalid_path() {
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_space_separated_path() {
|
||||
Test::new()
|
||||
.write("foo.just", "bar:\n @echo MODULE")
|
||||
.justfile(
|
||||
"
|
||||
mod foo
|
||||
",
|
||||
)
|
||||
.test_round_trip(false)
|
||||
.args(["--unstable", "--show", "foo bar"])
|
||||
.stdout("bar:\n @echo MODULE\n")
|
||||
.run();
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ pub(crate) fn tempdir() -> TempDir {
|
||||
|
||||
builder.prefix("just-test-tempdir");
|
||||
|
||||
if let Some(runtime_dir) = dirs::runtime_dir() {
|
||||
let path = runtime_dir.join("just");
|
||||
if let Some(cache_dir) = dirs::cache_dir() {
|
||||
let path = cache_dir.join("just");
|
||||
fs::create_dir_all(&path).unwrap();
|
||||
builder.tempdir_in(path)
|
||||
} else {
|
||||
|
@ -94,11 +94,6 @@ impl Test {
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn create_dir(self, path: impl AsRef<Path>) -> Self {
|
||||
fs::create_dir_all(self.tempdir.path().join(path.as_ref())).unwrap();
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn current_dir(mut self, path: impl AsRef<Path>) -> Self {
|
||||
path.as_ref().clone_into(&mut self.current_dir);
|
||||
self
|
||||
@ -206,9 +201,10 @@ impl Test {
|
||||
} else {
|
||||
self.stdout.clone()
|
||||
};
|
||||
|
||||
let stderr = unindent(&self.stderr);
|
||||
|
||||
fs::write(self.tempdir.path().join(".env"), "DOTENV_KEY=dotenv-value").unwrap();
|
||||
|
||||
let mut command = Command::new(executable_path("just"));
|
||||
|
||||
if self.shell {
|
||||
@ -262,7 +258,7 @@ impl Test {
|
||||
}
|
||||
}
|
||||
|
||||
if !compare("status", output.status.code(), Some(self.status))
|
||||
if !compare("status", output.status.code().unwrap(), self.status)
|
||||
| (self.stdout_regex.is_none() && !compare("stdout", output_stdout, &stdout))
|
||||
| (self.stderr_regex.is_none() && !compare("stderr", output_stderr, &stderr))
|
||||
{
|
||||
|
@ -1,126 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn unexport_environment_variable_linewise() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
unexport JUST_TEST_VARIABLE
|
||||
|
||||
@recipe:
|
||||
echo ${JUST_TEST_VARIABLE:-unset}
|
||||
",
|
||||
)
|
||||
.env("JUST_TEST_VARIABLE", "foo")
|
||||
.stdout("unset\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unexport_environment_variable_shebang() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
unexport JUST_TEST_VARIABLE
|
||||
|
||||
recipe:
|
||||
#!/usr/bin/env bash
|
||||
echo ${JUST_TEST_VARIABLE:-unset}
|
||||
",
|
||||
)
|
||||
.env("JUST_TEST_VARIABLE", "foo")
|
||||
.stdout("unset\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_unexport_fails() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
unexport JUST_TEST_VARIABLE
|
||||
|
||||
recipe:
|
||||
echo \"variable: $JUST_TEST_VARIABLE\"
|
||||
|
||||
unexport JUST_TEST_VARIABLE
|
||||
",
|
||||
)
|
||||
.env("JUST_TEST_VARIABLE", "foo")
|
||||
.stderr(
|
||||
"
|
||||
error: Variable `JUST_TEST_VARIABLE` is unexported multiple times
|
||||
——▶ justfile:6:10
|
||||
│
|
||||
6 │ unexport JUST_TEST_VARIABLE
|
||||
│ ^^^^^^^^^^^^^^^^^^
|
||||
",
|
||||
)
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_unexport_conflict() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
unexport JUST_TEST_VARIABLE
|
||||
|
||||
recipe:
|
||||
echo variable: $JUST_TEST_VARIABLE
|
||||
|
||||
export JUST_TEST_VARIABLE := 'foo'
|
||||
",
|
||||
)
|
||||
.stderr(
|
||||
"
|
||||
error: Variable JUST_TEST_VARIABLE is both exported and unexported
|
||||
——▶ justfile:6:8
|
||||
│
|
||||
6 │ export JUST_TEST_VARIABLE := 'foo'
|
||||
│ ^^^^^^^^^^^^^^^^^^
|
||||
",
|
||||
)
|
||||
.status(1)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unexport_doesnt_override_local_recipe_export() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
unexport JUST_TEST_VARIABLE
|
||||
|
||||
recipe $JUST_TEST_VARIABLE:
|
||||
@echo \"variable: $JUST_TEST_VARIABLE\"
|
||||
",
|
||||
)
|
||||
.args(["recipe", "value"])
|
||||
.stdout("variable: value\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unexport_does_not_conflict_with_recipe_syntax() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
unexport foo:
|
||||
@echo {{foo}}
|
||||
",
|
||||
)
|
||||
.args(["unexport", "bar"])
|
||||
.stdout("bar\n")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unexport_does_not_conflict_with_assignment_syntax() {
|
||||
Test::new()
|
||||
.justfile("unexport := 'foo'")
|
||||
.args(["--evaluate", "unexport"])
|
||||
.stdout("foo")
|
||||
.run();
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn bare_bash_in_shebang() {
|
||||
Test::new()
|
||||
.justfile(
|
||||
"
|
||||
default:
|
||||
#!bash
|
||||
echo FOO
|
||||
",
|
||||
)
|
||||
.stdout("FOO\n")
|
||||
.run();
|
||||
}
|
Loading…
Reference in New Issue
Block a user