casey / casey/just

Conditional exposure of recipe or module based on attribute with evaluation

Open
#2,747 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
35.8k
Forks
846
Avg merge
27m
Merged PRs (30d)
3

Description

I use just for recipes with shortcut commands for developing web applications locally, run them in CI and when being logged in to a container running on production.

Ideally, when executing something like `just --list` I would like to see only commands that are available to the respective environment.
On my own machine this may be `just up` to launch all containers for local development. When being being in a container on my local machine this might be a command to drop the database and to create a new one based on the dummy data that I have available `just reset-db`.
Off course I do not want to have this command available in production.

I use environment variables which already allow me to identify the context of my shell.
So I could already wrap the code in my recipes in an if statement to protect executing the wrong commands.

However ideally I only want to expose them based on the environment that they are in.

I noticed the attributes like `[windows]` and `[macos]`, which seem to do something like I want to do, but lack the flexibility.

It would be nice to have something available which allows me to evaluate an expression. When it is true, the module or recipe will be available.

So something like:

```
[available-if env('CI')]
test:
uv run pytest

[available-if env('CI')]
mod ci

[available-if env('environment') == 'local']
reset-db:
django reset_db --no-input

[available-if !env('incontainer')]
up:
docker compose up --detach
```

With Make I was able to create something like the above as if statements could be around the recipes, but it seems like this is not supported in just.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.