rust-just 1.36.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4145 +1,84 @@
1
1
  <div align=right>Table of Contents↗️</div>
2
2
 
3
- <h1 align=center><code>just</code></h1>
3
+ <h1 align=center><code>rust-just</code></h1>
4
4
 
5
5
  <div align=center>
6
- <a href=https://crates.io/crates/just>
7
- <img src=https://img.shields.io/crates/v/just.svg alt="crates.io version">
6
+ <a href=https://github.com/gnpaone/rust-just>
7
+ <img src=https://img.shields.io/badge/github-rust--just-silver?style=for-the-badge&logo=github&labelColor=black
8
+ alt="github repo">
8
9
  </a>
9
- <a href=https://github.com/casey/just/actions>
10
- <img src=https://github.com/casey/just/actions/workflows/ci.yaml/badge.svg alt="build status">
10
+ <a href=https://www.npmjs.com/package/rust-just>
11
+ <img src=https://img.shields.io/npm/dm/rust-just?style=for-the-badge&color=orchid alt="npm downloads">
11
12
  </a>
12
- <a href=https://github.com/casey/just/releases>
13
- <img src=https://img.shields.io/github/downloads/casey/just/total.svg alt=downloads>
13
+ <a href=https://github.com/gnpaone/rust-just/blob/master/LICENSE>
14
+ <img src=https://img.shields.io/npm/l/rust-just?style=for-the-badge alt="license">
14
15
  </a>
15
- <a href=https://discord.gg/ezYScXR>
16
- <img src=https://img.shields.io/discord/695580069837406228?logo=discord alt="chat on discord">
17
- </a>
18
- <a href=mailto:casey@rodarmor.com?subject=Thanks%20for%20Just!>
19
- <img src=https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg alt="say thanks">
16
+ <a href=https://www.npmjs.com/package/rust-just>
17
+ <img src=https://img.shields.io/npm/v/rust-just?style=for-the-badge&labelColor=firebrick&color=tan&logo=npm
18
+ alt="npm version">
20
19
  </a>
21
20
  </div>
22
21
  <br>
23
22
 
