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