I just found a new (to me) Justfile technique that brings me joy: Arguments as f...
Marijke Luttekes @mahryekuh@hachyderm.io
I just found a new (to me) Justfile technique that brings me joy:
Arguments as flag.
The scenario:
* I want to call one of two available NPM commands through a Justfile.
* The NPM command is either Biome in check mode, or Biome in fix mode; respectively called `biome` and `biome:fix`.
* I want to avoid creating two Just recipes, just because it feels better than having two (my current situation).
The solution:
1. Create a recipe argument `fix`, written as flag `-f` or `--fix` on the command-line.
2. The value of argument `fix` is an empty string by default, or string `:fix` when passed.
3. The value of `fix` gets appended to the string 'biome', where this string represents the name of the NPM script we call.
4. This means that we can call both NPM scripts from a single Just recipe, all by passing an optional flag.
5. Profit!
```
# … (omitted here is a recipe called "run" that runs NPM through Docker)
# Run Biome, optionally applying fixes.
[group('commands')]
[arg('fix', short='f', long='fix', value=':fix', help='Pass to apply automatic fixes.')]
biome fix='': (run 'biome' + fix)
```
NB. I might turn this into a proper blog article later.