What is just?

just is a task runner that allows you to automate repetitive tasks. You define tasks in a Justfile, and instead of remembering long commands, you can simply run just <task> to execute them. This makes project management much simpler.

Creating a Justfile

To use just, create a Justfile in the root directory of your project. This file is where you define your tasks.

Basic Task Definition

A Justfile contains one or more tasks. Each task has a name followed by the commands you want to run.

1
2
3
4
5
# Justfile

# Define a task called hello
hello:
echo "Hello, World!"

Explanation:

Running the Task

Once you’ve created the Justfile, you can run the task in your terminal by typing:

1
just hello

You should see the following output:

1
Hello, World!

Using Variables in Tasks

You can define variables in the Justfile and use them in your tasks. Variables are defined simply by assignment.

Example:

1
2
3
4
5
6
7
8
# Justfile

# Define a variable
name := "Alice"

# Define a task
greet:
echo "Hello, {{name}}!"

{{name}} will be replaced with the value of the name variable. When you run the task:

1
just greet

The output will be:

1
Hello, Alice!

Using Command-Line Arguments

You can also pass arguments from the command line to your tasks. This is useful if you want your tasks to be dynamic and change based on input.

1
2
3
4
5
# Justfile

# Task with command-line argument
greet_name name:
echo "Hello, {{name}}!"

Now you can run the task and provide a name as an argument:

1
just greet_name Bob

Output:

1
Hello, Bob!

Task Dependencies

You can make tasks depend on other tasks. This allows you to chain tasks together, ensuring that one task runs before another.

Example:

1
2
3
4
5
6
7
8
9
# Justfile

# Define a setup task
setup:
echo "Setting up the environment"

# Define a build task, which depends on setup
build: setup
echo "Building the project"

In this case, running just build will first execute the setup task, and then it will proceed with the build task:

1
just build

Output:

1
2
Setting up the environment
Building the project

Conditionals and Loops

just supports basic conditionals and loops, which you can use to add more logic to your tasks.

Conditional Example:

1
2
3
4
5
6
7
8
9
# Justfile

# Task: Check environment
check_env:
if test -f "dev.env"; then
echo "Development environment detected"
else
echo "Production environment detected"
fi

This example checks if the dev.env file exists and prints a message based on whether it’s found.

Loop Example:

1
2
3
4
5
6
7
# Justfile

# Task: Print numbers from 1 to 5
print_numbers:
for i in {1..5}; do
echo "Number: $i"
done

Using Just for Python Projects

If you have a Python project, you can use just to manage common tasks like running tests, installing dependencies, or running your application.

1
2
3
4
5
6
7
8
9
10
11
12
13
# Justfile

# Task: Install dependencies
install:
pip install -r requirements.txt

# Task: Run the Python script
run:
python3 app.py

# Task: Run unit tests
test:
pytest tests/

Now, you can run these tasks simply by typing:

1
2
3
just install    # Install dependencies
just run # Run the Python script
just test # Run unit tests

Advanced Usage: Skipping Tasks

You can skip a task’s execution by prefixing its name with @. This is useful when you want to skip a task in a chain.

1
just @install

This will skip the install task and proceed with the next task.