Rust Command Line Tool - Just
A while ago I decided to take on AOC in Rust. Then work got busy and the later puzzles got harder, so I put the whole thing on hold. Recently I shared my solutions on YouTube, and that is where I found a cool little tool called Just. In the demo, Just replaced the long command that you must type every time with something very short.
Just a Command Runner
Just is a simple tool. It wraps task scripts, and that is all it does. I came across something similar at work: Task, a tool that is written in Go. There I only used a Taskfile that somebody else wrote. Our CI used a different solution, so I never looked at this kind of tool closely.
Here is how the two compare. Task can arrange tasks in finer detail, but it is also more complex. Just has far fewer features, but those features are enough in normal situations. You write a Taskfile in YAML. You must also learn how to configure it, so the learning cost is a little higher. Just is based on the shell, which is easier for me. The rest, such as the settings for environment variables, is about the same.
Quick Start
The first step is to install the Just CLI. You can install it with Cargo:
cargo install justAfter the installation, pick a folder and create a file with the name justfile. Look at the first example in the manual:
## justfile
recipe-name:
echo 'This is a recipe!'
another-recipe:
@echo 'This is another recipe.'This justfile has two commands: recipe-name and another-recipe. Under each name, you write the shell commands that it runs.
Run just --list first. It shows the commands that are available:
❯ just --list
Available recipes:
another-receipe
recipe-nameTo run a specific recipe, use just <recipe-name>.
For more detail on the features, see the Just Programmer's Manual.
Miscellaneous
I wanted a tool like Just because it bundles the environment variables into the command up front. We usually isolate an application in a container. To simulate a different environment, we swap the environment variables. At work, everybody keeps these settings in an IDE. People prefer different IDEs, so the settings do not transfer easily.
With Just, every setting sits in the justfile, where you can see it at a glance. The settings are also easier to share, although you still have to configure the IDE separately. For now, the use that I can picture is local development. On my own machine I can switch environments easily for each situation: solo development, or local integration tests.
The manual lists several reasons why a command runner is valuable. Before I read it, I did not really understand what these tools are for. The flashy demos on YouTube are what showed me the point. Some of them generate a template from a few commands. Others run tests and load tests at many levels.
In the past I skipped tests because they felt like a chore. Now one short command runs them, and the whole thing flows.
P.S. Somebody also contributed a GitHub Action, so you can use Just in CI without a problem.