24
- `just` is a handy way to save and run project-specific commands.
25
-
26
- This readme is also available as a [book](https://just.systems/man/en/).
27
-
28
- (中文文档在 [这里](https://github.com/casey/just/blob/master/README.中文.md),
29
- 快看过来!)
23
+ `rust-just` is a handy way to save and run project-specific commands.
30
24
 
31
25
  Commands, called recipes, are stored in a file called `justfile` with syntax
32
- inspired by `make`:
33
-
34
- ![screenshot](https://raw.githubusercontent.com/casey/just/master/screenshot.png)
35
-
36
- You can then run them with `just RECIPE`:
37
-
38
- ```console
39
- $ just test-all
40
- cc *.c -o main
41
- ./test --all
42
- Yay, all your tests passed!
43
- ```
44
-
45
- `just` has a ton of useful features, and many improvements over `make`:
46
-
47
- - `just` is a command runner, not a build system, so it avoids much of
48
- [`make`'s complexity and idiosyncrasies](#what-are-the-idiosyncrasies-of-make-that-just-avoids).
49
- No need for `.PHONY` recipes!
50
-
51
- - Linux, MacOS, and Windows are supported with no additional dependencies.
52
- (Although if your system doesn't have an `sh`, you'll need to
53
- [choose a different shell](#shell).)
54
-
55
- - Errors are specific and informative, and syntax errors are reported along
56
- with their source context.
57
-
58
- - Recipes can accept [command line arguments](#recipe-parameters).
59
-
60
- - Wherever possible, errors are resolved statically. Unknown recipes and
61
- circular dependencies are reported before anything runs.
62
-
63
- - `just` [loads `.env` files](#dotenv-settings), making it easy to populate
64
- environment variables.
65
-
66
- - Recipes can be [listed from the command line](#listing-available-recipes).
67
-
68
- - Command line completion scripts are
69
- [available for most popular shells](#shell-completion-scripts).
70
-
71
- - Recipes can be written in
72
- [arbitrary languages](#shebang-recipes), like Python or NodeJS.
73
-
74
- - `just` can be invoked from any subdirectory, not just the directory that
75
- contains the `justfile`.
76
-
77
- - And [much more](https://just.systems/man/en/)!
78
-
79
- If you need help with `just` please feel free to open an issue or ping me on
80
- [Discord](https://discord.gg/ezYScXR). Feature requests and bug reports are
81
- always welcome!
82
-
83
- Installation
84
- ------------
85
-
86
- ### Prerequisites
87
-
88
- `just` should run on any system with a reasonable `sh`, including Linux, MacOS,
89
- and the BSDs.
90
-
91
- On Windows, `just` works with the `sh` provided by
92
- [Git for Windows](https://git-scm.com),
93
- [GitHub Desktop](https://desktop.github.com), or
94
- [Cygwin](http://www.cygwin.com).
95
-
96
- If you'd rather not install `sh`, you can use the `shell` setting to use the
97
- shell of your choice.
98
-
99
- Like PowerShell:
100
-
101
- ```just
102
- # use PowerShell instead of sh:
103
- set shell := ["powershell.exe", "-c"]
104
-
105
- hello:
106
- Write-Host "Hello, world!"
107
- ```
108
-
109
- …or `cmd.exe`:
110
-
111
- ```just
112
- # use cmd.exe instead of sh:
113
- set shell := ["cmd.exe", "/c"]
114
-
115
- list:
116
- dir
117
- ```
118
-
119
- You can also set the shell using command-line arguments. For example, to use
120
- PowerShell, launch `just` with `--shell powershell.exe --shell-arg -c`.
121
-
122
- (PowerShell is installed by default on Windows 7 SP1 and Windows Server 2008 R2
123
- S1 and later, and `cmd.exe` is quite fiddly, so PowerShell is recommended for
124
- most Windows users.)
125
-
126
- ### Packages
127
-
128
- #### Cross-platform
129
-
130
- <table>
131
- <thead>
132
- <tr>
133
- <th>Package Manager</th>
134
- <th>Package</th>
135
- <th>Command</th>
136
- </tr>
137
- </thead>
138
- <tbody>
139
- <tr>
140
- <td><a href=https://asdf-vm.com>asdf</a></td>
141
- <td><a href=https://github.com/olofvndrhr/asdf-just>just</a></td>
142
- <td>
143
- <code>asdf plugin add just</code><br>
144
- <code>asdf install just &lt;version&gt;</code>
145
- </td>
146
- </tr>
147
- <tr>
148
- <td><a href=https://www.rust-lang.org>Cargo</a></td>
149
- <td><a href=https://crates.io/crates/just>just</a></td>
150
- <td><code>cargo install just</code></td>
151
- </tr>
152
- <tr>
153
- <td><a href=https://docs.conda.io/projects/conda/en/latest/index.html>Conda</a></td>
154
- <td><a href=https://anaconda.org/conda-forge/just>just</a></td>
155
- <td><code>conda install -c conda-forge just</code></td>
156
- </tr>
157
- <tr>
158
- <td><a href=https://brew.sh>Homebrew</a></td>
159
- <td><a href=https://formulae.brew.sh/formula/just>just</a></td>
160
- <td><code>brew install just</code></td>
161
- </tr>
162
- <tr>
163
- <td><a href=https://nixos.org/nix/>Nix</a></td>
164
- <td><a href=https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix>just</a></td>
165
- <td><code>nix-env -iA nixpkgs.just</code></td>
166
- </tr>
167
- <tr>
168
- <td><a href=https://www.npmjs.com/>npm</a></td>
169
- <td><a href=https://www.npmjs.com/package/rust-just>rust-just</a></td>
170
- <td><code>npm install rust-just</code></td>
171
- </tr>
172
- <tr>
173
- <td><a href=https://pypi.org/>PyPI</a></td>
174
- <td><a href=https://pypi.org/project/rust-just/>rust-just</a></td>
175
- <td><code>pipx install rust-just</code></td>
176
- </tr>
177
- </tbody>
178
- </table>
179
-
180
- #### BSD
181
-
182
- <table>
183
- <thead>
184
- <tr>
185
- <th>Operating System</th>
186
- <th>Package Manager</th>
187
- <th>Package</th>
188
- <th>Command</th>
189
- </tr>
190
- </thead>
191
- <tbody>
192
- <tr>
193
- <td><a href=https://www.freebsd.org>FreeBSD</a></td>
194
- <td><a href=https://www.freebsd.org/doc/handbook/pkgng-intro.html>pkg</a></td>
195
- <td><a href=https://www.freshports.org/deskutils/just/>just</a></td>
196
- <td><code>pkg install just</code></td>
197
- </tr>
198
- </tbody>
199
- </table>
200
-
201
- #### Linux
202
-
203
- <table>
204
- <thead>
205
- <tr>
206
- <th>Operating System</th>
207
- <th>Package Manager</th>
208
- <th>Package</th>
209
- <th>Command</th>
210
- </tr>
211
- </thead>
212
- <tbody>
213
- <tr>
214
- <td><a href=https://alpinelinux.org>Alpine</a></td>
215
- <td><a href=https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management>apk-tools</a></td>
216
- <td><a href=https://pkgs.alpinelinux.org/package/edge/community/x86_64/just>just</a></td>
217
- <td><code>apk add just</code></td>
218
- </tr>
219
- <tr>
220
- <td><a href=https://www.archlinux.org>Arch</a></td>
221
- <td><a href=https://wiki.archlinux.org/title/Pacman>pacman</a></td>
222
- <td><a href=https://archlinux.org/packages/extra/x86_64/just/>just</a></td>
223
- <td><code>pacman -S just</code></td>
224
- </tr>
225
- <tr>
226
- <td>
227
- <a href=https://debian.org>Debian 13 (unreleased)</a> and
228
- <a href=https://ubuntu.com>Ubuntu 24.04</a> derivatives</td>
229
- <td><a href=https://en.wikipedia.org/wiki/APT_(software)>apt</a></td>
230
- <td><a href=https://packages.debian.org/trixie/just>just</a></td>
231
- <td><code>apt install just</code></td>
232
- </tr>
233
- <tr>
234
- <td><a href=https://debian.org>Debian</a> and <a href=https://ubuntu.com>Ubuntu</a> derivatives</td>
235
- <td><a href=https://mpr.makedeb.org>MPR</a></td>
236
- <td><a href=https://mpr.makedeb.org/packages/just>just</a></td>
237
- <td>
238
- <code>git clone https://mpr.makedeb.org/just</code><br>
239
- <code>cd just</code><br>
240
- <code>makedeb -si</code>
241
- </td>
242
- </tr>
243
- <tr>
244
- <td><a href=https://debian.org>Debian</a> and <a href=https://ubuntu.com>Ubuntu</a> derivatives</td>
245
- <td><a href=https://docs.makedeb.org/prebuilt-mpr>Prebuilt-MPR</a></td>
246
- <td><a href=https://mpr.makedeb.org/packages/just>just</a></td>
247
- <td>
248
- <sup><b>You must have the <a href=https://docs.makedeb.org/prebuilt-mpr/getting-started/#setting-up-the-repository>Prebuilt-MPR set up</a> on your system in order to run this command.</b></sup><br>
249
- <code>apt install just</code>
250
- </td>
251
- </tr>
252
- <tr>
253
- <td><a href=https://getfedora.org>Fedora</a></td>
254
- <td><a href=https://dnf.readthedocs.io/en/latest/>DNF</a></td>
255
- <td><a href=https://src.fedoraproject.org/rpms/rust-just>just</a></td>
256
- <td><code>dnf install just</code></td>
257
- </tr>
258
- <tr>
259
- <td><a href=https://www.gentoo.org>Gentoo</a></td>
260
- <td><a href=https://wiki.gentoo.org/wiki/Portage>Portage</a></td>
261
- <td><a href=https://github.com/gentoo-mirror/guru/tree/master/dev-build/just>guru/dev-build/just</a></td>
262
- <td>
263
- <code>eselect repository enable guru</code><br>
264
- <code>emerge --sync guru</code><br>
265
- <code>emerge dev-build/just</code>
266
- </td>
267
- </tr>
268
- <tr>
269
- <td><a href=https://nixos.org/nixos/>NixOS</a></td>
270
- <td><a href=https://nixos.org/nix/>Nix</a></td>
271
- <td><a href=https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix>just</a></td>
272
- <td><code>nix-env -iA nixos.just</code></td>
273
- </tr>
274
- <tr>
275
- <td><a href=https://opensuse.org>openSUSE</a></td>
276
- <td><a href=https://en.opensuse.org/Portal:Zypper>Zypper</a></td>
277
- <td><a href=https://build.opensuse.org/package/show/Base:System/just>just</a></td>
278
- <td><code>zypper in just</code></td>
279
- </tr>
280
- <tr>
281
- <td><a href=https://getsol.us>Solus</a></td>
282
- <td><a href=https://getsol.us/articles/package-management/basics/en>eopkg</a></td>
283
- <td><a href=https://dev.getsol.us/source/just/>just</a></td>
284
- <td><code>eopkg install just</code></td>
285
- </tr>
286
- <tr>
287
- <td><a href=https://voidlinux.org>Void</a></td>
288
- <td><a href=https://wiki.voidlinux.org/XBPS>XBPS</a></td>
289
- <td><a href=https://github.com/void-linux/void-packages/blob/master/srcpkgs/just/template>just</a></td>
290
- <td><code>xbps-install -S just</code></td>
291
- </tr>
292
- </tbody>
293
- </table>
294
-
295
- #### Windows
296
-
297
- <table>
298
- <thead>
299
- <tr>
300
- <th>Package Manager</th>
301
- <th>Package</th>
302
- <th>Command</th>
303
- </tr>
304
- </thead>
305
- <tbody>
306
- <tr>
307
- <td><a href=https://chocolatey.org>Chocolatey</a></td>
308
- <td><a href=https://github.com/michidk/just-choco>just</a></td>
309
- <td><code>choco install just</code></td>
310
- </tr>
311
- <tr>
312
- <td><a href=https://scoop.sh>Scoop</a></td>
313
- <td><a href=https://github.com/ScoopInstaller/Main/blob/master/bucket/just.json>just</a></td>
314
- <td><code>scoop install just</code></td>
315
- </tr>
316
- <tr>
317
- <td><a href=https://learn.microsoft.com/en-us/windows/package-manager/>Windows Package Manager</a></td>
318
- <td><a href=https://github.com/microsoft/winget-pkgs/tree/master/manifests/c/Casey/Just>Casey/Just</a></td>
319
- <td><code>winget install --id Casey.Just --exact</code></td>
320
- </tr>
321
- </tbody>
322
- </table>
323
-
324
- #### macOS
325
-
326
- <table>
327
- <thead>
328
- <tr>
329
- <th>Package Manager</th>
330
- <th>Package</th>
331
- <th>Command</th>
332
- </tr>
333
- </thead>
334
- <tbody>
335
- <tr>
336
- <td><a href=https://www.macports.org>MacPorts</a></td>
337
- <td><a href=https://ports.macports.org/port/just/summary>just</a></td>
338
- <td><code>port install just</code></td>
339
- </tr>
340
- </tbody>
341
- </table>
342
-
343
- ![just package version table](https://repology.org/badge/vertical-allrepos/just.svg)
344
-
345
- ![rust:just package version table](https://repology.org/badge/vertical-allrepos/rust:just.svg)
346
-
347
- ### Pre-Built Binaries
348
-
349
- Pre-built binaries for Linux, MacOS, and Windows can be found on
350
- [the releases page](https://github.com/casey/just/releases).
351
-
352
- You can use the following command on Linux, MacOS, or Windows to download the
353
- latest release, just replace `DEST` with the directory where you'd like to put
354
- `just`:
355
-
356
- ```console
357
- curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to DEST
358
- ```
359
-
360
- For example, to install `just` to `~/bin`:
361
-
362
- ```console
363
- # create ~/bin
364
- mkdir -p ~/bin
365
-
366
- # download and extract just to ~/bin/just
367
- curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to ~/bin
368
-
369
- # add `~/bin` to the paths that your shell searches for executables
370
- # this line should be added to your shells initialization file,
371
- # e.g. `~/.bashrc` or `~/.zshrc`
372
- export PATH="$PATH:$HOME/bin"
373
-
374
- # just should now be executable
375
- just --help
376
- ```
377
-
378
- Note that `install.sh` may fail on GitHub Actions, or in other environments
379
- where many machines share IP addresses. `install.sh` calls GitHub APIs in order
380
- to determine the latest version of `just` to install, and those API calls are
381
- rate-limited on a per-IP basis. To make `install.sh` more reliable in such
382
- circumstances, pass a specific tag to install with `--tag`.
383
-
384
- ### GitHub Actions
385
-
386
- `just` can be installed on GitHub Actions in a few ways.
387
-
388
- Using package managers pre-installed on GitHub Actions runners on MacOS with
389
- `brew install just`, and on Windows with `choco install just`.
390
-
391
- With [extractions/setup-just](https://github.com/extractions/setup-just):
392
-
393
- ```yaml
394
- - uses: extractions/setup-just@v1
395
- with:
396
- just-version: 1.5.0 # optional semver specification, otherwise latest
397
- ```
398
-
399
- Or with [taiki-e/install-action](https://github.com/taiki-e/install-action):
400
-
401
- ```yaml
402
- - uses: taiki-e/install-action@just
403
- ```
404
-
405
- ### Release RSS Feed
406
-
407
- An [RSS feed](https://en.wikipedia.org/wiki/RSS) of `just` releases is available [here](https://github.com/casey/just/releases.atom).
408
-
409
- ### Node.js Installation
410
-
411
- [just-install](https://npmjs.com/package/just-install) can be used to automate
412
- installation of `just` in Node.js applications.
413
-
414
- `just` is a great, more robust alternative to npm scripts. If you want to
415
- include `just` in the dependencies of a Node.js application, `just-install`
416
- will install a local, platform-specific binary as part of the `npm install`
417
- command. This removes the need for every developer to install `just`
418
- independently using one of the processes mentioned above. After installation,
419
- the `just` command will work in npm scripts or with npx. It's great for teams
420
- who want to make the set up process for their project as easy as possible.
421
-
422
- For more information, see the
423
- [just-install README file](https://github.com/brombal/just-install#readme).
424
-
425
- Backwards Compatibility
426
- -----------------------
427
-
428
- With the release of version 1.0, `just` features a strong commitment to
429
- backwards compatibility and stability.
430
-
431
- Future releases will not introduce backwards incompatible changes that make
432
- existing `justfile`s stop working, or break working invocations of the
433
- command-line interface.
434
-
435
- This does not, however, preclude fixing outright bugs, even if doing so might
436
- break `justfiles` that rely on their behavior.
437
-
438
- There will never be a `just` 2.0. Any desirable backwards-incompatible changes
439
- will be opt-in on a per-`justfile` basis, so users may migrate at their
440
- leisure.
441
-
442
- Features that aren't yet ready for stabilization are marked as unstable and may
443
- be changed or removed at any time. Using unstable features produces an error by
444
- default, which can be suppressed with by passing the `--unstable` flag,
445
- `set unstable`, or setting the environment variable `JUST_UNSTABLE`, to any
446
- value other than `false`, `0`, or the empty string.
447
-
448
- Editor Support
449
- --------------
450
-
451
- `justfile` syntax is close enough to `make` that you may want to tell your
452
- editor to use `make` syntax highlighting for `just`.
453
-
454
- ### Vim and Neovim
455
-
456
- #### `vim-just`
457
-
458
- The [vim-just](https://github.com/NoahTheDuke/vim-just) plugin provides syntax
459
- highlighting for `justfile`s.
460
-
461
- Install it with your favorite package manager, like
462
- [Plug](https://github.com/junegunn/vim-plug):
463
-
464
- ```vim
465
- call plug#begin()
466
-
467
- Plug 'NoahTheDuke/vim-just'
468
-
469
- call plug#end()
470
- ```
471
-
472
- Or with Vim's built-in package support:
473
-
474
- ```console
475
- mkdir -p ~/.vim/pack/vendor/start
476
- cd ~/.vim/pack/vendor/start
477
- git clone https://github.com/NoahTheDuke/vim-just.git
478
- ```
479
-
480
- #### `tree-sitter-just`
481
-
482
- [tree-sitter-just](https://github.com/IndianBoy42/tree-sitter-just) is an
483
- [Nvim Treesitter](https://github.com/nvim-treesitter/nvim-treesitter) plugin
484
- for Neovim.
485
-
486
- #### Makefile Syntax Highlighting
487
-
488
- Vim's built-in makefile syntax highlighting isn't perfect for `justfile`s, but
489
- it's better than nothing. You can put the following in `~/.vim/filetype.vim`:
490
-
491
- ```vimscript
492
- if exists("did_load_filetypes")
493
- finish
494
- endif
495
-
496
- augroup filetypedetect
497
- au BufNewFile,BufRead justfile setf make
498
- augroup END
499
- ```
500
-
501
- Or add the following to an individual `justfile` to enable `make` mode on a
502
- per-file basis:
503
-
504
- ```text
505
- # vim: set ft=make :
506
- ```
507
-
508
- ### Emacs
509
-
510
- [just-mode](https://github.com/leon-barrett/just-mode.el) provides syntax
511
- highlighting and automatic indentation of `justfile`s. It is available on
512
- [MELPA](https://melpa.org/) as [just-mode](https://melpa.org/#/just-mode).
513
-
514
- [justl](https://github.com/psibi/justl.el) provides commands for executing and
515
- listing recipes.
516
-
517
- You can add the following to an individual `justfile` to enable `make` mode on
518
- a per-file basis:
519
-
520
- ```text
521
- # Local Variables:
522
- # mode: makefile
523
- # End:
524
- ```
525
-
526
- ### Visual Studio Code
527
-
528
- An extension for VS Code is [available here](https://github.com/nefrob/vscode-just).
529
-
530
- Unmaintained VS Code extensions include
531
- [skellock/vscode-just](https://github.com/skellock/vscode-just) and
532
- [sclu1034/vscode-just](https://github.com/sclu1034/vscode-just).
533
-
534
- ### JetBrains IDEs
535
-
536
- A plugin for JetBrains IDEs by [linux_china](https://github.com/linux-china) is
537
- [available here](https://plugins.jetbrains.com/plugin/18658-just).
538
-
539
- ### Kakoune
540
-
541
- Kakoune supports `justfile` syntax highlighting out of the box, thanks to
542
- TeddyDD.
543
-
544
- ### Helix
545
-
546
- [Helix](https://helix-editor.com/) supports `justfile` syntax highlighting
547
- out-of-the-box since version 23.05.
548
-
549
- ### Sublime Text
550
-
551
- The [Just package](https://github.com/nk9/just_sublime) by
552
- [nk9](https://github.com/nk9) with `just` syntax and some other tools is
553
- available on [PackageControl](https://packagecontrol.io/packages/Just).
554
-
555
- ### Micro
556
-
557
- [Micro](https://micro-editor.github.io/) supports Justfile syntax highlighting
558
- out of the box, thanks to [tomodachi94](https://github.com/tomodachi94).
559
-
560
- ### Other Editors
561
-
562
- Feel free to send me the commands necessary to get syntax highlighting working
563
- in your editor of choice so that I may include them here.
564
-
565
- Quick Start
566
- -----------
567
-
568
- See [the installation section](#installation) for how to install `just` on your
569
- computer. Try running `just --version` to make sure that it's installed
570
- correctly.
571
-
572
- For an overview of the syntax, check out
573
- [this cheatsheet](https://cheatography.com/linux-china/cheat-sheets/justfile/).
26
+ inspired by `make`
574
27
 
575
- Once `just` is installed and working, create a file named `justfile` in the
576
- root of your project with the following contents:
28
+ ## Getting Started
577
29
 
578
- ```just
579
- recipe-name:
580
- echo 'This is a recipe!'
30
+ ### Run instantly without installation
581
31
 
582
- # this is a comment
583
- another-recipe:
584
- @echo 'This is another recipe.'
585
- ```
586
-
587
- When you invoke `just` it looks for file `justfile` in the current directory
588
- and upwards, so you can invoke it from any subdirectory of your project.
589
-
590
- The search for a `justfile` is case insensitive, so any case, like `Justfile`,
591
- `JUSTFILE`, or `JuStFiLe`, will work. `just` will also look for files with the
592
- name `.justfile`, in case you'd like to hide a `justfile`.
593
-
594
- Running `just` with no arguments runs the first recipe in the `justfile`:
595
-
596
- ```console
597
- $ just
598
- echo 'This is a recipe!'
599
- This is a recipe!
600
- ```
601
-
602
- One or more arguments specify the recipe(s) to run:
603
-
604
- ```console
605
- $ just another-recipe
606
- This is another recipe.
607
- ```
608
-
609
- `just` prints each command to standard error before running it, which is why
610
- `echo 'This is a recipe!'` was printed. This is suppressed for lines starting
611
- with `@`, which is why `echo 'This is another recipe.'` was not printed.
612
-
613
- Recipes stop running if a command fails. Here `cargo publish` will only run if
614
- `cargo test` succeeds:
615
-
616
- ```just
617
- publish:
618
- cargo test
619
- # tests passed, time to publish!
620
- cargo publish
621
- ```
622
-
623
- Recipes can depend on other recipes. Here the `test` recipe depends on the
624
- `build` recipe, so `build` will run before `test`:
625
-
626
- ```just
627
- build:
628
- cc main.c foo.c bar.c -o main
629
-
630
- test: build
631
- ./test
632
-
633
- sloc:
634
- @echo "`wc -l *.c` lines of code"
635
- ```
636
-
637
- ```console
638
- $ just test
639
- cc main.c foo.c bar.c -o main
640
- ./test
641
- testing… all tests passed!
642
- ```
643
-
644
- Recipes without dependencies will run in the order they're given on the command
645
- line:
646
-
647
- ```console
648
- $ just build sloc
649
- cc main.c foo.c bar.c -o main
650
- 1337 lines of code
651
- ```
652
-
653
- Dependencies will always run first, even if they are passed after a recipe that
654
- depends on them:
655
-
656
- ```console
657
- $ just test build
658
- cc main.c foo.c bar.c -o main
659
- ./test
660
- testing… all tests passed!
661
- ```
662
-
663
- Examples
664
- --------
665
-
666
- A variety of `justfile`s can be found in the
667
- [examples directory](https://github.com/casey/just/tree/master/examples) and on
668
- [GitHub](https://github.com/search?q=path%3A**%2Fjustfile&type=code).
669
-
670
- Features
671
- --------
672
-
673
- ### The Default Recipe
674
-
675
- When `just` is invoked without a recipe, it runs the first recipe in the
676
- `justfile`. This recipe might be the most frequently run command in the
677
- project, like running the tests:
678
-
679
- ```just
680
- test:
681
- cargo test
682
- ```
683
-
684
- You can also use dependencies to run multiple recipes by default:
685
-
686
- ```just
687
- default: lint build test
688
-
689
- build:
690
- echo Building…
691
-
692
- test:
693
- echo Testing…
694
-
695
- lint:
696
- echo Linting…
697
- ```
698
-
699
- If no recipe makes sense as the default recipe, you can add a recipe to the
700
- beginning of your `justfile` that lists the available recipes:
701
-
702
- ```just
703
- default:
704
- just --list
705
- ```
706
-
707
- ### Listing Available Recipes
708
-
709
- Recipes can be listed in alphabetical order with `just --list`:
710
-
711
- ```console
712
- $ just --list
713
- Available recipes:
714
- build
715
- test
716
- deploy
717
- lint
718
- ```
719
-
720
- Recipes in [submodules](#modules1190) can be listed with `just --list PATH`,
721
- where `PATH` is a space- or `::`-separated module path:
722
-
723
- ```
724
- $ cat justfile
725
- mod foo
726
- $ cat foo.just
727
- mod bar
728
- $ cat bar.just
729
- baz:
730
- $ just foo bar
731
- Available recipes:
732
- baz
733
- $ just foo::bar
734
- Available recipes:
735
- baz
736
- ```
737
-
738
- `just --summary` is more concise:
739
-
740
- ```console
741
- $ just --summary
742
- build test deploy lint
743
- ```
744
-
745
- Pass `--unsorted` to print recipes in the order they appear in the `justfile`:
746
-
747
- ```just
748
- test:
749
- echo 'Testing!'
750
-
751
- build:
752
- echo 'Building!'
753
- ```
754
-
755
- ```console
756
- $ just --list --unsorted
757
- Available recipes:
758
- test
759
- build
760
- ```
761
-
762
- ```console
763
- $ just --summary --unsorted
764
- test build
765
- ```
766
-
767
- If you'd like `just` to default to listing the recipes in the `justfile`, you
768
- can use this as your default recipe:
769
-
770
- ```just
771
- default:
772
- @just --list
773
- ```
32
+ The recommended way to run `rust-just` without installing it on your system is by using <a href="https://www.npmjs.com/package/npx">`npx`</a>:
774
33
 
775
- Note that you may need to add `--justfile {{justfile()}}` to the line above.
776
- Without it, if you executed `just -f /some/distant/justfile -d .` or
777
- `just -f ./non-standard-justfile`, the plain `just --list` inside the recipe
778
- would not necessarily use the file you provided. It would try to find a
779
- justfile in your current path, maybe even resulting in a `No justfile found`
780
- error.
781
-
782
- The heading text can be customized with `--list-heading`:
783
-
784
- ```console
785
- $ just --list --list-heading $'Cool stuff…\n'
786
- Cool stuff…
787
- test
788
- build
789
- ```
790
-
791
- And the indentation can be customized with `--list-prefix`:
792
-
793
- ```console
794
- $ just --list --list-prefix ····
795
- Available recipes:
796
- ····test
797
- ····build
798
- ```
799
-
800
- The argument to `--list-heading` replaces both the heading and the newline
801
- following it, so it should contain a newline if non-empty. It works this way so
802
- you can suppress the heading line entirely by passing the empty string:
803
-
804
- ```console
805
- $ just --list --list-heading ''
806
- test
807
- build
808
- ```
809
-
810
- ### Invoking Multiple Recipes
811
-
812
- Multiple recipes may be invoked on the command line at once:
813
-
814
- ```just
815
- build:
816
- make web
817
-
818
- serve:
819
- python3 -m http.server -d out 8000
820
- ```
821
-
822
- ```console
823
- $ just build serve
824
- make web
825
- python3 -m http.server -d out 8000
826
- ```
827
-
828
- Keep in mind that recipes with parameters will swallow arguments, even if they
829
- match the names of other recipes:
830
-
831
- ```just
832
- build project:
833
- make {{project}}
834
-
835
- serve:
836
- python3 -m http.server -d out 8000
837
- ```
838
-
839
- ```console
840
- $ just build serve
841
- make: *** No rule to make target `serve'. Stop.
842
- ```
843
-
844
- The `--one` flag can be used to restrict command-line invocations to a single
845
- recipe:
846
-
847
- ```console
848
- $ just --one build serve
849
- error: Expected 1 command-line recipe invocation but found 2.
850
- ```
851
-
852
- ### Working Directory
853
-
854
- By default, recipes run with the working directory set to the directory that
855
- contains the `justfile`.
856
-
857
- The `[no-cd]` attribute can be used to make recipes run with the working
858
- directory set to directory in which `just` was invoked.
859
-
860
- ```just
861
- @foo:
862
- pwd
863
-
864
- [no-cd]
865
- @bar:
866
- pwd
867
- ```
868
-
869
- ```console
870
- $ cd subdir
871
- $ just foo
872
- /
873
- $ just bar
874
- /subdir
875
34
  ```
876
-
877
- You can override working directory with `set working-directory := '…'`, whose value
878
- is relative to the default working directory.
879
-
880
- ```just
881
- set working-directory := 'bar'
882
-
883
- @foo:
884
- pwd
885
- ```
886
-
887
- ```console
888
- $ pwd
889
- /home/bob
890
- $ just foo
891
- /home/bob/bar
892
- ```
893
-
894
- ### Aliases
895
-
896
- Aliases allow recipes to be invoked on the command line with alternative names:
897
-
898
- ```just
899
- alias b := build
900
-
901
- build:
902
- echo 'Building!'
903
- ```
904
-
905
- ```console
906
- $ just b
907
- echo 'Building!'
908
- Building!
909
- ```
910
-
911
- ### Settings
912
-
913
- Settings control interpretation and execution. Each setting may be specified at
914
- most once, anywhere in the `justfile`.
915
-
916
- For example:
917
-
918
- ```just
919
- set shell := ["zsh", "-cu"]
920
-
921
- foo:
922
- # this line will be run as `zsh -cu 'ls **/*.txt'`
923
- ls **/*.txt
35
+ ~/$ npx rust-just@latest [OPTIONS] [ARGUMENTS]...
924
36
  ```
925
37
 
926
- #### Table of Settings
38
+ It will run the most recent version of `rust-just`.
927
39
 
928
- | Name | Value | Default | Description |
929
- |------|-------|---------|-------------|
930
- | `allow-duplicate-recipes` | boolean | `false` | Allow recipes appearing later in a `justfile` to override earlier recipes with the same name. |
931
- | `allow-duplicate-variables` | boolean | `false` | Allow variables appearing later in a `justfile` to override earlier variables with the same name. |
932
- | `dotenv-filename` | string | - | Load a `.env` file with a custom name, if present. |
933
- | `dotenv-load` | boolean | `false` | Load a `.env` file, if present. |
934
- | `dotenv-path` | string | - | Load a `.env` file from a custom path and error if not present. Overrides `dotenv-filename`. |
935
- | `dotenv-required` | boolean | `false` | Error if a `.env` file isn't found. |
936
- | `export` | boolean | `false` | Export all variables as environment variables. |
937
- | `fallback` | boolean | `false` | Search `justfile` in parent directory if the first recipe on the command line is not found. |
938
- | `ignore-comments` | boolean | `false` | Ignore recipe lines beginning with `#`. |
939
- | `positional-arguments` | boolean | `false` | Pass positional arguments. |
940
- | `script-interpreter`<sup>1.33.0</sup> | `[COMMAND, ARGS…]` | `['sh', '-eu']` | Set command used to invoke recipes with empty `[script]` attribute. |
941
- | `shell` | `[COMMAND, ARGS…]` | - | Set command used to invoke recipes and evaluate backticks. |
942
- | `tempdir` | string | - | Create temporary directories in `tempdir` instead of the system default temporary directory. |
943
- | `unstable`<sup>1.31.0</sup> | boolean | `false` | Enable unstable features. |
944
- | `windows-powershell` | boolean | `false` | Use PowerShell on Windows as default shell. (Deprecated. Use `windows-shell` instead. |
945
- | `windows-shell` | `[COMMAND, ARGS…]` | - | Set the command used to invoke recipes and evaluate backticks. |
946
- | `working-directory`<sup>1.33.0</sup> | string | - | Set the working directory for recipes and backticks, relative to the default working directory. |
40
+ ### Installation as global dependency
947
41
 
948
- Boolean settings can be written as:
42
+ `rust-just` could also be installed as a global dependency:
949
43
 
950
- ```justfile
951
- set NAME
952
44
  ```
953
-
954
- Which is equivalent to:
955
-
956
- ```justfile
957
- set NAME := true
45
+ ~/$ npm install -g rust-just
958
46
  ```
959
47
 
960
- #### Allow Duplicate Recipes
48
+ and then run with:
961
49
 
962
- If `allow-duplicate-recipes` is set to `true`, defining multiple recipes with
963
- the same name is not an error and the last definition is used. Defaults to
964
- `false`.
965
-
966
- ```just
967
- set allow-duplicate-recipes
968
-
969
- @foo:
970
- echo foo
971
-
972
- @foo:
973
- echo bar
974
50
  ```
975
-
976
- ```console
977
- $ just foo
978
- bar
51
+ ~/$ rust-just [OPTIONS] [ARGUMENTS]...
979
52
  ```
980
53
 
981
- #### Allow Duplicate Variables
54
+ ### Installation as local dependency
982
55
 
983
- If `allow-duplicate-variables` is set to `true`, defining multiple variables
984
- with the same name is not an error and the last definition is used. Defaults to
985
- `false`.
986
-
987
- ```just
988
- set allow-duplicate-variables
989
-
990
- a := "foo"
991
- a := "bar"
992
-
993
- @foo:
994
- echo $a
995
56
  ```
996
-
997
- ```console
998
- $ just foo
999
- bar
57
+ ~/$ npm install rust-just
1000
58
  ```
1001
59
 
1002
- #### Dotenv Settings
1003
-
1004
- If any of `dotenv-load`, `dotenv-filename`, `dotenv-path`, or `dotenv-required`
1005
- are set, `just` will try to load environment variables from a file.
1006
-
1007
- If `dotenv-path` is set, `just` will look for a file at the given path, which
1008
- may be absolute, or relative to the working directory.
1009
-
1010
- The command-line option `--dotenv-path`, short form `-E`, can be used to set or
1011
- override `dotenv-path` at runtime.
1012
-
1013
- If `dotenv-filename` is set `just` will look for a file at the given path,
1014
- relative to the working directory and each of its ancestors.
1015
-
1016
- If `dotenv-filename` is not set, but `dotenv-load` or `dotenv-required` are
1017
- set, just will look for a file named `.env`, relative to the working directory
1018
- and each of its ancestors.
1019
-
1020
- `dotenv-filename` and `dotenv-path` are similar, but `dotenv-path` is only
1021
- checked relative to the working directory, whereas `dotenv-filename` is checked
1022
- relative to the working directory and each of its ancestors.
1023
-
1024
- It is not an error if an environment file is not found, unless
1025
- `dotenv-required` is set.
1026
-
1027
- The loaded variables are environment variables, not `just` variables, and so
1028
- must be accessed using `$VARIABLE_NAME` in recipes and backticks.
1029
-
1030
- For example, if your `.env` file contains:
1031
-
1032
- ```console
1033
- # a comment, will be ignored
1034
- DATABASE_ADDRESS=localhost:6379
1035
- SERVER_PORT=1337
1036
- ```
1037
-
1038
- And your `justfile` contains:
1039
-
1040
- ```just
1041
- set dotenv-load
1042
-
1043
- serve:
1044
- @echo "Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…"
1045
- ./server --database $DATABASE_ADDRESS --port $SERVER_PORT
1046
- ```
1047
-
1048
- `just serve` will output:
1049
-
1050
- ```console
1051
- $ just serve
1052
- Starting server with database localhost:6379 on port 1337…
1053
- ./server --database $DATABASE_ADDRESS --port $SERVER_PORT
1054
- ```
1055
-
1056
- #### Export
1057
-
1058
- The `export` setting causes all `just` variables to be exported as environment
1059
- variables. Defaults to `false`.
1060
-
1061
- ```just
1062
- set export
1063
-
1064
- a := "hello"
1065
-
1066
- @foo b:
1067
- echo $a
1068
- echo $b
1069
- ```
1070
-
1071
- ```console
1072
- $ just foo goodbye
1073
- hello
1074
- goodbye
1075
- ```
1076
-
1077
- #### Positional Arguments
1078
-
1079
- If `positional-arguments` is `true`, recipe arguments will be passed as
1080
- positional arguments to commands. For linewise recipes, argument `$0` will be
1081
- the name of the recipe.
1082
-
1083
- For example, running this recipe:
1084
-
1085
- ```just
1086
- set positional-arguments
1087
-
1088
- @foo bar:
1089
- echo $0
1090
- echo $1
1091
- ```
1092
-
1093
- Will produce the following output:
1094
-
1095
- ```console
1096
- $ just foo hello
1097
- foo
1098
- hello
1099
- ```
1100
-
1101
- When using an `sh`-compatible shell, such as `bash` or `zsh`, `$@` expands to
1102
- the positional arguments given to the recipe, starting from one. When used
1103
- within double quotes as `"$@"`, arguments including whitespace will be passed
1104
- on as if they were double-quoted. That is, `"$@"` is equivalent to `"$1" "$2"`…
1105
- When there are no positional parameters, `"$@"` and `$@` expand to nothing
1106
- (i.e., they are removed).
1107
-
1108
- This example recipe will print arguments one by one on separate lines:
1109
-
1110
- ```just
1111
- set positional-arguments
1112
-
1113
- @test *args='':
1114
- bash -c 'while (( "$#" )); do echo - $1; shift; done' -- "$@"
1115
- ```
1116
-
1117
- Running it with _two_ arguments:
1118
-
1119
- ```console
1120
- $ just test foo "bar baz"
1121
- - foo
1122
- - bar baz
1123
- ```
1124
-
1125
- Positional arguments may also be turned on on a per-recipe basis with the
1126
- `[positional-arguments]` attribute<sup>1.29.0</sup>:
1127
-
1128
- ```just
1129
- [positional-arguments]
1130
- @foo bar:
1131
- echo $0
1132
- echo $1
1133
- ```
1134
-
1135
- Note that PowerShell does not handle positional arguments in the same way as
1136
- other shells, so turning on positional arguments will likely break recipes that
1137
- use PowerShell.
1138
-
1139
- #### Shell
1140
-
1141
- The `shell` setting controls the command used to invoke recipe lines and
1142
- backticks. Shebang recipes are unaffected. The default shell is `sh -cu`.
1143
-
1144
- ```just
1145
- # use python3 to execute recipe lines and backticks
1146
- set shell := ["python3", "-c"]
1147
-
1148
- # use print to capture result of evaluation
1149
- foos := `print("foo" * 4)`
1150
-
1151
- foo:
1152
- print("Snake snake snake snake.")
1153
- print("{{foos}}")
1154
- ```
1155
-
1156
- `just` passes the command to be executed as an argument. Many shells will need
1157
- an additional flag, often `-c`, to make them evaluate the first argument.
1158
-
1159
- ##### Windows Shell
1160
-
1161
- `just` uses `sh` on Windows by default. To use a different shell on Windows,
1162
- use `windows-shell`:
1163
-
1164
- ```just
1165
- set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
1166
-
1167
- hello:
1168
- Write-Host "Hello, world!"
1169
- ```
1170
-
1171
- See
1172
- [powershell.just](https://github.com/casey/just/blob/master/examples/powershell.just)
1173
- for a justfile that uses PowerShell on all platforms.
1174
-
1175
- ##### Windows PowerShell
1176
-
1177
- *`set windows-powershell` uses the legacy `powershell.exe` binary, and is no
1178
- longer recommended. See the `windows-shell` setting above for a more flexible
1179
- way to control which shell is used on Windows.*
1180
-
1181
- `just` uses `sh` on Windows by default. To use `powershell.exe` instead, set
1182
- `windows-powershell` to true.
1183
-
1184
- ```just
1185
- set windows-powershell := true
1186
-
1187
- hello:
1188
- Write-Host "Hello, world!"
1189
- ```
1190
-
1191
- ##### Python 3
1192
-
1193
- ```just
1194
- set shell := ["python3", "-c"]
1195
- ```
1196
-
1197
- ##### Bash
1198
-
1199
- ```just
1200
- set shell := ["bash", "-uc"]
1201
- ```
1202
-
1203
- ##### Z Shell
1204
-
1205
- ```just
1206
- set shell := ["zsh", "-uc"]
1207
- ```
1208
-
1209
- ##### Fish
1210
-
1211
- ```just
1212
- set shell := ["fish", "-c"]
1213
- ```
1214
-
1215
- ##### Nushell
1216
-
1217
- ```just
1218
- set shell := ["nu", "-c"]
1219
- ```
1220
-
1221
- If you want to change the default table mode to `light`:
1222
-
1223
- ```just
1224
- set shell := ['nu', '-m', 'light', '-c']
1225
- ```
1226
-
1227
- *[Nushell](https://github.com/nushell/nushell) was written in Rust, and **has
1228
- cross-platform support for Windows / macOS and Linux**.*
1229
-
1230
- ### Documentation Comments
1231
-
1232
- Comments immediately preceding a recipe will appear in `just --list`:
1233
-
1234
- ```just
1235
- # build stuff
1236
- build:
1237
- ./bin/build
1238
-
1239
- # test stuff
1240
- test:
1241
- ./bin/test
1242
- ```
1243
-
1244
- ```console
1245
- $ just --list
1246
- Available recipes:
1247
- build # build stuff
1248
- test # test stuff
1249
- ```
1250
-
1251
- The `[doc]` attribute can be used to set or suppress a recipe's doc comment:
1252
-
1253
- ```just
1254
- # This comment won't appear
1255
- [doc('Build stuff')]
1256
- build:
1257
- ./bin/build
1258
-
1259
- # This one won't either
1260
- [doc]
1261
- test:
1262
- ./bin/test
1263
- ```
1264
-
1265
- ```console
1266
- $ just --list
1267
- Available recipes:
1268
- build # Build stuff
1269
- test
1270
- ```
1271
-
1272
- ### Variables and Substitution
1273
-
1274
- Variables, strings, concatenation, path joining, and substitution using `{{…}}`
1275
- are supported:
1276
-
1277
- ```just
1278
- tmpdir := `mktemp -d`
1279
- version := "0.2.7"
1280
- tardir := tmpdir / "awesomesauce-" + version
1281
- tarball := tardir + ".tar.gz"
1282
-
1283
- publish:
1284
- rm -f {{tarball}}
1285
- mkdir {{tardir}}
1286
- cp README.md *.c {{tardir}}
1287
- tar zcvf {{tarball}} {{tardir}}
1288
- scp {{tarball}} me@server.com:release/
1289
- rm -rf {{tarball}} {{tardir}}
1290
- ```
1291
-
1292
- #### Joining Paths
1293
-
1294
- The `/` operator can be used to join two strings with a slash:
1295
-
1296
- ```just
1297
- foo := "a" / "b"
1298
- ```
1299
-
1300
- ```
1301
- $ just --evaluate foo
1302
- a/b
1303
- ```
1304
-
1305
- Note that a `/` is added even if one is already present:
1306
-
1307
- ```just
1308
- foo := "a/"
1309
- bar := foo / "b"
1310
- ```
1311
-
1312
- ```
1313
- $ just --evaluate bar
1314
- a//b
1315
- ```
1316
-
1317
- Absolute paths can also be constructed<sup>1.5.0</sup>:
1318
-
1319
- ```just
1320
- foo := / "b"
1321
- ```
1322
-
1323
- ```
1324
- $ just --evaluate foo
1325
- /b
1326
- ```
1327
-
1328
- The `/` operator uses the `/` character, even on Windows. Thus, using the `/`
1329
- operator should be avoided with paths that use universal naming convention
1330
- (UNC), i.e., those that start with `\?`, since forward slashes are not
1331
- supported with UNC paths.
1332
-
1333
- #### Escaping `{{`
1334
-
1335
- To write a recipe containing `{{`, use `{{{{`:
1336
-
1337
- ```just
1338
- braces:
1339
- echo 'I {{{{LOVE}} curly braces!'
1340
- ```
1341
-
1342
- (An unmatched `}}` is ignored, so it doesn't need to be escaped.)
1343
-
1344
- Another option is to put all the text you'd like to escape inside of an
1345
- interpolation:
1346
-
1347
- ```just
1348
- braces:
1349
- echo '{{'I {{LOVE}} curly braces!'}}'
1350
- ```
1351
-
1352
- Yet another option is to use `{{ "{{" }}`:
1353
-
1354
- ```just
1355
- braces:
1356
- echo 'I {{ "{{" }}LOVE}} curly braces!'
1357
- ```
1358
-
1359
- ### Strings
1360
-
1361
- Double-quoted strings support escape sequences:
1362
-
1363
- ```just
1364
- carriage-return := "\r"
1365
- double-quote := "\""
1366
- newline := "\n"
1367
- no-newline := "\
1368
- "
1369
- slash := "\\"
1370
- tab := "\t"
1371
- unicode-codepoint := "\u{1F916}"
1372
- ```
1373
-
1374
- ```console
1375
- $ just --evaluate
1376
- "arriage-return := "
1377
- double-quote := """
1378
- newline := "
1379
- "
1380
- no-newline := ""
1381
- slash := "\"
1382
- tab := " "
1383
- unicode-codepoint := "🤖"
1384
- ```
1385
-
1386
- The unicode character escape sequence `\u{…}`<sup>1.36.0</sup> accepts up to
1387
- six hex digits.
1388
-
1389
- Strings may contain line breaks:
1390
-
1391
- ```just
1392
- single := '
1393
- hello
1394
- '
1395
-
1396
- double := "
1397
- goodbye
1398
- "
1399
- ```
1400
-
1401
- Single-quoted strings do not recognize escape sequences:
1402
-
1403
- ```just
1404
- escapes := '\t\n\r\"\\'
1405
- ```
1406
-
1407
- ```console
1408
- $ just --evaluate
1409
- escapes := "\t\n\r\"\\"
1410
- ```
1411
-
1412
- Indented versions of both single- and double-quoted strings, delimited by
1413
- triple single- or double-quotes, are supported. Indented string lines are
1414
- stripped of a leading line break, and leading whitespace common to all
1415
- non-blank lines:
1416
-
1417
- ```just
1418
- # this string will evaluate to `foo\nbar\n`
1419
- x := '''
1420
- foo
1421
- bar
1422
- '''
1423
-
1424
- # this string will evaluate to `abc\n wuv\nxyz\n`
1425
- y := """
1426
- abc
1427
- wuv
1428
- xyz
1429
- """
1430
- ```
1431
-
1432
- Similar to unindented strings, indented double-quoted strings process escape
1433
- sequences, and indented single-quoted strings ignore escape sequences. Escape
1434
- sequence processing takes place after unindentation. The unindentation
1435
- algorithm does not take escape-sequence produced whitespace or newlines into
1436
- account.
1437
-
1438
- Strings prefixed with `x` are shell expanded<sup>1.27.0</sup>:
1439
-
1440
- ```justfile
1441
- foobar := x'~/$FOO/${BAR}'
1442
- ```
1443
-
1444
- | Value | Replacement |
1445
- |------|-------------|
1446
- | `$VAR` | value of environment variable `VAR` |
1447
- | `${VAR}` | value of environment variable `VAR` |
1448
- | `${VAR:-DEFAULT}` | value of environment variable `VAR`, or `DEFAULT` if `VAR` is not set |
1449
- | Leading `~` | path to current user's home directory |
1450
- | Leading `~USER` | path to `USER`'s home directory |
1451
-
1452
- This expansion is performed at compile time, so variables from `.env` files and
1453
- exported `just` variables cannot be used. However, this allows shell expanded
1454
- strings to be used in places like settings and import paths, which cannot
1455
- depend on `just` variables and `.env` files.
1456
-
1457
- ### Ignoring Errors
1458
-
1459
- Normally, if a command returns a non-zero exit status, execution will stop. To
1460
- continue execution after a command, even if it fails, prefix the command with
1461
- `-`:
1462
-
1463
- ```just
1464
- foo:
1465
- -cat foo
1466
- echo 'Done!'
1467
- ```
1468
-
1469
- ```console
1470
- $ just foo
1471
- cat foo
1472
- cat: foo: No such file or directory
1473
- echo 'Done!'
1474
- Done!
1475
- ```
1476
-
1477
- ### Functions
1478
-
1479
- `just` provides a few built-in functions that might be useful when writing
1480
- recipes.
1481
-
1482
- All functions ending in `_directory` can be abbreviated to `_dir`. So
1483
- `home_directory()` can also be written as `home_dir()`. In addition,
1484
- `invocation_directory_native()` can be abbreviated to
1485
- `invocation_dir_native()`.
1486
-
1487
- #### System Information
1488
-
1489
- - `arch()` — Instruction set architecture. Possible values are: `"aarch64"`,
1490
- `"arm"`, `"asmjs"`, `"hexagon"`, `"mips"`, `"msp430"`, `"powerpc"`,
1491
- `"powerpc64"`, `"s390x"`, `"sparc"`, `"wasm32"`, `"x86"`, `"x86_64"`, and
1492
- `"xcore"`.
1493
- - `num_cpus()`<sup>1.15.0</sup> - Number of logical CPUs.
1494
- - `os()` — Operating system. Possible values are: `"android"`, `"bitrig"`,
1495
- `"dragonfly"`, `"emscripten"`, `"freebsd"`, `"haiku"`, `"ios"`, `"linux"`,
1496
- `"macos"`, `"netbsd"`, `"openbsd"`, `"solaris"`, and `"windows"`.
1497
- - `os_family()` — Operating system family; possible values are: `"unix"` and
1498
- `"windows"`.
1499
-
1500
- For example:
1501
-
1502
- ```just
1503
- system-info:
1504
- @echo "This is an {{arch()}} machine".
1505
- ```
1506
-
1507
- ```console
1508
- $ just system-info
1509
- This is an x86_64 machine
1510
- ```
1511
-
1512
- The `os_family()` function can be used to create cross-platform `justfile`s
1513
- that work on various operating systems. For an example, see
1514
- [cross-platform.just](https://github.com/casey/just/blob/master/examples/cross-platform.just)
1515
- file.
1516
-
1517
- #### External Commands
1518
-
1519
- - `shell(command, args...)`<sup>1.27.0</sup> returns the standard output of shell script
1520
- `command` with zero or more positional arguments `args`. The shell used to
1521
- interpret `command` is the same shell that is used to evaluate recipe lines,
1522
- and can be changed with `set shell := […]`.
1523
-
1524
- `command` is passed as the first argument, so if the command is `'echo $@'`,
1525
- the full command line, with the default shell command `shell -cu` and `args`
1526
- `'foo'` and `'bar'` will be:
1527
-
1528
- ```
1529
- 'shell' '-cu' 'echo $@' 'echo $@' 'foo' 'bar'
1530
- ```
1531
-
1532
- This is so that `$@` works as expected, and `$1` refers to the first
1533
- argument. `$@` does not include the first positional argument, which is
1534
- expected to be the name of the program being run.
1535
-
1536
- ```just
1537
- # arguments can be variables or expressions
1538
- file := '/sys/class/power_supply/BAT0/status'
1539
- bat0stat := shell('cat $1', file)
1540
-
1541
- # commands can be variables or expressions
1542
- command := 'wc -l'
1543
- output := shell(command + ' "$1"', 'main.c')
1544
-
1545
- # arguments referenced by the shell command must be used
1546
- empty := shell('echo', 'foo')
1547
- full := shell('echo $1', 'foo')
1548
- error := shell('echo $1')
1549
- ```
1550
-
1551
- ```just
1552
- # Using python as the shell. Since `python -c` sets `sys.argv[0]` to `'-c'`,
1553
- # the first "real" positional argument will be `sys.argv[2]`.
1554
- set shell := ["python3", "-c"]
1555
- olleh := shell('import sys; print(sys.argv[2][::-1])', 'hello')
1556
- ```
1557
-
1558
- #### Environment Variables
1559
-
1560
- - `env_var(key)` — Retrieves the environment variable with name `key`, aborting
1561
- if it is not present.
1562
-
1563
- ```just
1564
- home_dir := env_var('HOME')
1565
-
1566
- test:
1567
- echo "{{home_dir}}"
1568
- ```
1569
-
1570
- ```console
1571
- $ just
1572
- /home/user1
1573
- ```
1574
-
1575
- - `env_var_or_default(key, default)` — Retrieves the environment variable with
1576
- name `key`, returning `default` if it is not present.
1577
- - `env(key)`<sup>1.15.0</sup> — Alias for `env_var(key)`.
1578
- - `env(key, default)`<sup>1.15.0</sup> — Alias for `env_var_or_default(key, default)`.
1579
-
1580
- #### Invocation Information
1581
-
1582
- - `is_dependency()` - Returns the string `true` if the current recipe is being
1583
- run as a dependency of another recipe, rather than being run directly,
1584
- otherwise returns the string `false`.
1585
-
1586
- #### Invocation Directory
1587
-
1588
- - `invocation_directory()` - Retrieves the absolute path to the current
1589
- directory when `just` was invoked, before `just` changed it (chdir'd) prior
1590
- to executing commands. On Windows, `invocation_directory()` uses `cygpath` to
1591
- convert the invocation directory to a Cygwin-compatible `/`-separated path.
1592
- Use `invocation_directory_native()` to return the verbatim invocation
1593
- directory on all platforms.
1594
-
1595
- For example, to call `rustfmt` on files just under the "current directory"
1596
- (from the user/invoker's perspective), use the following rule:
1597
-
1598
- ```just
1599
- rustfmt:
1600
- find {{invocation_directory()}} -name \*.rs -exec rustfmt {} \;
1601
- ```
1602
-
1603
- Alternatively, if your command needs to be run from the current directory, you
1604
- could use (e.g.):
1605
-
1606
- ```just
1607
- build:
1608
- cd {{invocation_directory()}}; ./some_script_that_needs_to_be_run_from_here
1609
- ```
1610
-
1611
- - `invocation_directory_native()` - Retrieves the absolute path to the current
1612
- directory when `just` was invoked, before `just` changed it (chdir'd) prior
1613
- to executing commands.
1614
-
1615
- #### Justfile and Justfile Directory
1616
-
1617
- - `justfile()` - Retrieves the path of the current `justfile`.
1618
-
1619
- - `justfile_directory()` - Retrieves the path of the parent directory of the
1620
- current `justfile`.
1621
-
1622
- For example, to run a command relative to the location of the current
1623
- `justfile`:
1624
-
1625
- ```just
1626
- script:
1627
- {{justfile_directory()}}/scripts/some_script
1628
- ```
1629
-
1630
- #### Source and Source Directory
1631
-
1632
- - `source_file()`<sup>1.27.0</sup> - Retrieves the path of the current source file.
1633
-
1634
- - `source_directory()`<sup>1.27.0</sup> - Retrieves the path of the parent directory of the
1635
- current source file.
1636
-
1637
- `source_file()` and `source_directory()` behave the same as `justfile()` and
1638
- `justfile_directory()` in the root `justfile`, but will return the path and
1639
- directory, respectively, of the current `import` or `mod` source file when
1640
- called from within an import or submodule.
1641
-
1642
- #### Just Executable
1643
-
1644
- - `just_executable()` - Absolute path to the `just` executable.
1645
-
1646
- For example:
1647
-
1648
- ```just
1649
- executable:
1650
- @echo The executable is at: {{just_executable()}}
1651
- ```
1652
-
1653
- ```console
1654
- $ just
1655
- The executable is at: /bin/just
1656
- ```
1657
-
1658
- #### Just Process ID
1659
-
1660
- - `just_pid()` - Process ID of the `just` executable.
1661
-
1662
- For example:
1663
-
1664
- ```just
1665
- pid:
1666
- @echo The process ID is: {{ just_pid() }}
1667
- ```
1668
-
1669
- ```console
1670
- $ just
1671
- The process ID is: 420
1672
- ```
1673
-
1674
- #### String Manipulation
1675
-
1676
- - `append(suffix, s)`<sup>1.27.0</sup> Append `suffix` to whitespace-separated
1677
- strings in `s`. `append('/src', 'foo bar baz')` → `'foo/src bar/src baz/src'`
1678
- - `prepend(prefix, s)`<sup>1.27.0</sup> Prepend `prefix` to
1679
- whitespace-separated strings in `s`. `prepend('src/', 'foo bar baz')` →
1680
- `'src/foo src/bar src/baz'`
1681
- - `encode_uri_component(s)`<sup>1.27.0</sup> - Percent-encode characters in `s`
1682
- except `[A-Za-z0-9_.!~*'()-]`, matching the behavior of the
1683
- [JavaScript `encodeURIComponent` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).
1684
- - `quote(s)` - Replace all single quotes with `'\''` and prepend and append
1685
- single quotes to `s`. This is sufficient to escape special characters for
1686
- many shells, including most Bourne shell descendants.
1687
- - `replace(s, from, to)` - Replace all occurrences of `from` in `s` to `to`.
1688
- - `replace_regex(s, regex, replacement)` - Replace all occurrences of `regex`
1689
- in `s` to `replacement`. Regular expressions are provided by the
1690
- [Rust `regex` crate](https://docs.rs/regex/latest/regex/). See the
1691
- [syntax documentation](https://docs.rs/regex/latest/regex/#syntax) for usage
1692
- examples. Capture groups are supported. The `replacement` string uses
1693
- [Replacement string syntax](https://docs.rs/regex/latest/regex/struct.Regex.html#replacement-string-syntax).
1694
- - `trim(s)` - Remove leading and trailing whitespace from `s`.
1695
- - `trim_end(s)` - Remove trailing whitespace from `s`.
1696
- - `trim_end_match(s, pat)` - Remove suffix of `s` matching `pat`.
1697
- - `trim_end_matches(s, pat)` - Repeatedly remove suffixes of `s` matching
1698
- `pat`.
1699
- - `trim_start(s)` - Remove leading whitespace from `s`.
1700
- - `trim_start_match(s, pat)` - Remove prefix of `s` matching `pat`.
1701
- - `trim_start_matches(s, pat)` - Repeatedly remove prefixes of `s` matching
1702
- `pat`.
1703
-
1704
- #### Case Conversion
1705
-
1706
- - `capitalize(s)`<sup>1.7.0</sup> - Convert first character of `s` to uppercase
1707
- and the rest to lowercase.
1708
- - `kebabcase(s)`<sup>1.7.0</sup> - Convert `s` to `kebab-case`.
1709
- - `lowercamelcase(s)`<sup>1.7.0</sup> - Convert `s` to `lowerCamelCase`.
1710
- - `lowercase(s)` - Convert `s` to lowercase.
1711
- - `shoutykebabcase(s)`<sup>1.7.0</sup> - Convert `s` to `SHOUTY-KEBAB-CASE`.
1712
- - `shoutysnakecase(s)`<sup>1.7.0</sup> - Convert `s` to `SHOUTY_SNAKE_CASE`.
1713
- - `snakecase(s)`<sup>1.7.0</sup> - Convert `s` to `snake_case`.
1714
- - `titlecase(s)`<sup>1.7.0</sup> - Convert `s` to `Title Case`.
1715
- - `uppercamelcase(s)`<sup>1.7.0</sup> - Convert `s` to `UpperCamelCase`.
1716
- - `uppercase(s)` - Convert `s` to uppercase.
1717
-
1718
- #### Path Manipulation
1719
-
1720
- ##### Fallible
1721
-
1722
- - `absolute_path(path)` - Absolute path to relative `path` in the working
1723
- directory. `absolute_path("./bar.txt")` in directory `/foo` is
1724
- `/foo/bar.txt`.
1725
- - `canonicalize(path)`<sup>1.24.0</sup> - Canonicalize `path` by resolving symlinks and removing
1726
- `.`, `..`, and extra `/`s where possible.
1727
- - `extension(path)` - Extension of `path`. `extension("/foo/bar.txt")` is
1728
- `txt`.
1729
- - `file_name(path)` - File name of `path` with any leading directory components
1730
- removed. `file_name("/foo/bar.txt")` is `bar.txt`.
1731
- - `file_stem(path)` - File name of `path` without extension.
1732
- `file_stem("/foo/bar.txt")` is `bar`.
1733
- - `parent_directory(path)` - Parent directory of `path`.
1734
- `parent_directory("/foo/bar.txt")` is `/foo`.
1735
- - `without_extension(path)` - `path` without extension.
1736
- `without_extension("/foo/bar.txt")` is `/foo/bar`.
1737
-
1738
- These functions can fail, for example if a path does not have an extension,
1739
- which will halt execution.
1740
-
1741
- ##### Infallible
1742
-
1743
- - `clean(path)` - Simplify `path` by removing extra path separators,
1744
- intermediate `.` components, and `..` where possible. `clean("foo//bar")` is
1745
- `foo/bar`, `clean("foo/..")` is `.`, `clean("foo/./bar")` is `foo/bar`.
1746
- - `join(a, b…)` - *This function uses `/` on Unix and `\` on Windows, which can
1747
- be lead to unwanted behavior. The `/` operator, e.g., `a / b`, which always
1748
- uses `/`, should be considered as a replacement unless `\`s are specifically
1749
- desired on Windows.* Join path `a` with path `b`. `join("foo/bar", "baz")` is
1750
- `foo/bar/baz`. Accepts two or more arguments.
1751
-
1752
- #### Filesystem Access
1753
-
1754
- - `path_exists(path)` - Returns `true` if the path points at an existing entity
1755
- and `false` otherwise. Traverses symbolic links, and returns `false` if the
1756
- path is inaccessible or points to a broken symlink.
1757
-
1758
- ##### Error Reporting
1759
-
1760
- - `error(message)` - Abort execution and report error `message` to user.
1761
-
1762
- #### UUID and Hash Generation
1763
-
1764
- - `blake3(string)`<sup>1.25.0</sup> - Return [BLAKE3] hash of `string` as hexadecimal string.
1765
- - `blake3_file(path)`<sup>1.25.0</sup> - Return [BLAKE3] hash of file at `path` as hexadecimal
1766
- string.
1767
- - `sha256(string)` - Return the SHA-256 hash of `string` as hexadecimal string.
1768
- - `sha256_file(path)` - Return SHA-256 hash of file at `path` as hexadecimal
1769
- string.
1770
- - `uuid()` - Generate a random version 4 UUID.
1771
-
1772
- [BLAKE3]: https://github.com/BLAKE3-team/BLAKE3/
1773
-
1774
- #### Random
1775
-
1776
- - `choose(n, alphabet)`<sup>1.27.0</sup> - Generate a string of `n` randomly
1777
- selected characters from `alphabet`, which may not contain repeated
1778
- characters. For example, `choose('64', HEX)` will generate a random
1779
- 64-character lowercase hex string.
1780
-
1781
- #### Datetime
1782
-
1783
- - `datetime(format)`<sup>1.30.0</sup> - Return local time with `format`.
1784
- - `datetime_utc(format)`<sup>1.30.0</sup> - Return UTC time with `format`.
1785
-
1786
- The arguments to `datetime` and `datetime_utc` are `strftime`-style format
1787
- strings, see the
1788
- [`chrono` library docs](https://docs.rs/chrono/latest/chrono/format/strftime/index.html)
1789
- for details.
1790
-
1791
- #### Semantic Versions
1792
-
1793
- - `semver_matches(version, requirement)`<sup>1.16.0</sup> - Check whether a
1794
- [semantic `version`](https://semver.org), e.g., `"0.1.0"` matches a
1795
- `requirement`, e.g., `">=0.1.0"`, returning `"true"` if so and `"false"`
1796
- otherwise.
1797
-
1798
- ##### XDG Directories<sup>1.23.0</sup>
1799
-
1800
- These functions return paths to user-specific directories for things like
1801
- configuration, data, caches, executables, and the user's home directory. These
1802
- functions follow the
1803
- [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html),
1804
- and are implemented with the
1805
- [`dirs`](https://docs.rs/dirs/latest/dirs/index.html) crate.
1806
-
1807
- - `cache_directory()` - The user-specific cache directory.
1808
- - `config_directory()` - The user-specific configuration directory.
1809
- - `config_local_directory()` - The local user-specific configuration directory.
1810
- - `data_directory()` - The user-specific data directory.
1811
- - `data_local_directory()` - The local user-specific data directory.
1812
- - `executable_directory()` - The user-specific executable directory.
1813
- - `home_directory()` - The user's home directory.
1814
-
1815
- ### Constants
1816
-
1817
- A number of constants are predefined:
1818
-
1819
- | Name | Value |
1820
- |------|-------------|
1821
- | `HEX`<sup>1.27.0</sup> | `"0123456789abcdef"` |
1822
- | `HEXLOWER`<sup>1.27.0</sup> | `"0123456789abcdef"` |
1823
- | `HEXUPPER`<sup>1.27.0</sup> | `"0123456789ABCDEF"` |
1824
-
1825
- ```just
1826
- @foo:
1827
- echo {{HEX}}
1828
- ```
1829
-
1830
- ```console
1831
- $ just foo
1832
- 0123456789abcdef
1833
- ```
1834
-
1835
- ### Attributes
1836
-
1837
- Recipes, `mod` statements, and aliases may be annotated with attributes that change their behavior.
1838
-
1839
- | Name | Type | Description |
1840
- |------|------|-------------|
1841
- | `[confirm]`<sup>1.17.0</sup> | recipe | Require confirmation prior to executing recipe. |
1842
- | `[confirm('PROMPT')]`<sup>1.23.0</sup> | recipe | Require confirmation prior to executing recipe with a custom prompt. |
1843
- | `[doc('DOC')]`<sup>1.27.0</sup> | module, recipe | Set recipe or module's [documentation comment](#documentation-comments) to `DOC`. |
1844
- | `[extension('EXT')]`<sup>1.32.0</sup> | recipe | Set shebang recipe script's file extension to `EXT`. `EXT` should include a period if one is desired. |
1845
- | `[group('NAME')]`<sup>1.27.0</sup> | module, recipe | Put recipe or module in in [group](#groups) `NAME`. |
1846
- | `[linux]`<sup>1.8.0</sup> | recipe | Enable recipe on Linux. |
1847
- | `[macos]`<sup>1.8.0</sup> | recipe | Enable recipe on MacOS. |
1848
- | `[no-cd]`<sup>1.9.0</sup> | recipe | Don't change directory before executing recipe. |
1849
- | `[no-exit-message]`<sup>1.7.0</sup> | recipe | Don't print an error message if recipe fails. |
1850
- | `[no-quiet]`<sup>1.23.0</sup> | recipe | Override globally quiet recipes and always echo out the recipe. |
1851
- | `[positional-arguments]`<sup>1.29.0</sup> | recipe | Turn on [positional arguments](#positional-arguments) for this recipe. |
1852
- | `[private]`<sup>1.10.0</sup> | alias, recipe | Make recipe, alias, or variable private. See [Private Recipes](#private-recipes). |
1853
- | `[script]`<sup>1.33.0</sup> | recipe | Execute recipe as script. See [script recipes](#script-recipes) for more details. |
1854
- | `[script(COMMAND)]`<sup>1.32.0</sup> | recipe | Execute recipe as a script interpreted by `COMMAND`. See [script recipes](#script-recipes) for more details. |
1855
- | `[unix]`<sup>1.8.0</sup> | recipe | Enable recipe on Unixes. (Includes MacOS). |
1856
- | `[windows]`<sup>1.8.0</sup> | recipe | Enable recipe on Windows. |
1857
-
1858
- A recipe can have multiple attributes, either on multiple lines:
1859
-
1860
- ```just
1861
- [no-cd]
1862
- [private]
1863
- foo:
1864
- echo "foo"
1865
- ```
1866
-
1867
- Or separated by commas on a single line<sup>1.14.0</sup>:
1868
-
1869
- ```just
1870
- [no-cd, private]
1871
- foo:
1872
- echo "foo"
1873
- ```
1874
-
1875
- #### Enabling and Disabling Recipes<sup>1.8.0</sup>
1876
-
1877
- The `[linux]`, `[macos]`, `[unix]`, and `[windows]` attributes are
1878
- configuration attributes. By default, recipes are always enabled. A recipe with
1879
- one or more configuration attributes will only be enabled when one or more of
1880
- those configurations is active.
1881
-
1882
- This can be used to write `justfile`s that behave differently depending on
1883
- which operating system they run on. The `run` recipe in this `justfile` will
1884
- compile and run `main.c`, using a different C compiler and using the correct
1885
- output binary name for that compiler depending on the operating system:
1886
-
1887
- ```just
1888
- [unix]
1889
- run:
1890
- cc main.c
1891
- ./a.out
1892
-
1893
- [windows]
1894
- run:
1895
- cl main.c
1896
- main.exe
1897
- ```
1898
-
1899
- #### Disabling Changing Directory<sup>1.9.0</sup>
1900
-
1901
- `just` normally executes recipes with the current directory set to the
1902
- directory that contains the `justfile`. This can be disabled using the
1903
- `[no-cd]` attribute. This can be used to create recipes which use paths
1904
- relative to the invocation directory, or which operate on the current
1905
- directory.
1906
-
1907
- For example, this `commit` recipe:
1908
-
1909
- ```just
1910
- [no-cd]
1911
- commit file:
1912
- git add {{file}}
1913
- git commit
1914
- ```
1915
-
1916
- Can be used with paths that are relative to the current directory, because
1917
- `[no-cd]` prevents `just` from changing the current directory when executing
1918
- `commit`.
1919
-
1920
- #### Requiring Confirmation for Recipes<sup>1.17.0</sup>
1921
-
1922
- `just` normally executes all recipes unless there is an error. The `[confirm]`
1923
- attribute allows recipes require confirmation in the terminal prior to running.
1924
- This can be overridden by passing `--yes` to `just`, which will automatically
1925
- confirm any recipes marked by this attribute.
1926
-
1927
- Recipes dependent on a recipe that requires confirmation will not be run if the
1928
- relied upon recipe is not confirmed, as well as recipes passed after any recipe
1929
- that requires confirmation.
1930
-
1931
- ```just
1932
- [confirm]
1933
- delete-all:
1934
- rm -rf *
1935
- ```
1936
-
1937
- #### Custom Confirmation Prompt<sup>1.23.0</sup>
1938
-
1939
- The default confirmation prompt can be overridden with `[confirm(PROMPT)]`:
1940
-
1941
- ```just
1942
- [confirm("Are you sure you want to delete everything?")]
1943
- delete-everything:
1944
- rm -rf *
1945
- ```
1946
-
1947
- ### Groups
1948
-
1949
- Recipes and modules may be annotated with a group name:
1950
-
1951
- ```just
1952
- [group('lint')]
1953
- js-lint:
1954
- echo 'Running JS linter…'
1955
-
1956
- [group('rust recipes')]
1957
- [group('lint')]
1958
- rust-lint:
1959
- echo 'Running Rust linter…'
1960
-
1961
- [group('lint')]
1962
- cpp-lint:
1963
- echo 'Running C++ linter…'
1964
-
1965
- # not in any group
1966
- email-everyone:
1967
- echo 'Sending mass email…'
1968
- ```
1969
-
1970
- Recipes are listed by group:
1971
-
1972
- ```
1973
- $ just --list
1974
- Available recipes:
1975
- email-everyone # not in any group
1976
-
1977
- [lint]
1978
- cpp-lint
1979
- js-lint
1980
- rust-lint
1981
-
1982
- [rust recipes]
1983
- rust-lint
1984
- ```
1985
-
1986
- `just --list --unsorted` prints recipes in their justfile order within each group:
1987
-
1988
- ```
1989
- $ just --list --unsorted
1990
- Available recipes:
1991
- (no group)
1992
- email-everyone # not in any group
1993
-
1994
- [lint]
1995
- js-lint
1996
- rust-lint
1997
- cpp-lint
1998
-
1999
- [rust recipes]
2000
- rust-lint
2001
- ```
2002
-
2003
- Groups can be listed with `--groups`:
2004
-
2005
- ```
2006
- $ just --groups
2007
- Recipe groups:
2008
- lint
2009
- rust recipes
2010
- ```
2011
-
2012
- Use `just --groups --unsorted` to print groups in their justfile order.
2013
-
2014
- ### Command Evaluation Using Backticks
2015
-
2016
- Backticks can be used to store the result of commands:
2017
-
2018
- ```just
2019
- localhost := `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'`
2020
-
2021
- serve:
2022
- ./serve {{localhost}} 8080
2023
- ```
2024
-
2025
- Indented backticks, delimited by three backticks, are de-indented in the same
2026
- manner as indented strings:
2027
-
2028
- ````just
2029
- # This backtick evaluates the command `echo foo\necho bar\n`, which produces the value `foo\nbar\n`.
2030
- stuff := ```
2031
- echo foo
2032
- echo bar
2033
- ```
2034
- ````
2035
-
2036
- See the [Strings](#strings) section for details on unindenting.
2037
-
2038
- Backticks may not start with `#!`. This syntax is reserved for a future
2039
- upgrade.
2040
-
2041
- ### Conditional Expressions
2042
-
2043
- `if`/`else` expressions evaluate different branches depending on if two
2044
- expressions evaluate to the same value:
2045
-
2046
- ```just
2047
- foo := if "2" == "2" { "Good!" } else { "1984" }
2048
-
2049
- bar:
2050
- @echo "{{foo}}"
2051
- ```
2052
-
2053
- ```console
2054
- $ just bar
2055
- Good!
2056
- ```
2057
-
2058
- It is also possible to test for inequality:
2059
-
2060
- ```just
2061
- foo := if "hello" != "goodbye" { "xyz" } else { "abc" }
2062
-
2063
- bar:
2064
- @echo {{foo}}
2065
- ```
2066
-
2067
- ```console
2068
- $ just bar
2069
- xyz
2070
- ```
2071
-
2072
- And match against regular expressions:
2073
-
2074
- ```just
2075
- foo := if "hello" =~ 'hel+o' { "match" } else { "mismatch" }
2076
-
2077
- bar:
2078
- @echo {{foo}}
2079
- ```
2080
-
2081
- ```console
2082
- $ just bar
2083
- match
2084
- ```
2085
-
2086
- Regular expressions are provided by the
2087
- [regex crate](https://github.com/rust-lang/regex), whose syntax is documented on
2088
- [docs.rs](https://docs.rs/regex/1.5.4/regex/#syntax). Since regular expressions
2089
- commonly use backslash escape sequences, consider using single-quoted string
2090
- literals, which will pass slashes to the regex parser unmolested.
2091
-
2092
- Conditional expressions short-circuit, which means they only evaluate one of
2093
- their branches. This can be used to make sure that backtick expressions don't
2094
- run when they shouldn't.
2095
-
2096
- ```just
2097
- foo := if env_var("RELEASE") == "true" { `get-something-from-release-database` } else { "dummy-value" }
2098
- ```
2099
-
2100
- Conditionals can be used inside of recipes:
2101
-
2102
- ```just
2103
- bar foo:
2104
- echo {{ if foo == "bar" { "hello" } else { "goodbye" } }}
2105
- ```
2106
-
2107
- Note the space after the final `}`! Without the space, the interpolation will
2108
- be prematurely closed.
2109
-
2110
- Multiple conditionals can be chained:
2111
-
2112
- ```just
2113
- foo := if "hello" == "goodbye" {
2114
- "xyz"
2115
- } else if "a" == "a" {
2116
- "abc"
2117
- } else {
2118
- "123"
2119
- }
2120
-
2121
- bar:
2122
- @echo {{foo}}
2123
- ```
2124
-
2125
- ```console
2126
- $ just bar
2127
- abc
2128
- ```
2129
-
2130
- ### Stopping execution with error
2131
-
2132
- Execution can be halted with the `error` function. For example:
2133
-
2134
- ```just
2135
- foo := if "hello" == "goodbye" {
2136
- "xyz"
2137
- } else if "a" == "b" {
2138
- "abc"
2139
- } else {
2140
- error("123")
2141
- }
2142
- ```
2143
-
2144
- Which produce the following error when run:
2145
-
2146
- ```
2147
- error: Call to function `error` failed: 123
2148
- |
2149
- 16 | error("123")
2150
- ```
2151
-
2152
- ### Setting Variables from the Command Line
2153
-
2154
- Variables can be overridden from the command line.
2155
-
2156
- ```just
2157
- os := "linux"
2158
-
2159
- test: build
2160
- ./test --test {{os}}
2161
-
2162
- build:
2163
- ./build {{os}}
2164
- ```
2165
-
2166
- ```console
2167
- $ just
2168
- ./build linux
2169
- ./test --test linux
2170
- ```
2171
-
2172
- Any number of arguments of the form `NAME=VALUE` can be passed before recipes:
2173
-
2174
- ```console
2175
- $ just os=plan9
2176
- ./build plan9
2177
- ./test --test plan9
2178
- ```
2179
-
2180
- Or you can use the `--set` flag:
2181
-
2182
- ```console
2183
- $ just --set os bsd
2184
- ./build bsd
2185
- ./test --test bsd
2186
- ```
2187
-
2188
- ### Getting and Setting Environment Variables
2189
-
2190
- #### Exporting `just` Variables
2191
-
2192
- Assignments prefixed with the `export` keyword will be exported to recipes as
2193
- environment variables:
2194
-
2195
- ```just
2196
- export RUST_BACKTRACE := "1"
2197
-
2198
- test:
2199
- # will print a stack trace if it crashes
2200
- cargo test
2201
- ```
2202
-
2203
- Parameters prefixed with a `$` will be exported as environment variables:
2204
-
2205
- ```just
2206
- test $RUST_BACKTRACE="1":
2207
- # will print a stack trace if it crashes
2208
- cargo test
2209
- ```
2210
-
2211
- Exported variables and parameters are not exported to backticks in the same scope.
2212
-
2213
- ```just
2214
- export WORLD := "world"
2215
- # This backtick will fail with "WORLD: unbound variable"
2216
- BAR := `echo hello $WORLD`
2217
- ```
2218
-
2219
- ```just
2220
- # Running `just a foo` will fail with "A: unbound variable"
2221
- a $A $B=`echo $A`:
2222
- echo $A $B
2223
- ```
2224
-
2225
- When [export](#export) is set, all `just` variables are exported as environment
2226
- variables.
2227
-
2228
- #### Unexporting Environment Variables<sup>1.29.0</sup>
2229
-
2230
- Environment variables can be unexported with the `unexport keyword`:
2231
-
2232
- ```just
2233
- unexport FOO
2234
-
2235
- @foo:
2236
- echo $FOO
2237
- ```
2238
-
2239
- ```
2240
- $ export FOO=bar
2241
- $ just foo
2242
- sh: FOO: unbound variable
2243
- ```
2244
-
2245
- #### Getting Environment Variables from the environment
2246
-
2247
- Environment variables from the environment are passed automatically to the
2248
- recipes.
2249
-
2250
- ```just
2251
- print_home_folder:
2252
- echo "HOME is: '${HOME}'"
2253
- ```
2254
-
2255
- ```console
2256
- $ just
2257
- HOME is '/home/myuser'
2258
- ```
2259
-
2260
- #### Setting `just` Variables from Environment Variables
2261
-
2262
- Environment variables can be propagated to `just` variables using the functions
2263
- `env_var()` and `env_var_or_default()`. See
2264
- [environment-variables](#environment-variables).
2265
-
2266
- ### Recipe Parameters
2267
-
2268
- Recipes may have parameters. Here recipe `build` has a parameter called
2269
- `target`:
2270
-
2271
- ```just
2272
- build target:
2273
- @echo 'Building {{target}}…'
2274
- cd {{target}} && make
2275
- ```
2276
-
2277
- To pass arguments on the command line, put them after the recipe name:
2278
-
2279
- ```console
2280
- $ just build my-awesome-project
2281
- Building my-awesome-project…
2282
- cd my-awesome-project && make
2283
- ```
2284
-
2285
- To pass arguments to a dependency, put the dependency in parentheses along with
2286
- the arguments:
2287
-
2288
- ```just
2289
- default: (build "main")
2290
-
2291
- build target:
2292
- @echo 'Building {{target}}…'
2293
- cd {{target}} && make
2294
- ```
2295
-
2296
- Variables can also be passed as arguments to dependencies:
2297
-
2298
- ```just
2299
- target := "main"
2300
-
2301
- _build version:
2302
- @echo 'Building {{version}}…'
2303
- cd {{version}} && make
2304
-
2305
- build: (_build target)
2306
- ```
2307
-
2308
- A command's arguments can be passed to dependency by putting the dependency in
2309
- parentheses along with the arguments:
2310
-
2311
- ```just
2312
- build target:
2313
- @echo "Building {{target}}…"
2314
-
2315
- push target: (build target)
2316
- @echo 'Pushing {{target}}…'
2317
- ```
2318
-
2319
- Parameters may have default values:
2320
-
2321
- ```just
2322
- default := 'all'
2323
-
2324
- test target tests=default:
2325
- @echo 'Testing {{target}}:{{tests}}…'
2326
- ./test --tests {{tests}} {{target}}
2327
- ```
2328
-
2329
- Parameters with default values may be omitted:
2330
-
2331
- ```console
2332
- $ just test server
2333
- Testing server:all…
2334
- ./test --tests all server
2335
- ```
2336
-
2337
- Or supplied:
2338
-
2339
- ```console
2340
- $ just test server unit
2341
- Testing server:unit…
2342
- ./test --tests unit server
2343
- ```
2344
-
2345
- Default values may be arbitrary expressions, but concatenations or path joins
2346
- must be parenthesized:
2347
-
2348
- ```just
2349
- arch := "wasm"
2350
-
2351
- test triple=(arch + "-unknown-unknown") input=(arch / "input.dat"):
2352
- ./test {{triple}}
2353
- ```
2354
-
2355
- The last parameter of a recipe may be variadic, indicated with either a `+` or
2356
- a `*` before the argument name:
2357
-
2358
- ```just
2359
- backup +FILES:
2360
- scp {{FILES}} me@server.com:
2361
- ```
2362
-
2363
- Variadic parameters prefixed with `+` accept _one or more_ arguments and expand
2364
- to a string containing those arguments separated by spaces:
2365
-
2366
- ```console
2367
- $ just backup FAQ.md GRAMMAR.md
2368
- scp FAQ.md GRAMMAR.md me@server.com:
2369
- FAQ.md 100% 1831 1.8KB/s 00:00
2370
- GRAMMAR.md 100% 1666 1.6KB/s 00:00
2371
- ```
2372
-
2373
- Variadic parameters prefixed with `*` accept _zero or more_ arguments and
2374
- expand to a string containing those arguments separated by spaces, or an empty
2375
- string if no arguments are present:
2376
-
2377
- ```just
2378
- commit MESSAGE *FLAGS:
2379
- git commit {{FLAGS}} -m "{{MESSAGE}}"
2380
- ```
2381
-
2382
- Variadic parameters can be assigned default values. These are overridden by
2383
- arguments passed on the command line:
2384
-
2385
- ```just
2386
- test +FLAGS='-q':
2387
- cargo test {{FLAGS}}
2388
- ```
2389
-
2390
- `{{…}}` substitutions may need to be quoted if they contain spaces. For
2391
- example, if you have the following recipe:
2392
-
2393
- ```just
2394
- search QUERY:
2395
- lynx https://www.google.com/?q={{QUERY}}
2396
- ```
2397
-
2398
- And you type:
2399
-
2400
- ```console
2401
- $ just search "cat toupee"
2402
- ```
2403
-
2404
- `just` will run the command `lynx https://www.google.com/?q=cat toupee`, which
2405
- will get parsed by `sh` as `lynx`, `https://www.google.com/?q=cat`, and
2406
- `toupee`, and not the intended `lynx` and `https://www.google.com/?q=cat toupee`.
2407
-
2408
- You can fix this by adding quotes:
2409
-
2410
- ```just
2411
- search QUERY:
2412
- lynx 'https://www.google.com/?q={{QUERY}}'
2413
- ```
2414
-
2415
- Parameters prefixed with a `$` will be exported as environment variables:
2416
-
2417
- ```just
2418
- foo $bar:
2419
- echo $bar
2420
- ```
2421
-
2422
- ### Dependencies
2423
-
2424
- Dependencies run before recipes that depend on them:
2425
-
2426
- ```just
2427
- a: b
2428
- @echo A
2429
-
2430
- b:
2431
- @echo B
2432
- ```
2433
-
2434
- ```
2435
- $ just a
2436
- B
2437
- A
2438
- ```
2439
-
2440
- In a given invocation of `just`, a recipe with the same arguments will only run
2441
- once, regardless of how many times it appears in the command-line invocation,
2442
- or how many times it appears as a dependency:
2443
-
2444
- ```just
2445
- a:
2446
- @echo A
2447
-
2448
- b: a
2449
- @echo B
2450
-
2451
- c: a
2452
- @echo C
2453
- ```
2454
-
2455
- ```
2456
- $ just a a a a a
2457
- A
2458
- $ just b c
2459
- A
2460
- B
2461
- C
2462
- ```
2463
-
2464
- Multiple recipes may depend on a recipe that performs some kind of setup, and
2465
- when those recipes run, that setup will only be performed once:
2466
-
2467
- ```just
2468
- build:
2469
- cc main.c
2470
-
2471
- test-foo: build
2472
- ./a.out --test foo
2473
-
2474
- test-bar: build
2475
- ./a.out --test bar
2476
- ```
2477
-
2478
- ```
2479
- $ just test-foo test-bar
2480
- cc main.c
2481
- ./a.out --test foo
2482
- ./a.out --test bar
2483
- ```
2484
-
2485
- Recipes in a given run are only skipped when they receive the same arguments:
2486
-
2487
- ```just
2488
- build:
2489
- cc main.c
2490
-
2491
- test TEST: build
2492
- ./a.out --test {{TEST}}
2493
- ```
2494
-
2495
- ```
2496
- $ just test foo test bar
2497
- cc main.c
2498
- ./a.out --test foo
2499
- ./a.out --test bar
2500
- ```
2501
-
2502
- #### Running Recipes at the End of a Recipe
2503
-
2504
- Normal dependencies of a recipes always run before a recipe starts. That is to
2505
- say, the dependee always runs before the depender. These dependencies are
2506
- called "prior dependencies".
2507
-
2508
- A recipe can also have subsequent dependencies, which run immediately after the
2509
- recipe and are introduced with an `&&`:
2510
-
2511
- ```just
2512
- a:
2513
- echo 'A!'
2514
-
2515
- b: a && c d
2516
- echo 'B!'
2517
-
2518
- c:
2519
- echo 'C!'
2520
-
2521
- d:
2522
- echo 'D!'
2523
- ```
2524
-
2525
- …running _b_ prints:
2526
-
2527
- ```console
2528
- $ just b
2529
- echo 'A!'
2530
- A!
2531
- echo 'B!'
2532
- B!
2533
- echo 'C!'
2534
- C!
2535
- echo 'D!'
2536
- D!
2537
- ```
2538
-
2539
- #### Running Recipes in the Middle of a Recipe
2540
-
2541
- `just` doesn't support running recipes in the middle of another recipe, but you
2542
- can call `just` recursively in the middle of a recipe. Given the following
2543
- `justfile`:
2544
-
2545
- ```just
2546
- a:
2547
- echo 'A!'
2548
-
2549
- b: a
2550
- echo 'B start!'
2551
- just c
2552
- echo 'B end!'
2553
-
2554
- c:
2555
- echo 'C!'
2556
- ```
2557
-
2558
- …running _b_ prints:
2559
-
2560
- ```console
2561
- $ just b
2562
- echo 'A!'
2563
- A!
2564
- echo 'B start!'
2565
- B start!
2566
- echo 'C!'
2567
- C!
2568
- echo 'B end!'
2569
- B end!
2570
- ```
2571
-
2572
- This has limitations, since recipe `c` is run with an entirely new invocation
2573
- of `just`: Assignments will be recalculated, dependencies might run twice, and
2574
- command line arguments will not be propagated to the child `just` process.
2575
-
2576
- ### Shebang Recipes
2577
-
2578
- Recipes that start with `#!` are called shebang recipes, and are executed by
2579
- saving the recipe body to a file and running it. This lets you write recipes in
2580
- different languages:
2581
-
2582
- ```just
2583
- polyglot: python js perl sh ruby nu
2584
-
2585
- python:
2586
- #!/usr/bin/env python3
2587
- print('Hello from python!')
2588
-
2589
- js:
2590
- #!/usr/bin/env node
2591
- console.log('Greetings from JavaScript!')
2592
-
2593
- perl:
2594
- #!/usr/bin/env perl
2595
- print "Larry Wall says Hi!\n";
2596
-
2597
- sh:
2598
- #!/usr/bin/env sh
2599
- hello='Yo'
2600
- echo "$hello from a shell script!"
2601
-
2602
- nu:
2603
- #!/usr/bin/env nu
2604
- let hello = 'Hola'
2605
- echo $"($hello) from a nushell script!"
2606
-
2607
- ruby:
2608
- #!/usr/bin/env ruby
2609
- puts "Hello from ruby!"
2610
- ```
2611
-
2612
- ```console
2613
- $ just polyglot
2614
- Hello from python!
2615
- Greetings from JavaScript!
2616
- Larry Wall says Hi!
2617
- Yo from a shell script!
2618
- Hola from a nushell script!
2619
- Hello from ruby!
2620
- ```
2621
-
2622
- On Unix-like operating systems, including Linux and MacOS, shebang recipes are
2623
- executed by saving the recipe body to a file in a temporary directory, marking
2624
- the file as executable, and executing it. The OS then parses the shebang line
2625
- into a command line and invokes it, including the path to the file. For
2626
- example, if a recipe starts with `#!/usr/bin/env bash`, the final command that
2627
- the OS runs will be something like `/usr/bin/env bash
2628
- /tmp/PATH_TO_SAVED_RECIPE_BODY`.
2629
-
2630
- Shebang line splitting is operating system dependent. When passing a command
2631
- with arguments, you may need to tell `env` to split them explicitly by using
2632
- the `-S` flag:
2633
-
2634
- ```just
2635
- run:
2636
- #!/usr/bin/env -S bash -x
2637
- ls
2638
- ```
2639
-
2640
- Windows does not support shebang lines. On Windows, `just` splits the shebang
2641
- line into a command and arguments, saves the recipe body to a file, and invokes
2642
- the split command and arguments, adding the path to the saved recipe body as
2643
- the final argument. For example, on Windows, if a recipe starts with `#! py`,
2644
- the final command the OS runs will be something like
2645
- `py C:\Temp\PATH_TO_SAVED_RECIPE_BODY`.
2646
-
2647
- ### Script Recipes
2648
-
2649
- Recipes with a `[script(COMMAND)]`<sup>1.32.0</sup> attribute are run as
2650
- scripts interpreted by `COMMAND`. This avoids some of the issues with shebang
2651
- recipes, such as the use of `cygpath` on Windows, the need to use
2652
- `/usr/bin/env`, and inconsistences in shebang line splitting across Unix OSs.
2653
-
2654
- Recipes with an empty `[script]` attribute are executed with the value of
2655
- `set script-interpreter := […]`<sup>1.33.0</sup>, defaulting to `sh -eu`.
2656
-
2657
- The body of the recipe is evaluated, written to disk in the temporary
2658
- directory, and run by passing its path as an argument to `COMMAND`.
2659
-
2660
- The `[script(…)]` attribute is unstable, so you'll need to use `set unstable`,
2661
- set the `JUST_UNSTABLE` environment variable, or pass `--unstable` on the
2662
- command line.
2663
-
2664
- ### Safer Bash Shebang Recipes
2665
-
2666
- If you're writing a `bash` shebang recipe, consider adding `set -euxo
2667
- pipefail`:
2668
-
2669
- ```just
2670
- foo:
2671
- #!/usr/bin/env bash
2672
- set -euxo pipefail
2673
- hello='Yo'
2674
- echo "$hello from Bash!"
2675
- ```
2676
-
2677
- It isn't strictly necessary, but `set -euxo pipefail` turns on a few useful
2678
- features that make `bash` shebang recipes behave more like normal, linewise
2679
- `just` recipe:
2680
-
2681
- - `set -e` makes `bash` exit if a command fails.
2682
-
2683
- - `set -u` makes `bash` exit if a variable is undefined.
2684
-
2685
- - `set -x` makes `bash` print each script line before it's run.
2686
-
2687
- - `set -o pipefail` makes `bash` exit if a command in a pipeline fails. This is
2688
- `bash`-specific, so isn't turned on in normal linewise `just` recipes.
2689
-
2690
- Together, these avoid a lot of shell scripting gotchas.
2691
-
2692
- #### Shebang Recipe Execution on Windows
2693
-
2694
- On Windows, shebang interpreter paths containing a `/` are translated from
2695
- Unix-style paths to Windows-style paths using `cygpath`, a utility that ships
2696
- with [Cygwin](http://www.cygwin.com).
2697
-
2698
- For example, to execute this recipe on Windows:
2699
-
2700
- ```just
2701
- echo:
2702
- #!/bin/sh
2703
- echo "Hello!"
2704
- ```
2705
-
2706
- The interpreter path `/bin/sh` will be translated to a Windows-style path using
2707
- `cygpath` before being executed.
2708
-
2709
- If the interpreter path does not contain a `/` it will be executed without
2710
- being translated. This is useful if `cygpath` is not available, or you wish to
2711
- pass a Windows-style path to the interpreter.
2712
-
2713
- ### Setting Variables in a Recipe
2714
-
2715
- Recipe lines are interpreted by the shell, not `just`, so it's not possible to
2716
- set `just` variables in the middle of a recipe:
2717
-
2718
- ```mf
2719
- foo:
2720
- x := "hello" # This doesn't work!
2721
- echo {{x}}
2722
- ```
2723
-
2724
- It is possible to use shell variables, but there's another problem. Every
2725
- recipe line is run by a new shell instance, so variables set in one line won't
2726
- be set in the next:
2727
-
2728
- ```just
2729
- foo:
2730
- x=hello && echo $x # This works!
2731
- y=bye
2732
- echo $y # This doesn't, `y` is undefined here!
2733
- ```
2734
-
2735
- The best way to work around this is to use a shebang recipe. Shebang recipe
2736
- bodies are extracted and run as scripts, so a single shell instance will run
2737
- the whole thing:
2738
-
2739
- ```just
2740
- foo:
2741
- #!/usr/bin/env bash
2742
- set -euxo pipefail
2743
- x=hello
2744
- echo $x
2745
- ```
2746
-
2747
- ### Sharing Environment Variables Between Recipes
2748
-
2749
- Each line of each recipe is executed by a fresh shell, so it is not possible to
2750
- share environment variables between recipes.
2751
-
2752
- #### Using Python Virtual Environments
2753
-
2754
- Some tools, like [Python's venv](https://docs.python.org/3/library/venv.html),
2755
- require loading environment variables in order to work, making them challenging
2756
- to use with `just`. As a workaround, you can execute the virtual environment
2757
- binaries directly:
2758
-
2759
- ```just
2760
- venv:
2761
- [ -d foo ] || python3 -m venv foo
2762
-
2763
- run: venv
2764
- ./foo/bin/python3 main.py
2765
- ```
2766
-
2767
- ### Changing the Working Directory in a Recipe
2768
-
2769
- Each recipe line is executed by a new shell, so if you change the working
2770
- directory on one line, it won't have an effect on later lines:
2771
-
2772
- ```just
2773
- foo:
2774
- pwd # This `pwd` will print the same directory…
2775
- cd bar
2776
- pwd # …as this `pwd`!
2777
- ```
2778
-
2779
- There are a couple ways around this. One is to call `cd` on the same line as
2780
- the command you want to run:
2781
-
2782
- ```just
2783
- foo:
2784
- cd bar && pwd
2785
- ```
2786
-
2787
- The other is to use a shebang recipe. Shebang recipe bodies are extracted and
2788
- run as scripts, so a single shell instance will run the whole thing, and thus a
2789
- `pwd` on one line will affect later lines, just like a shell script:
2790
-
2791
- ```just
2792
- foo:
2793
- #!/usr/bin/env bash
2794
- set -euxo pipefail
2795
- cd bar
2796
- pwd
2797
- ```
2798
-
2799
- ### Indentation
2800
-
2801
- Recipe lines can be indented with spaces or tabs, but not a mix of both. All of
2802
- a recipe's lines must have the same type of indentation, but different recipes
2803
- in the same `justfile` may use different indentation.
2804
-
2805
- Each recipe must be indented at least one level from the `recipe-name` but
2806
- after that may be further indented.
2807
-
2808
- Here's a justfile with a recipe indented with spaces, represented as `·`, and
2809
- tabs, represented as `→`.
2810
-
2811
- ```justfile
2812
- set windows-shell := ["pwsh", "-NoLogo", "-NoProfileLoadTime", "-Command"]
2813
-
2814
- set ignore-comments
2815
-
2816
- list-space directory:
2817
- ··#!pwsh
2818
- ··foreach ($item in $(Get-ChildItem {{directory}} )) {
2819
- ····echo $item.Name
2820
- ··}
2821
- ··echo ""
2822
-
2823
- # indentation nesting works even when newlines are escaped
2824
- list-tab directory:
2825
- → @foreach ($item in $(Get-ChildItem {{directory}} )) { \
2826
- → → echo $item.Name \
2827
- → }
2828
- → @echo ""
2829
- ```
2830
-
2831
- ```pwsh
2832
- PS > just list-space ~
2833
- Desktop
2834
- Documents
2835
- Downloads
2836
-
2837
- PS > just list-tab ~
2838
- Desktop
2839
- Documents
2840
- Downloads
2841
- ```
2842
-
2843
- ### Multi-Line Constructs
2844
-
2845
- Recipes without an initial shebang are evaluated and run line-by-line, which
2846
- means that multi-line constructs probably won't do what you want.
2847
-
2848
- For example, with the following `justfile`:
2849
-
2850
- ```mf
2851
- conditional:
2852
- if true; then
2853
- echo 'True!'
2854
- fi
2855
- ```
2856
-
2857
- The extra leading whitespace before the second line of the `conditional` recipe
2858
- will produce a parse error:
2859
-
2860
- ```console
2861
- $ just conditional
2862
- error: Recipe line has extra leading whitespace
2863
- |
2864
- 3 | echo 'True!'
2865
- | ^^^^^^^^^^^^^^^^
2866
- ```
2867
-
2868
- To work around this, you can write conditionals on one line, escape newlines
2869
- with slashes, or add a shebang to your recipe. Some examples of multi-line
2870
- constructs are provided for reference.
2871
-
2872
- #### `if` statements
2873
-
2874
- ```just
2875
- conditional:
2876
- if true; then echo 'True!'; fi
2877
- ```
2878
-
2879
- ```just
2880
- conditional:
2881
- if true; then \
2882
- echo 'True!'; \
2883
- fi
2884
- ```
2885
-
2886
- ```just
2887
- conditional:
2888
- #!/usr/bin/env sh
2889
- if true; then
2890
- echo 'True!'
2891
- fi
2892
- ```
2893
-
2894
- #### `for` loops
2895
-
2896
- ```just
2897
- for:
2898
- for file in `ls .`; do echo $file; done
2899
- ```
2900
-
2901
- ```just
2902
- for:
2903
- for file in `ls .`; do \
2904
- echo $file; \
2905
- done
2906
- ```
2907
-
2908
- ```just
2909
- for:
2910
- #!/usr/bin/env sh
2911
- for file in `ls .`; do
2912
- echo $file
2913
- done
2914
- ```
2915
-
2916
- #### `while` loops
2917
-
2918
- ```just
2919
- while:
2920
- while `server-is-dead`; do ping -c 1 server; done
2921
- ```
2922
-
2923
- ```just
2924
- while:
2925
- while `server-is-dead`; do \
2926
- ping -c 1 server; \
2927
- done
2928
- ```
2929
-
2930
- ```just
2931
- while:
2932
- #!/usr/bin/env sh
2933
- while `server-is-dead`; do
2934
- ping -c 1 server
2935
- done
2936
- ```
2937
-
2938
- #### Outside Recipe Bodies
2939
-
2940
- Parenthesized expressions can span multiple lines:
2941
-
2942
- ```just
2943
- abc := ('a' +
2944
- 'b'
2945
- + 'c')
2946
-
2947
- abc2 := (
2948
- 'a' +
2949
- 'b' +
2950
- 'c'
2951
- )
2952
-
2953
- foo param=('foo'
2954
- + 'bar'
2955
- ):
2956
- echo {{param}}
2957
-
2958
- bar: (foo
2959
- 'Foo'
2960
- )
2961
- echo 'Bar!'
2962
- ```
2963
-
2964
- Lines ending with a backslash continue on to the next line as if the lines were
2965
- joined by whitespace<sup>1.15.0</sup>:
2966
-
2967
- ```just
2968
- a := 'foo' + \
2969
- 'bar'
2970
-
2971
- foo param1 \
2972
- param2='foo' \
2973
- *varparam='': dep1 \
2974
- (dep2 'foo')
2975
- echo {{param1}} {{param2}} {{varparam}}
2976
-
2977
- dep1: \
2978
- # this comment is not part of the recipe body
2979
- echo 'dep1'
2980
-
2981
- dep2 \
2982
- param:
2983
- echo 'Dependency with parameter {{param}}'
2984
- ```
2985
-
2986
- Backslash line continuations can also be used in interpolations. The line
2987
- following the backslash must be indented.
2988
-
2989
- ```just
2990
- recipe:
2991
- echo '{{ \
2992
- "This interpolation " + \
2993
- "has a lot of text." \
2994
- }}'
2995
- echo 'back to recipe body'
2996
- ```
2997
-
2998
- ### Command Line Options
2999
-
3000
- `just` supports a number of useful command line options for listing, dumping,
3001
- and debugging recipes and variables:
3002
-
3003
- ```console
3004
- $ just --list
3005
- Available recipes:
3006
- js
3007
- perl
3008
- polyglot
3009
- python
3010
- ruby
3011
- $ just --show perl
3012
- perl:
3013
- #!/usr/bin/env perl
3014
- print "Larry Wall says Hi!\n";
3015
- $ just --show polyglot
3016
- polyglot: python js perl sh ruby
3017
- ```
3018
-
3019
- Some command-line options can be set with environment variables. For example:
3020
-
3021
- ```console
3022
- $ export JUST_UNSTABLE=1
3023
- $ just
3024
- ```
3025
-
3026
- Is equivalent to:
3027
-
3028
- ```console
3029
- $ just --unstable
3030
- ```
3031
-
3032
- Consult `just --help` to see which options can be set from environment
3033
- variables.
3034
-
3035
- ### Private Recipes
3036
-
3037
- Recipes and aliases whose name starts with a `_` are omitted from `just --list`:
3038
-
3039
- ```just
3040
- test: _test-helper
3041
- ./bin/test
3042
-
3043
- _test-helper:
3044
- ./bin/super-secret-test-helper-stuff
3045
- ```
3046
-
3047
- ```console
3048
- $ just --list
3049
- Available recipes:
3050
- test
3051
- ```
3052
-
3053
- And from `just --summary`:
3054
-
3055
- ```console
3056
- $ just --summary
3057
- test
3058
- ```
3059
-
3060
- The `[private]` attribute<sup>1.10.0</sup> may also be used to hide recipes or
3061
- aliases without needing to change the name:
3062
-
3063
- ```just
3064
- [private]
3065
- foo:
3066
-
3067
- [private]
3068
- alias b := bar
3069
-
3070
- bar:
3071
- ```
3072
-
3073
- ```console
3074
- $ just --list
3075
- Available recipes:
3076
- bar
3077
- ```
3078
-
3079
- This is useful for helper recipes which are only meant to be used as
3080
- dependencies of other recipes.
3081
-
3082
- ### Quiet Recipes
3083
-
3084
- A recipe name may be prefixed with `@` to invert the meaning of `@` before each
3085
- line:
3086
-
3087
- ```just
3088
- @quiet:
3089
- echo hello
3090
- echo goodbye
3091
- @# all done!
3092
- ```
3093
-
3094
- Now only the lines starting with `@` will be echoed:
3095
-
3096
- ```console
3097
- $ just quiet
3098
- hello
3099
- goodbye
3100
- # all done!
3101
- ```
3102
-
3103
- All recipes in a Justfile can be made quiet with `set quiet`:
3104
-
3105
- ```just
3106
- set quiet
3107
-
3108
- foo:
3109
- echo "This is quiet"
3110
-
3111
- @foo2:
3112
- echo "This is also quiet"
3113
- ```
3114
-
3115
- The `[no-quiet]` attribute overrides this setting:
3116
-
3117
- ```just
3118
- set quiet
3119
-
3120
- foo:
3121
- echo "This is quiet"
3122
-
3123
- [no-quiet]
3124
- foo2:
3125
- echo "This is not quiet"
3126
- ```
3127
-
3128
- Shebang recipes are quiet by default:
3129
-
3130
- ```just
3131
- foo:
3132
- #!/usr/bin/env bash
3133
- echo 'Foo!'
3134
- ```
3135
-
3136
- ```console
3137
- $ just foo
3138
- Foo!
3139
- ```
3140
-
3141
- Adding `@` to a shebang recipe name makes `just` print the recipe before
3142
- executing it:
3143
-
3144
- ```just
3145
- @bar:
3146
- #!/usr/bin/env bash
3147
- echo 'Bar!'
3148
- ```
3149
-
3150
- ```console
3151
- $ just bar
3152
- #!/usr/bin/env bash
3153
- echo 'Bar!'
3154
- Bar!
3155
- ```
3156
-
3157
- `just` normally prints error messages when a recipe line fails. These error
3158
- messages can be suppressed using the `[no-exit-message]`<sup>1.7.0</sup>
3159
- attribute. You may find this especially useful with a recipe that wraps a tool:
3160
-
3161
- ```just
3162
- git *args:
3163
- @git {{args}}
3164
- ```
3165
-
3166
- ```console
3167
- $ just git status
3168
- fatal: not a git repository (or any of the parent directories): .git
3169
- error: Recipe `git` failed on line 2 with exit code 128
3170
- ```
3171
-
3172
- Add the attribute to suppress the exit error message when the tool exits with a
3173
- non-zero code:
3174
-
3175
- ```just
3176
- [no-exit-message]
3177
- git *args:
3178
- @git {{args}}
3179
- ```
3180
-
3181
- ```console
3182
- $ just git status
3183
- fatal: not a git repository (or any of the parent directories): .git
3184
- ```
3185
-
3186
- ### Selecting Recipes to Run With an Interactive Chooser
3187
-
3188
- The `--choose` subcommand makes `just` invoke a chooser to select which recipes
3189
- to run. Choosers should read lines containing recipe names from standard input
3190
- and print one or more of those names separated by spaces to standard output.
3191
-
3192
- Because there is currently no way to run a recipe that requires arguments with
3193
- `--choose`, such recipes will not be given to the chooser. Private recipes and
3194
- aliases are also skipped.
3195
-
3196
- The chooser can be overridden with the `--chooser` flag. If `--chooser` is not
3197
- given, then `just` first checks if `$JUST_CHOOSER` is set. If it isn't, then
3198
- the chooser defaults to `fzf`, a popular fuzzy finder.
3199
-
3200
- Arguments can be included in the chooser, i.e. `fzf --exact`.
3201
-
3202
- The chooser is invoked in the same way as recipe lines. For example, if the
3203
- chooser is `fzf`, it will be invoked with `sh -cu 'fzf'`, and if the shell, or
3204
- the shell arguments are overridden, the chooser invocation will respect those
3205
- overrides.
3206
-
3207
- If you'd like `just` to default to selecting recipes with a chooser, you can
3208
- use this as your default recipe:
3209
-
3210
- ```just
3211
- default:
3212
- @just --choose
3213
- ```
3214
-
3215
- ### Invoking `justfile`s in Other Directories
3216
-
3217
- If the first argument passed to `just` contains a `/`, then the following
3218
- occurs:
3219
-
3220
- 1. The argument is split at the last `/`.
3221
-
3222
- 2. The part before the last `/` is treated as a directory. `just` will start
3223
- its search for the `justfile` there, instead of in the current directory.
3224
-
3225
- 3. The part after the last slash is treated as a normal argument, or ignored
3226
- if it is empty.
3227
-
3228
- This may seem a little strange, but it's useful if you wish to run a command in
3229
- a `justfile` that is in a subdirectory.
3230
-
3231
- For example, if you are in a directory which contains a subdirectory named
3232
- `foo`, which contains a `justfile` with the recipe `build`, which is also the
3233
- default recipe, the following are all equivalent:
3234
-
3235
- ```console
3236
- $ (cd foo && just build)
3237
- $ just foo/build
3238
- $ just foo/
3239
- ```
3240
-
3241
- Additional recipes after the first are sought in the same `justfile`. For
3242
- example, the following are both equivalent:
3243
-
3244
- ```console
3245
- $ just foo/a b
3246
- $ (cd foo && just a b)
3247
- ```
3248
-
3249
- And will both invoke recipes `a` and `b` in `foo/justfile`.
3250
-
3251
- ### Imports
3252
-
3253
- One `justfile` can include the contents of another using `import` statements.
3254
-
3255
- If you have the following `justfile`:
3256
-
3257
- ```mf
3258
- import 'foo/bar.just'
3259
-
3260
- a: b
3261
- @echo A
3262
- ```
3263
-
3264
- And the following text in `foo/bar.just`:
3265
-
3266
- ```just
3267
- b:
3268
- @echo B
3269
- ```
3270
-
3271
- `foo/bar.just` will be included in `justfile` and recipe `b` will be defined:
3272
-
3273
- ```console
3274
- $ just b
3275
- B
3276
- $ just a
3277
- B
3278
- A
3279
- ```
3280
-
3281
- The `import` path can be absolute or relative to the location of the justfile
3282
- containing it. A leading `~/` in the import path is replaced with the current
3283
- users home directory.
3284
-
3285
- Justfiles are insensitive to order, so included files can reference variables
3286
- and recipes defined after the `import` statement.
3287
-
3288
- Imported files can themselves contain `import`s, which are processed
3289
- recursively.
3290
-
3291
- When `allow-duplicate-recipes` is set, recipes in parent modules override
3292
- recipes in imports. In a similar manner, when `allow-duplicate-variables` is
3293
- set, variables in parent modules override variables in imports.
3294
-
3295
- Imports may be made optional by putting a `?` after the `import` keyword:
3296
-
3297
- ```mf
3298
- import? 'foo/bar.just'
3299
- ```
3300
-
3301
- Missing source files for optional imports do not produce an error.
3302
-
3303
- ### Modules<sup>1.19.0</sup>
3304
-
3305
- A `justfile` can declare modules using `mod` statements.
3306
-
3307
- `mod` statements were stabilized in `just`<sup>1.31.0</sup>. In earlier
3308
- versions, you'll need to use the `--unstable` flag, `set unstable`, or set the
3309
- `JUST_UNSTABLE` environment variable to use them.
3310
-
3311
- If you have the following `justfile`:
3312
-
3313
- ```mf
3314
- mod bar
3315
-
3316
- a:
3317
- @echo A
3318
- ```
3319
-
3320
- And the following text in `bar.just`:
3321
-
3322
- ```just
3323
- b:
3324
- @echo B
3325
- ```
3326
-
3327
- `bar.just` will be included in `justfile` as a submodule. Recipes, aliases, and
3328
- variables defined in one submodule cannot be used in another, and each module
3329
- uses its own settings.
3330
-
3331
- Recipes in submodules can be invoked as subcommands:
3332
-
3333
- ```console
3334
- $ just bar b
3335
- B
3336
- ```
3337
-
3338
- Or with path syntax:
3339
-
3340
- ```console
3341
- $ just bar::b
3342
- B
3343
- ```
3344
-
3345
- If a module is named `foo`, just will search for the module file in `foo.just`,
3346
- `foo/mod.just`, `foo/justfile`, and `foo/.justfile`. In the latter two cases,
3347
- the module file may have any capitalization.
3348
-
3349
- Module statements may be of the form:
3350
-
3351
- ```mf
3352
- mod foo 'PATH'
3353
- ```
3354
-
3355
- Which loads the module's source file from `PATH`, instead of from the usual
3356
- locations. A leading `~/` in `PATH` is replaced with the current user's home
3357
- directory. `PATH` may point to the module source file itself, or to a directory
3358
- containing the module source file with the name `mod.just`, `justfile`, or
3359
- `.justfile`. In the latter two cases, the module file may have any
3360
- capitalization.
3361
-
3362
- Environment files are only loaded for the root justfile, and loaded environment
3363
- variables are available in submodules. Settings in submodules that affect
3364
- environment file loading are ignored.
3365
-
3366
- Recipes in submodules without the `[no-cd]` attribute run with the working
3367
- directory set to the directory containing the submodule source file.
3368
-
3369
- `justfile()` and `justfile_directory()` always return the path to the root
3370
- justfile and the directory that contains it, even when called from submodule
3371
- recipes.
3372
-
3373
- Modules may be made optional by putting a `?` after the `mod` keyword:
3374
-
3375
- ```mf
3376
- mod? foo
3377
- ```
3378
-
3379
- Missing source files for optional modules do not produce an error.
3380
-
3381
- Optional modules with no source file do not conflict, so you can have multiple
3382
- mod statements with the same name, but with different source file paths, as
3383
- long as at most one source file exists:
3384
-
3385
- ```mf
3386
- mod? foo 'bar.just'
3387
- mod? foo 'baz.just'
3388
- ```
3389
-
3390
- Modules may be given doc comments which appear in `--list`
3391
- output<sup>1.30.0</sup>:
3392
-
3393
- ```mf
3394
- # foo is a great module!
3395
- mod foo
3396
- ```
3397
-
3398
- ```console
3399
- $ just --list
3400
- Available recipes:
3401
- foo ... # foo is a great module!
3402
- ```
3403
-
3404
- Modules are still missing a lot of features, for example, the ability to depend
3405
- on recipes and refer to variables in other modules. See the
3406
- [module improvement tracking issue](https://github.com/casey/just/issues/2252)
3407
- for more information.
3408
-
3409
- ### Hiding `justfile`s
3410
-
3411
- `just` looks for `justfile`s named `justfile` and `.justfile`, which can be
3412
- used to keep a `justfile` hidden.
3413
-
3414
- ### Just Scripts
3415
-
3416
- By adding a shebang line to the top of a `justfile` and making it executable,
3417
- `just` can be used as an interpreter for scripts:
3418
-
3419
- ```console
3420
- $ cat > script <<EOF
3421
- #!/usr/bin/env just --justfile
3422
-
3423
- foo:
3424
- echo foo
3425
- EOF
3426
- $ chmod +x script
3427
- $ ./script foo
3428
- echo foo
3429
- foo
3430
- ```
3431
-
3432
- When a script with a shebang is executed, the system supplies the path to the
3433
- script as an argument to the command in the shebang. So, with a shebang of
3434
- `#!/usr/bin/env just --justfile`, the command will be `/usr/bin/env just --justfile PATH_TO_SCRIPT`.
3435
-
3436
- With the above shebang, `just` will change its working directory to the
3437
- location of the script. If you'd rather leave the working directory unchanged,
3438
- use `#!/usr/bin/env just --working-directory . --justfile`.
3439
-
3440
- Note: Shebang line splitting is not consistent across operating systems. The
3441
- previous examples have only been tested on macOS. On Linux, you may need to
3442
- pass the `-S` flag to `env`:
3443
-
3444
- ```just
3445
- #!/usr/bin/env -S just --justfile
3446
-
3447
- default:
3448
- echo foo
3449
- ```
3450
-
3451
- ### Formatting and dumping `justfile`s
3452
-
3453
- Each `justfile` has a canonical formatting with respect to whitespace and
3454
- newlines.
3455
-
3456
- You can overwrite the current justfile with a canonically-formatted version
3457
- using the currently-unstable `--fmt` flag:
3458
-
3459
- ```console
3460
- $ cat justfile
3461
- # A lot of blank lines
3462
-
3463
-
3464
-
3465
-
3466
-
3467
- some-recipe:
3468
- echo "foo"
3469
- $ just --fmt --unstable
3470
- $ cat justfile
3471
- # A lot of blank lines
3472
-
3473
- some-recipe:
3474
- echo "foo"
3475
- ```
3476
-
3477
- Invoking `just --fmt --check --unstable` runs `--fmt` in check mode. Instead of
3478
- overwriting the `justfile`, `just` will exit with an exit code of 0 if it is
3479
- formatted correctly, and will exit with 1 and print a diff if it is not.
3480
-
3481
- You can use the `--dump` command to output a formatted version of the
3482
- `justfile` to stdout:
3483
-
3484
- ```console
3485
- $ just --dump > formatted-justfile
3486
- ```
3487
-
3488
- The `--dump` command can be used with `--dump-format json` to print a JSON
3489
- representation of a `justfile`.
3490
-
3491
- ### Fallback to parent `justfile`s
3492
-
3493
- If a recipe is not found in a `justfile` and the `fallback` setting is set,
3494
- `just` will look for `justfile`s in the parent directory and up, until it
3495
- reaches the root directory. `just` will stop after it reaches a `justfile` in
3496
- which the `fallback` setting is `false` or unset.
3497
-
3498
- As an example, suppose the current directory contains this `justfile`:
3499
-
3500
- ```just
3501
- set fallback
3502
- foo:
3503
- echo foo
3504
- ```
3505
-
3506
- And the parent directory contains this `justfile`:
3507
-
3508
- ```just
3509
- bar:
3510
- echo bar
3511
- ```
3512
-
3513
- ```console
3514
- $ just bar
3515
- Trying ../justfile
3516
- echo bar
3517
- bar
3518
- ```
3519
-
3520
- ### Avoiding Argument Splitting
3521
-
3522
- Given this `justfile`:
3523
-
3524
- ```just
3525
- foo argument:
3526
- touch {{argument}}
3527
- ```
3528
-
3529
- The following command will create two files, `some` and `argument.txt`:
3530
-
3531
- ```console
3532
- $ just foo "some argument.txt"
3533
- ```
3534
-
3535
- The users shell will parse `"some argument.txt"` as a single argument, but when
3536
- `just` replaces `touch {{argument}}` with `touch some argument.txt`, the quotes
3537
- are not preserved, and `touch` will receive two arguments.
3538
-
3539
- There are a few ways to avoid this: quoting, positional arguments, and exported
3540
- arguments.
3541
-
3542
- #### Quoting
3543
-
3544
- Quotes can be added around the `{{argument}}` interpolation:
3545
-
3546
- ```just
3547
- foo argument:
3548
- touch '{{argument}}'
3549
- ```
3550
-
3551
- This preserves `just`'s ability to catch variable name typos before running,
3552
- for example if you were to write `{{argument}}`, but will not do what you want
3553
- if the value of `argument` contains single quotes.
3554
-
3555
- #### Positional Arguments
3556
-
3557
- The `positional-arguments` setting causes all arguments to be passed as
3558
- positional arguments, allowing them to be accessed with `$1`, `$2`, …, and
3559
- `$@`, which can be then double-quoted to avoid further splitting by the shell:
3560
-
3561
- ```just
3562
- set positional-arguments
3563
-
3564
- foo argument:
3565
- touch "$1"
3566
- ```
3567
-
3568
- This defeats `just`'s ability to catch typos, for example if you type `$2`
3569
- instead of `$1`, but works for all possible values of `argument`, including
3570
- those with double quotes.
3571
-
3572
- #### Exported Arguments
3573
-
3574
- All arguments are exported when the `export` setting is set:
3575
-
3576
- ```just
3577
- set export
3578
-
3579
- foo argument:
3580
- touch "$argument"
3581
- ```
3582
-
3583
- Or individual arguments may be exported by prefixing them with `$`:
3584
-
3585
- ```just
3586
- foo $argument:
3587
- touch "$argument"
3588
- ```
3589
-
3590
- This defeats `just`'s ability to catch typos, for example if you type
3591
- `$argument`, but works for all possible values of `argument`, including those
3592
- with double quotes.
3593
-
3594
- ### Configuring the Shell
3595
-
3596
- There are a number of ways to configure the shell for linewise recipes, which
3597
- are the default when a recipe does not start with a `#!` shebang. Their
3598
- precedence, from highest to lowest, is:
3599
-
3600
- 1. The `--shell` and `--shell-arg` command line options. Passing either of
3601
- these will cause `just` to ignore any settings in the current justfile.
3602
- 2. `set windows-shell := [...]`
3603
- 3. `set windows-powershell` (deprecated)
3604
- 4. `set shell := [...]`
3605
-
3606
- Since `set windows-shell` has higher precedence than `set shell`, you can use
3607
- `set windows-shell` to pick a shell on Windows, and `set shell` to pick a shell
3608
- for all other platforms.
3609
-
3610
- ### Timestamps
3611
-
3612
- `just` can print timestamps before each recipe commands:
3613
-
3614
- ```just
3615
- recipe:
3616
- echo one
3617
- sleep 2
3618
- echo two
3619
- ```
3620
-
3621
- ```
3622
- $ just --timestamp recipe
3623
- [07:28:46] echo one
3624
- one
3625
- [07:28:46] sleep 2
3626
- [07:28:48] echo two
3627
- two
3628
- ```
3629
-
3630
- By default, timestamps are formatted as `HH:MM:SS`. The format can be changed
3631
- with `--timestamp-format`:
3632
-
3633
- ```
3634
- $ just --timestamp recipe --timestamp-format '%H:%M:%S%.3f %Z'
3635
- [07:32:11:.349 UTC] echo one
3636
- one
3637
- [07:32:11:.350 UTC] sleep 2
3638
- [07:32:13:.352 UTC] echo two
3639
- two
3640
- ```
3641
-
3642
- The argument to `--timestamp-format` is a `strftime`-style format string, see
3643
- the
3644
- [`chrono` library docs](https://docs.rs/chrono/latest/chrono/format/strftime/index.html)
3645
- for details.
3646
-
3647
- Changelog
3648
- ---------
3649
-
3650
- A changelog for the latest release is available in
3651
- [CHANGELOG.md](https://raw.githubusercontent.com/casey/just/master/CHANGELOG.md).
3652
- Changelogs for previous releases are available on
3653
- [the releases page](https://github.com/casey/just/releases). `just --changelog`
3654
- can also be used to make a `just` binary print its changelog.
3655
-
3656
- Miscellanea
3657
- -----------
3658
-
3659
- ### Re-running recipes when files change
3660
-
3661
- [`watchexec`](https://github.com/mattgreen/watchexec) can re-run any command
3662
- when files change.
3663
-
3664
- To re-run the recipe `foo` when any file changes:
3665
-
3666
- ```console
3667
- watchexec just foo
3668
- ```
3669
-
3670
- See `watchexec --help` for more info, including how to specify which files
3671
- should be watched for changes.
3672
-
3673
- ### Running tasks in parallel
3674
-
3675
- GNU parallel can be used to run tasks concurrently:
3676
-
3677
- ```just
3678
- parallel:
3679
- #!/usr/bin/env -S parallel --shebang --ungroup --jobs {{ num_cpus() }}
3680
- echo task 1 start; sleep 3; echo task 1 done
3681
- echo task 2 start; sleep 3; echo task 2 done
3682
- echo task 3 start; sleep 3; echo task 3 done
3683
- echo task 4 start; sleep 3; echo task 4 done
3684
- ```
3685
-
3686
- ### Shell Alias
3687
-
3688
- For lightning-fast command running, put `alias j=just` in your shell's
3689
- configuration file.
3690
-
3691
- In `bash`, the aliased command may not keep the shell completion functionality
3692
- described in the next section. Add the following line to your `.bashrc` to use
3693
- the same completion function as `just` for your aliased command:
3694
-
3695
- ```console
3696
- complete -F _just -o bashdefault -o default j
3697
- ```
3698
-
3699
- ### Shell Completion Scripts
3700
-
3701
- Shell completion scripts for Bash, Elvish, Fish, Nushell, PowerShell, and Zsh
3702
- are available [release archives](https://github.com/casey/just/releases).
3703
-
3704
- The `just` binary can also generate the same completion scripts at runtime
3705
- using `just --completions SHELL`:
3706
-
3707
- ```console
3708
- $ just --completions zsh > just.zsh
3709
- ```
3710
-
3711
- Please refer to your shell's documentation for how to install them.
3712
-
3713
- *macOS Note:* Recent versions of macOS use zsh as the default shell. If you use
3714
- Homebrew to install `just`, it will automatically install the most recent copy
3715
- of the zsh completion script in the Homebrew zsh directory, which the built-in
3716
- version of zsh doesn't know about by default. It's best to use this copy of the
3717
- script if possible, since it will be updated whenever you update `just` via
3718
- Homebrew. Also, many other Homebrew packages use the same location for
3719
- completion scripts, and the built-in zsh doesn't know about those either. To
3720
- take advantage of `just` completion in zsh in this scenario, you can set
3721
- `fpath` to the Homebrew location before calling `compinit`. Note also that Oh
3722
- My Zsh runs `compinit` by default. So your `.zshrc` file could look like this:
3723
-
3724
- ```zsh
3725
- # Init Homebrew, which adds environment variables
3726
- eval "$(brew shellenv)"
3727
-
3728
- fpath=($HOMEBREW_PREFIX/share/zsh/site-functions $fpath)
3729
-
3730
- # Then choose one of these options:
3731
- # 1. If you're using Oh My Zsh, you can initialize it here
3732
- # source $ZSH/oh-my-zsh.sh
3733
-
3734
- # 2. Otherwise, run compinit yourself
3735
- # autoload -U compinit
3736
- # compinit
3737
- ```
3738
-
3739
- ### Man Page
3740
-
3741
- `just` can print its own man page with `just --man`. Man pages are written in
3742
- [`roff`](https://en.wikipedia.org/wiki/Roff_%28software%29), a venerable markup
3743
- language and one of the first practical applications of Unix. If you have
3744
- [`groff`](https://www.gnu.org/software/groff/) installed you can view the man
3745
- page with `just --man | groff -mandoc -Tascii | less`.
3746
-
3747
- ### Grammar
3748
-
3749
- A non-normative grammar of `justfile`s can be found in
3750
- [GRAMMAR.md](https://github.com/casey/just/blob/master/GRAMMAR.md).
3751
-
3752
- ### just.sh
3753
-
3754
- Before `just` was a fancy Rust program it was a tiny shell script that called
3755
- `make`. You can find the old version in
3756
- [contrib/just.sh](https://github.com/casey/just/blob/master/contrib/just.sh).
3757
-
3758
- ### Global and User `justfile`s
3759
-
3760
- If you want some recipes to be available everywhere, you have a few options.
3761
-
3762
- #### Global Justfile
3763
-
3764
- `just --global-justfile`, or `just -g` for short, searches the following paths,
3765
- in-order, for a justfile:
3766
-
3767
- - `$XDG_CONFIG_HOME/just/justfile`
3768
- - `$HOME/.config/just/justfile`
3769
- - `$HOME/justfile`
3770
- - `$HOME/.justfile`
3771
-
3772
- You can put recipes that are used across many projects in a global justfile to
3773
- easily invoke them from any directory.
3774
-
3775
- #### User justfile tips
3776
-
3777
- You can also adopt some of the following workflows. These tips assume you've
3778
- created a `justfile` at `~/.user.justfile`, but you can put this `justfile`
3779
- at any convenient path on your system.
3780
-
3781
- ##### Recipe Aliases
3782
-
3783
- If you want to call the recipes in `~/.user.justfile` by name, and don't mind
3784
- creating an alias for every recipe, add the following to your shell's
3785
- initialization script:
3786
-
3787
- ```console
3788
- for recipe in `just --justfile ~/.user.justfile --summary`; do
3789
- alias $recipe="just --justfile ~/.user.justfile --working-directory . $recipe"
3790
- done
3791
- ```
3792
-
3793
- Now, if you have a recipe called `foo` in `~/.user.justfile`, you can just type
3794
- `foo` at the command line to run it.
3795
-
3796
- It took me way too long to realize that you could create recipe aliases like
3797
- this. Notwithstanding my tardiness, I am very pleased to bring you this major
3798
- advance in `justfile` technology.
3799
-
3800
- ##### Forwarding Alias
3801
-
3802
- If you'd rather not create aliases for every recipe, you can create a single alias:
3803
-
3804
- ```console
3805
- alias .j='just --justfile ~/.user.justfile --working-directory .'
3806
- ```
3807
-
3808
- Now, if you have a recipe called `foo` in `~/.user.justfile`, you can just type
3809
- `.j foo` at the command line to run it.
3810
-
3811
- I'm pretty sure that nobody actually uses this feature, but it's there.
3812
-
3813
- ¯\\\_(ツ)\_/¯
3814
-
3815
- ##### Customization
3816
-
3817
- You can customize the above aliases with additional options. For example, if
3818
- you'd prefer to have the recipes in your `justfile` run in your home directory,
3819
- instead of the current directory:
3820
-
3821
- ```console
3822
- alias .j='just --justfile ~/.user.justfile --working-directory ~'
3823
- ```
3824
-
3825
- ### Node.js `package.json` Script Compatibility
3826
-
3827
- The following export statement gives `just` recipes access to local Node module
3828
- binaries, and makes `just` recipe commands behave more like `script` entries in
3829
- Node.js `package.json` files:
3830
-
3831
- ```just
3832
- export PATH := "./node_modules/.bin:" + env_var('PATH')
3833
- ```
3834
-
3835
- ### Paths on Windows
3836
-
3837
- On Windows, functions that return paths will return `\`-separated paths. When
3838
- not using PowerShell or `cmd.exe` these paths should be quoted to prevent the
3839
- `\`s from being interpreted as character escapes:
3840
-
3841
- ```just
3842
- ls:
3843
- echo '{{absolute_path(".")}}'
3844
- ```
3845
-
3846
- ### Remote Justfiles
3847
-
3848
- If you wish to include a `mod` or `import` source file in many `justfiles`
3849
- without needing to duplicate it, you can use an optional `mod` or `import`,
3850
- along with a recipe to fetch the module source:
3851
-
3852
- ```just
3853
- import? 'foo.just'
3854
-
3855
- fetch:
3856
- curl https://raw.githubusercontent.com/casey/just/master/justfile > foo.just
3857
- ```
3858
-
3859
- Given the above `justfile`, after running `just fetch`, the recipes in
3860
- `foo.just` will be available.
3861
-
3862
- ### Alternatives and Prior Art
3863
-
3864
- There is no shortage of command runners! Some more or less similar alternatives
3865
- to `just` include:
3866
-
3867
- - [make](https://en.wikipedia.org/wiki/Make_(software)): The Unix build tool
3868
- that inspired `just`. There are a few different modern day descendents of the
3869
- original `make`, including
3870
- [FreeBSD Make](https://www.freebsd.org/cgi/man.cgi?make(1)) and
3871
- [GNU Make](https://www.gnu.org/software/make/).
3872
- - [task](https://github.com/go-task/task): A YAML-based command runner written
3873
- in Go.
3874
- - [maid](https://github.com/egoist/maid): A Markdown-based command runner
3875
- written in JavaScript.
3876
- - [microsoft/just](https://github.com/microsoft/just): A JavaScript-based
3877
- command runner written in JavaScript.
3878
- - [cargo-make](https://github.com/sagiegurari/cargo-make): A command runner for
3879
- Rust projects.
3880
- - [mmake](https://github.com/tj/mmake): A wrapper around `make` with a number
3881
- of improvements, including remote includes.
3882
- - [robo](https://github.com/tj/robo): A YAML-based command runner written in
3883
- Go.
3884
- - [mask](https://github.com/jakedeichert/mask): A Markdown-based command runner
3885
- written in Rust.
3886
- - [makesure](https://github.com/xonixx/makesure): A simple and portable command
3887
- runner written in AWK and shell.
3888
- - [haku](https://github.com/VladimirMarkelov/haku): A make-like command runner
3889
- written in Rust.
3890
-
3891
- Contributing
3892
- ------------
3893
-
3894
- `just` welcomes your contributions! `just` is released under the maximally
3895
- permissive
3896
- [CC0](https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt) public
3897
- domain dedication and fallback license, so your changes must also be released
3898
- under this license.
3899
-
3900
- ### Getting Started
3901
-
3902
- `just` is written in Rust. Use
3903
- [rustup](https://www.rust-lang.org/tools/install) to install a Rust toolchain.
3904
-
3905
- `just` is extensively tested. All new features must be covered by unit or
3906
- integration tests. Unit tests are under
3907
- [src](https://github.com/casey/just/blob/master/src), live alongside the code
3908
- being tested, and test code in isolation. Integration tests are in the [tests
3909
- directory](https://github.com/casey/just/blob/master/tests) and test the `just`
3910
- binary from the outside by invoking `just` on a given `justfile` and set of
3911
- command-line arguments, and checking the output.
3912
-
3913
- You should write whichever type of tests are easiest to write for your feature
3914
- while still providing good test coverage.
3915
-
3916
- Unit tests are useful for testing new Rust functions that are used internally
3917
- and as an aid for development. A good example are the unit tests which cover
3918
- the
3919
- [`unindent()` function](https://github.com/casey/just/blob/master/src/unindent.rs),
3920
- used to unindent triple-quoted strings and backticks. `unindent()` has a bunch
3921
- of tricky edge cases which are easy to exercise with unit tests that call
3922
- `unindent()` directly.
3923
-
3924
- Integration tests are useful for making sure that the final behavior of the
3925
- `just` binary is correct. `unindent()` is also covered by integration tests
3926
- which make sure that evaluating a triple-quoted string produces the correct
3927
- unindented value. However, there are not integration tests for all possible
3928
- cases. These are covered by faster, more concise unit tests that call
3929
- `unindent()` directly.
3930
-
3931
- Existing integration tests are in two forms, those that use the `test!` macro
3932
- and those that use the `Test` struct directly. The `test!` macro, while often
3933
- concise, is less flexible and harder to understand, so new tests should use the
3934
- `Test` struct. The `Test` struct is a builder which allows for easily invoking
3935
- `just` with a given `justfile`, arguments, and environment variables, and
3936
- checking the program's stdout, stderr, and exit code .
3937
-
3938
- ### Contribution Workflow
3939
-
3940
- 1. Make sure the feature is wanted. There should be an open issue about the
3941
- feature with a comment from [@casey](https://github.com/casey) saying that
3942
- it's a good idea or seems reasonable. If there isn't, open a new issue and
3943
- ask for feedback.
3944
-
3945
- There are lots of good features which can't be merged, either because they
3946
- aren't backwards compatible, have an implementation which would
3947
- overcomplicate the codebase, or go against `just`'s design philosophy.
3948
-
3949
- 2. Settle on the design of the feature. If the feature has multiple possible
3950
- implementations or syntaxes, make sure to nail down the details in the
3951
- issue.
3952
-
3953
- 3. Clone `just` and start hacking. The best workflow is to have the code you're
3954
- working on in an editor alongside a job that re-runs tests whenever a file
3955
- changes. You can run such a job by installing
3956
- [cargo-watch](https://github.com/watchexec/cargo-watch) with `cargo install
3957
- cargo-watch` and running `just watch test`.
3958
-
3959
- 4. Add a failing test for your feature. Most of the time this will be an
3960
- integration test which exercises the feature end-to-end. Look for an
3961
- appropriate file to put the test in in
3962
- [tests](https://github.com/casey/just/blob/master/tests), or add a new file
3963
- in [tests](https://github.com/casey/just/blob/master/tests) and add a `mod`
3964
- statement importing that file in
3965
- [tests/lib.rs](https://github.com/casey/just/blob/master/tests/lib.rs).
3966
-
3967
- 5. Implement the feature.
3968
-
3969
- 6. Run `just ci` to make sure that all tests, lints, and checks pass.
3970
-
3971
- 7. Open a PR with the new code that is editable by maintainers. PRs often
3972
- require rebasing and minor tweaks. If the PR is not editable by maintainers,
3973
- each rebase and tweak will require a round trip of code review. Your PR may
3974
- be summarily closed if it is not editable by maintainers.
3975
-
3976
- 8. Incorporate feedback.
3977
-
3978
- 9. Enjoy the sweet feeling of your PR getting merged!
3979
-
3980
- Feel free to open a draft PR at any time for discussion and feedback.
3981
-
3982
- ### Hints
3983
-
3984
- Here are some hints to get you started with specific kinds of new features,
3985
- which you can use in addition to the contribution workflow above.
3986
-
3987
- #### Adding a New Attribute
3988
-
3989
- 1. Write a new integration test in
3990
- [tests/attributes.rs](https://github.com/casey/just/blob/master/tests/attributes.rs).
3991
-
3992
- 2. Add a new variant to the
3993
- [`Attribute`](https://github.com/casey/just/blob/master/src/attribute.rs)
3994
- enum.
3995
-
3996
- 3. Implement the functionality of the new attribute.
3997
-
3998
- 4. Run `just ci` to make sure that all tests pass.
3999
-
4000
- ### Janus
4001
-
4002
- [Janus](https://github.com/casey/janus) is a tool for checking whether a change
4003
- to `just` breaks or changes the interpretation of existing `justfile`s. It
4004
- collects and analyzes public `justfile`s on GitHub.
4005
-
4006
- Before merging a particularly large or gruesome change, Janus should be run to
4007
- make sure that nothing breaks. Don't worry about running Janus yourself, Casey
4008
- will happily run it for you on changes that need it.
4009
-
4010
- ### Minimum Supported Rust Version
4011
-
4012
- The minimum supported Rust version, or MSRV, is current stable Rust. It may
4013
- build on older versions of Rust, but this is not guaranteed.
4014
-
4015
- ### New Releases
4016
-
4017
- New releases of `just` are made frequently so that users quickly get access to
4018
- new features.
4019
-
4020
- Release commit messages use the following template:
4021
-
4022
- ```
4023
- Release x.y.z
4024
-
4025
- - Bump version: x.y.z → x.y.z
4026
- - Update changelog
4027
- - Update changelog contributor credits
4028
- - Update dependencies
4029
- - Update version references in readme
4030
- ```
4031
-
4032
- Frequently Asked Questions
4033
- --------------------------
4034
-
4035
- ### What are the idiosyncrasies of Make that Just avoids?
4036
-
4037
- `make` has some behaviors which are confusing, complicated, or make it
4038
- unsuitable for use as a general command runner.
4039
-
4040
- One example is that under some circumstances, `make` won't actually run the
4041
- commands in a recipe. For example, if you have a file called `test` and the
4042
- following makefile:
4043
-
4044
- ```just
4045
- test:
4046
- ./test
4047
- ```
4048
-
4049
- `make` will refuse to run your tests:
4050
-
4051
- ```console
4052
- $ make test
4053
- make: `test' is up to date.
4054
- ```
4055
-
4056
- `make` assumes that the `test` recipe produces a file called `test`. Since this
4057
- file exists and the recipe has no other dependencies, `make` thinks that it
4058
- doesn't have anything to do and exits.
4059
-
4060
- To be fair, this behavior is desirable when using `make` as a build system, but
4061
- not when using it as a command runner. You can disable this behavior for
4062
- specific targets using `make`'s built-in
4063
- [`.PHONY` target name](https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html),
4064
- but the syntax is verbose and can be hard to remember. The explicit list of
4065
- phony targets, written separately from the recipe definitions, also introduces
4066
- the risk of accidentally defining a new non-phony target. In `just`, all
4067
- recipes are treated as if they were phony.
4068
-
4069
- Other examples of `make`'s idiosyncrasies include the difference between `=`
4070
- and `:=` in assignments, the confusing error messages that are produced if you
4071
- mess up your makefile, needing `$$` to use environment variables in recipes,
4072
- and incompatibilities between different flavors of `make`.
4073
-
4074
- ### What's the relationship between Just and Cargo build scripts?
4075
-
4076
- [`cargo` build scripts](http://doc.crates.io/build-script.html) have a pretty
4077
- specific use, which is to control how `cargo` builds your Rust project. This
4078
- might include adding flags to `rustc` invocations, building an external
4079
- dependency, or running some kind of codegen step.
4080
-
4081
- `just`, on the other hand, is for all the other miscellaneous commands you
4082
- might run as part of development. Things like running tests in different
4083
- configurations, linting your code, pushing build artifacts to a server,
4084
- removing temporary files, and the like.
4085
-
4086
- Also, although `just` is written in Rust, it can be used regardless of the
4087
- language or build system your project uses.
4088
-
4089
- Further Ramblings
4090
- -----------------
4091
-
4092
- I personally find it very useful to write a `justfile` for almost every
4093
- project, big or small.
4094
-
4095
- On a big project with multiple contributors, it's very useful to have a file
4096
- with all the commands needed to work on the project close at hand.
4097
-
4098
- There are probably different commands to test, build, lint, deploy, and the
4099
- like, and having them all in one place is useful and cuts down on the time you
4100
- have to spend telling people which commands to run and how to type them.
4101
-
4102
- And, with an easy place to put commands, it's likely that you'll come up with
4103
- other useful things which are part of the project's collective wisdom, but
4104
- which aren't written down anywhere, like the arcane commands needed for some
4105
- part of your revision control workflow, to install all your project's
4106
- dependencies, or all the random flags you might need to pass to the build
4107
- system.
4108
-
4109
- Some ideas for recipes:
4110
-
4111
- - Deploying/publishing the project
4112
-
4113
- - Building in release mode vs debug mode
4114
-
4115
- - Running in debug mode or with logging enabled
4116
-
4117
- - Complex git workflows
4118
-
4119
- - Updating dependencies
4120
-
4121
- - Running different sets of tests, for example fast tests vs slow tests, or
4122
- running them with verbose output
60
+ > **Note:** To pass Execa options to `rust-just`, use the `--execaoptions <OPTIONS>` flag, where `OPTIONS` is in JSON format.
61
+ >
62
+ > For example:
63
+ >
64
+ > ```
65
+ > ~/$ rust-just --execaoptions '{"stdio": "inherit", "reject": false}' [OPTIONS] [ARGUMENTS]...
66
+ > ```
67
+ >
68
+ > For a complete list of available Execa options, refer to the [Execa API documentation](https://github.com/sindresorhus/execa/blob/main/docs/api.md#options-1).
4123
69
 
4124
- - Any complex set of commands that you really should write down somewhere, if
4125
- only to be able to remember them
70
+ To read more visit: https://just.systems/man/en/
4126
71
 
4127
- Even for small, personal projects it's nice to be able to remember commands by
4128
- name instead of ^Reverse searching your shell history, and it's a huge boon to
4129
- be able to go into an old project written in a random language with a
4130
- mysterious build system and know that all the commands you need to do whatever
4131
- you need to do are in the `justfile`, and that if you type `just` something
4132
- useful (or at least interesting!) will probably happen.
72
+ ## Author & Maintainer
4133
73
 
4134
- For ideas for recipes, check out
4135
- [this project's `justfile`](https://github.com/casey/just/blob/master/justfile),
4136
- or some of the
4137
- `justfile`s
4138
- [out in the wild](https://github.com/search?q=path%3A**%2Fjustfile&type=code).
74
+ - [@gnpaone](https://www.github.com/gnpaone)
4139
75
 
4140
- Anyways, I think that's about it for this incredibly long-winded README.
76
+ ## Documentation
4141
77
 
4142
- I hope you enjoy using `just` and find great success and satisfaction in all
4143
- your computational endeavors!
78
+ The documentation is available as a [book](https://just.systems/man/en/).
4144
79
 
4145
- 😸
80
+ <sub>
81
+ <hr>
82
+ <strong>Disclaimer:</strong>
83
+ The <a href="https://www.npmjs.com/package/rust-just"><code>rust-just</code> npm package</a> is maintained by <a href="https://www.github.com/gnpaone">@gnpaone</a> with permission from the original <code>just</code> developer. This package is not officially maintained by <a href="https://github.com/casey"><code>just</code>’s creator</a> but uses up-to-date, official binaries from the <a href="https://github.com/casey/just">casey/just</a> repository at the time of release to ensure compatibility and authenticity.
84
+ </sub>