What is
just
?
just
is a task runner that allows you to automate repetitive tasks. You define tasks in aJustfile
, and instead of remembering long commands, you can simply runjust <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 | # Justfile |
Explanation:
hello:
is the task name.echo "Hello, World!"
is the command that will run when you invoke this task.
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 | # Justfile |
{{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 | # Justfile |
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 | # Justfile |
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 | Setting up the environment |
Conditionals and Loops
just
supports basic conditionals and loops, which you can use to add more logic to your tasks.
Conditional Example:
1 | # Justfile |
This example checks if the dev.env
file exists and prints a message based on whether it’s found.
Loop Example:
1 | # Justfile |
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 | # Justfile |
Now, you can run these tasks simply by typing:
1 | just install # Install dependencies |
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.