### Example: Install Just to ~/bin Source: https://github.com/casey/just/blob/master/README.md This example demonstrates creating a bin directory, installing 'just' to it, and updating the PATH environment variable. It concludes with a check for the 'just' command. ```bash # create ~/bin mkdir -p ~/bin # download and extract just to ~/bin/just curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to ~/bin # add `~/bin` to the paths that your shell searches for executables # this line should be added to your shell's initialization file, # e.g. `~/.bashrc` or `~/.zshrc` export PATH="$PATH:$HOME/bin" # just should now be executable just --help ``` -------------------------------- ### Project Setup Recipes Source: https://github.com/casey/just/blob/master/_autodocs/INDEX.md Defines common project setup tasks like installing dependencies, building, testing, formatting, and deploying. Uses attributes like `doc` and `confirm` for enhanced recipe behavior. ```just set default-list default: help [doc("Show available recipes")] help: just --list [doc("Install dependencies")] install: npm install [doc("Build the project")] build: npm run build [doc("Run tests")] test: build npm test [doc("Format code")] fmt: npx prettier --write . [doc("Deploy to production")] [confirm("Deploy to production?")] deploy: test npm run deploy ``` -------------------------------- ### Install Just with arkade Source: https://github.com/casey/just/blob/master/README.md Use the arkade package manager to get the 'just' tool. ```bash arkade get just ``` -------------------------------- ### Install Just with Snap Source: https://github.com/casey/just/blob/master/README.md Install 'just' using Snap, with edge and classic channels. ```bash snap install --edge --classic just ``` -------------------------------- ### Python Project Setup with Just Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Configure a Justfile for a Python project. This setup includes managing virtual environments, installing dependencies, running tests, code formatting, type checking, linting, and cleaning artifacts. ```just set shell := ["bash", "-uc"] virtualenv := ".venv" python := venv / "bin/python" pip := venv / "bin/pip" # Default target [default] help: @just --list --unsorted # Create virtual environment setup: python3 -m venv {{venv}} {{pip}} install -e .[dev] # Run tests test: {{python}} -m pytest -v # Format code fmt: {{python}} -m black . {{python}} -m isort . # Type checking type-check: {{python}} -m mypy src/ # Lint lint: type-check {{python}} -m flake8 src/ # Run application run: {{python}} -m myapp # Clean cache clean: find . -type d -name __pycache__ -exec rm -r {} + rm -rf {{venv}} build/ dist/ *.egg-info ``` -------------------------------- ### Install Just on openSUSE Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on openSUSE via Zypper. ```bash zypper in just ``` -------------------------------- ### Get Just Executable Path Example Output Source: https://github.com/casey/just/blob/master/README.md Example output demonstrating the result of calling the just_executable() function. ```console $ just The executable is at: /bin/just ``` -------------------------------- ### Install Just on Solus Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Solus via eopkg. ```bash eopkg install just ``` -------------------------------- ### Install Just on Void Linux Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Void Linux via XBPS. ```bash xbps-install -S just ``` -------------------------------- ### Install Just with Nix Source: https://github.com/casey/just/blob/master/README.md Install 'just' using Nix package manager. ```bash nix-env -iA nixpkgs.just ``` -------------------------------- ### Install Just with uv Source: https://github.com/casey/just/blob/master/README.md Install the 'rust-just' tool using the uv package manager. ```bash uv tool install rust-just ``` -------------------------------- ### Install Just on Fedora Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Fedora via DNF. ```bash dnf install just ``` -------------------------------- ### Simple Web Project Setup with Just Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Configure a Justfile for a simple web project. This includes setting up a development server, running tests, building for production, and deployment. ```just # Web project justfile set shell := ["bash", "-uc"] host := "localhost" port := "8080" # Default recipe shows help [default] help: @echo "Available recipes:" @just --list --unsorted # Development server dev: python3 -m http.server --directory . {{port}} # Run tests test: npm test # Build for production build: npm run build ls -lh dist/ # Deploy [confirm("Deploy to production?")] deploy: test build scp -r dist/ user@server:/var/www/app/ # Clean build artifacts clean: rm -rf dist/ node_modules/ npm install ``` -------------------------------- ### Install Just with Cargo Binstall Source: https://github.com/casey/just/blob/master/README.md Install 'just' using the Cargo Binstall tool. ```bash cargo binstall just ``` -------------------------------- ### Install Just with npm Source: https://github.com/casey/just/blob/master/README.md Install the 'rust-just' package globally using npm. ```bash npm install -g rust-just ``` -------------------------------- ### Run Project Commands with Just Source: https://github.com/casey/just/blob/master/README.md Example of running a 'test-all' recipe defined in a justfile. This demonstrates the basic usage of 'just' to execute project-specific commands. ```console $ just test-all cc *.c -o main ./test --all Yay, all your tests passed! ``` -------------------------------- ### Install and Run cargo-watch Source: https://github.com/casey/just/blob/master/README.md Install `cargo-watch` to automatically re-run tests when code changes. Use `just watch test` to start this process. ```bash cargo install cargo-watch ``` ```bash just watch test ``` -------------------------------- ### Import Execution Example Source: https://github.com/casey/just/blob/master/README.md Demonstrates the execution flow when recipes are imported. Recipe 'b' from the imported file is executed before recipe 'a'. ```console $ just b B $ just a B A ``` -------------------------------- ### Install Just with pipx Source: https://github.com/casey/just/blob/master/README.md Install the 'rust-just' package using pipx. ```bash pipx install rust-just ``` -------------------------------- ### Install Just on GitHub Actions with setup-just Source: https://github.com/casey/just/blob/master/README.md Install a specific version of 'just' on GitHub Actions using the 'extractions/setup-just' action. The 'just-version' input is optional and defaults to the latest. ```yaml - uses: extractions/setup-just@v3 with: just-version: 1.5.0 # optional semver specification, otherwise latest ``` -------------------------------- ### Install Just on Gentoo Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Gentoo via Portage. ```bash emerge -av dev-build/just ``` -------------------------------- ### Install Just with Cargo Source: https://github.com/casey/just/blob/master/README.md Install 'just' using the Cargo package manager. ```bash cargo install just ``` -------------------------------- ### Install Just on NixOS Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on NixOS via nix-env. ```bash nix-env -iA nixos.just ``` -------------------------------- ### Shared Dependency Execution Source: https://github.com/casey/just/blob/master/README.md Illustrates a scenario where multiple recipes depend on a setup recipe. The setup recipe runs only once. ```just build: cc main.c test-foo: build ./a.out --test foo test-bar: build ./a.out --test bar ``` ```console $ just test-foo test-bar cc main.c ./a.out --test foo ./a.out --test bar ``` -------------------------------- ### Justfile Syntax and Recipe Examples Source: https://github.com/casey/just/blob/master/_autodocs/INDEX.md Demonstrates basic Justfile structure, including settings, variables, aliases, modules, and different types of recipes like default, parameterized, dependent, private, and documented recipes. ```just # Settings set shell := ["bash", "-uc"] set export # Variables version := "1.0.0" target := "release" # Module mod scripts # Aliases alias b := build # Default recipe [default] help: just --list # Recipe with parameters build profile="debug": echo "Building in {{profile}}" cargo build --{{profile}} # Recipe with dependencies test: build lint cargo test # Private recipe [private] _setup: mkdir -p build # Recipe with documentation # Build and run the application run: build ./target/{{target}}/app ``` -------------------------------- ### Install Just on OpenBSD Source: https://github.com/casey/just/blob/master/README.md Install 'just' on OpenBSD using the pkg_* package management tools. ```bash pkg_add just ``` -------------------------------- ### Installing vim-just Plugin with Vim's Built-in Package Support Source: https://github.com/casey/just/blob/master/README.md This command shows how to install the vim-just plugin using Vim's native package management system. It creates the necessary directory structure and clones the repository. ```bash mkdir -p ~/.vim/pack/vendor/start cd ~/.vim/pack/vendor/start git clone https://github.com/NoahTheDuke/vim-just.git ``` -------------------------------- ### Rust Project Setup with Just Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md A Justfile for a Rust project. It includes recipes for checking code, linting with clippy, formatting, testing, building debug and release binaries, benchmarking, and running the application. ```just set shell := ["bash", "-uc"] export RUST_LOG := "debug" target := "debug" default: @just --list --unsorted # Check code without building check: cargo check --all-targets # Run clippy linter lint: cargo clippy --all-targets --all-features -- -D warnings # Format code fmt: cargo fmt --all just lint # Run tests test: cargo test --all-features -- --nocapture # Build debug binary build: cargo build # Build release binary release: cargo build --release strip target/release/myapp # Benchmark bench: cargo bench --all-features # Run the application run: build ./target/{{target}}/myapp # Combined workflow all: fmt test release @echo "✓ All checks passed and release built" ``` -------------------------------- ### Cache Recipe with Input and Output Files Source: https://github.com/casey/just/blob/master/README.md This example uses `[cache(inputs = ..., outputs = ...)]` to manage caching based on both input file changes and the existence of output files. The `build` recipe re-runs if inputs change or if the `main` output file is missing. The `clean` recipe ensures `main` is removed, forcing `build` to re-run. ```just set unstable set lists [script] [cache(inputs = ["lib.c", "main.c"], outputs = "main")] build: cc lib.c main.c -o main clean: rm -f main ``` -------------------------------- ### Install Just on FreeBSD Source: https://github.com/casey/just/blob/master/README.md Install 'just' on FreeBSD using the pkg package manager. ```bash pkg install just ``` -------------------------------- ### Install Just on Windows with Scoop Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Windows via Scoop. ```powershell scoop install just ``` -------------------------------- ### Install Just with Conda Source: https://github.com/casey/just/blob/master/README.md Install 'just' from the conda-forge channel using Conda. ```bash conda install -c conda-forge just ``` -------------------------------- ### Define Build and Test Commands in Justfile Source: https://github.com/casey/just/blob/master/etc/crates-io-readme.md This example shows how to define basic build and test commands in a Justfile. The 'build' recipe compiles C code, and 'test-all' depends on 'build' before running tests. A parameterized 'test' recipe is also shown. ```make build: cc *.c -o main # test everything test-all: build ./test --all # run a specific test test TEST: build ./test --test {{TEST}} ``` -------------------------------- ### Cache Recipe with Input Files Source: https://github.com/casey/just/blob/master/README.md This example demonstrates using `[cache(inputs = ...)]` to specify input files for a cached recipe. The `build` recipe will re-run if `lib.c` or `main.c` change, as their hashes are included in the cache key. ```just set unstable set lists [script] [cache(inputs = ["lib.c", "main.c"])] build: cc lib.c main.c -o main ``` -------------------------------- ### Build System with Variables Source: https://github.com/casey/just/blob/master/_autodocs/INDEX.md Configures a build system using variables for target and binary names, and defines recipes for building, testing, releasing, and installing. It demonstrates setting the shell for command execution. ```just set shell := ["bash", "-uc"] target := "release" binary := "myapp" build: cargo build --{{target}} test: cargo test release: test cargo build --release strip target/release/{{binary}} install: release cp target/release/{{binary}} /usr/local/bin/ ``` -------------------------------- ### Install Just on Alpine Linux Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Alpine Linux via apk. ```bash apk add just ``` -------------------------------- ### Install Just with asdf Source: https://github.com/casey/just/blob/master/README.md Add the 'just' plugin to asdf and install a specific version. ```bash asdf plugin add just ``` ```bash asdf install just ``` -------------------------------- ### Install Just on Debian/Ubuntu Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Debian 13 and Ubuntu 24.04 derivatives via apt. ```bash apt install just ``` -------------------------------- ### Showing a Polyglot Recipe Source: https://github.com/casey/just/blob/master/README.md Example of using '--show' on a polyglot recipe, listing the languages it supports. ```console $ just --show polyglot polyglot: python js perl sh ruby ``` -------------------------------- ### Justfile Syntax Example Source: https://github.com/casey/just/blob/master/skills/just/SKILL.md Defines variables, compilation, execution, testing, serving, and publishing recipes. Uses shell commands and templating. ```just executable := 'main' # compile main.c compile: cc main.c -o {{ executable }} # run main run: compile ./{{ executable }} # run test test name: compile ./bin/test {{ name }} # start webserver serve port='8080': python -m http.server {{port}} # publish current tag publish: #!/usr/bin/env bash set -euxo pipefail tag=`git describe --tags --exact-match` ./bin/check-tag $tag git push origin $tag ``` -------------------------------- ### Install Just with Homebrew Source: https://github.com/casey/just/blob/master/README.md Install 'just' using the Homebrew package manager on macOS. ```bash brew install just ``` -------------------------------- ### Install Fish Completion Script Source: https://github.com/casey/just/blob/master/README.md Saves the completion script for Fish to the appropriate directory for lazy-loading. ```fish mkdir -p ~/.config/fish/completions just --completions fish > ~/.config/fish/completions/just.fish ``` -------------------------------- ### Install Just on Arch Linux Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Arch Linux via pacman. ```bash pacman -S just ``` -------------------------------- ### Install Just on Windows with Chocolatey Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Windows via Chocolatey. ```powershell choco install just ``` -------------------------------- ### Download and Install Latest Just Release Source: https://github.com/casey/just/blob/master/README.md Use this command to download and install the latest 'just' release to a specified directory. Ensure the directory is added to your PATH. ```bash curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to DEST ``` -------------------------------- ### Installing vim-just Plugin with Plug Source: https://github.com/casey/just/blob/master/README.md This code demonstrates how to install the vim-just plugin using the junegunn/vim-plug package manager for Vim. Ensure you are within the plug#begin() and plug#end() calls. ```vim call plug#begin() Plug 'NoahTheDuke/vim-just' call plug#end() ``` -------------------------------- ### Rust `run` Function Example Source: https://github.com/casey/just/blob/master/_autodocs/api-reference-run.md This example demonstrates how to use the `run` function in a typical Rust application. It passes the operating system's arguments to `run` and exits with the appropriate status code based on the result. ```Rust use std::env; use just::run; fn main() { match run(env::args_os()) { Ok(()) => std::process::exit(0), Err(code) => std::process::exit(code), } } ``` -------------------------------- ### Positional Parameter Example Source: https://github.com/casey/just/blob/master/README.md Demonstrates a recipe with a positional parameter 'bar'. The parameter is passed as a command-line argument. ```just @foo bar: echo bar={{bar}} ``` ```console $ just foo hello bar=hello ``` -------------------------------- ### Install Bash Completion Script (Lazy-loading) Source: https://github.com/casey/just/blob/master/README.md Installs the Bash completion script into the recommended directory for lazy-loading with the bash-completions package. ```bash mkdir -p ~/.local/share/bash-completion/completions just --completions bash > ~/.local/share/bash-completion/completions/just ``` -------------------------------- ### Shell-Expanded String Example Source: https://github.com/casey/just/blob/master/README.md Shows how to use shell-expanded strings prefixed with 'x' in Just for environment variable substitution and path expansion. ```justfile foobar := x'~/$FOO/${BAR}' ``` -------------------------------- ### Install Just on GitHub Actions with install-action Source: https://github.com/casey/just/blob/master/README.md Install 'just' on GitHub Actions using the 'taiki-e/install-action'. This action simplifies the process of adding 'just' to your CI environment. ```yaml - uses: taiki-e/install-action@just ``` -------------------------------- ### Install Just on Windows with Windows Package Manager Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on Windows via Windows Package Manager (winget). ```powershell winget install --id Casey.Just --exact ``` -------------------------------- ### Get Just Process ID Example Output Source: https://github.com/casey/just/blob/master/README.md Example output demonstrating the result of calling the just_pid() function. ```console $ just The process ID is: 420 ``` -------------------------------- ### Create a Starter Justfile Source: https://github.com/casey/just/blob/master/_autodocs/api-reference-subcommands.md Run `just --init` to create a new `justfile` in the current directory with a default 'Hello, world!' recipe. This command will not overwrite an existing justfile. ```bash just --init ``` ```just # https://just.systems default: echo 'Hello, world!' ``` -------------------------------- ### Pre-recipe Execution Hook Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md Define a setup recipe that runs before another recipe by listing it first in the recipe definition. This is useful for initialization tasks. ```just default: setup build @setup: echo "Setup started" build: cargo build ``` -------------------------------- ### Positional Arguments Example Source: https://github.com/casey/just/blob/master/README.md Demonstrates how positional arguments are passed to commands when 'positional-arguments' is true. $0 is the recipe name and subsequent arguments are passed positionally. ```just set positional-arguments @foo bar: echo $0 echo $1 ``` -------------------------------- ### Basic Import Example Source: https://github.com/casey/just/blob/master/README.md Illustrates how to include recipes from another Justfile using the 'import' statement. The imported recipes become available in the current Justfile. ```justfile import 'foo/bar.just' a: b @echo A ``` ```just b: @echo B ``` -------------------------------- ### Module Not Found Error Example Source: https://github.com/casey/just/blob/master/_autodocs/modules-and-imports.md Shows a recipe that depends on a non-existent module, leading to a 'module not found' error. ```just depend: missing::build # Error: module 'missing' not found ``` -------------------------------- ### Get Number of CPUs Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Retrieves the number of logical CPUs as a string. Example shows assigning the result to a variable. ```just threads := num_cpus() # "8" ``` -------------------------------- ### Get Operating System Name Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Retrieves the operating system name. Example shows assigning the result to a variable. ```just platform := os() # "linux" ``` -------------------------------- ### Get System Architecture Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Retrieves the instruction set architecture of the system. Example shows assigning the result to a variable. ```just target := arch() # "x86_64" ``` -------------------------------- ### Multi-Platform Build and Install with OS/Arch Detection Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Dynamically sets the Cargo build target based on the detected operating system and architecture. Includes platform-specific installation logic. ```just set shell := ["bash", "-uc"] os_type := os() arch_type := arch() target := if os_type == "windows" { "x86_64-pc-windows-gnu" } else if os_type == "macos" { if arch_type == "aarch64" { "aarch64-apple-darwin" } else { "x86_64-apple-darwin" } } else { "x86_64-unknown-linux-gnu" } build: cargo build --target={{target}} install: build @if [ "{{os_type}}" = "windows" ]; then \ copy target\{{target}}\release\myapp.exe C:\Program Files\; \ else \ sudo cp target/{{target}}/release/myapp /usr/local/bin/; \ fi ``` -------------------------------- ### Get Required Environment Variable Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Retrieves a required environment variable, aborting if it is not set. Example shows retrieving 'HOME' and 'USER'. ```just home := env('HOME') user := env('USER') ``` -------------------------------- ### Basic Dependency Execution Source: https://github.com/casey/just/blob/master/README.md Demonstrates how dependencies run before the recipes that depend on them. Recipes with the same arguments run only once. ```just a: b @echo A b: @echo B ``` ```console $ just a B A ``` ```just a: @echo A b: a @echo B c: a @echo C ``` ```console $ just a a a a a A $ just b c A B C ``` -------------------------------- ### Submodule Recipe Dependency Source: https://github.com/casey/just/blob/master/README.md Example of a recipe depending on a recipe within a submodule. ```just mod foo baz: foo::bar ``` -------------------------------- ### Get Environment Variable with Default Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Retrieves an environment variable, providing a default value if it is not set. Examples show retrieving 'PORT' and 'HOST'. ```just port := env('PORT', '8080') host := env('HOST', 'localhost') ``` -------------------------------- ### Optional Import Example Source: https://github.com/casey/just/blob/master/README.md Demonstrates how to make an import optional using 'import?'. If the specified Justfile does not exist, 'just' will not produce an error. ```justfile import? 'foo/bar.just' ``` -------------------------------- ### Running a Recipe with Dependencies Source: https://github.com/casey/just/blob/master/README.md Demonstrates the execution order when running a recipe that has dependencies. ```console $ just test cc main.c foo.c bar.c -o main ./test testing… all tests passed! ``` -------------------------------- ### Running the Default Recipe Source: https://github.com/casey/just/blob/master/README.md Demonstrates invoking 'just' without arguments to run the first recipe defined in the justfile. ```console $ just echo 'This is a recipe!' This is a recipe! ``` -------------------------------- ### Showing Recipe Signature with `--usage` Source: https://github.com/casey/just/blob/master/_autodocs/modules-and-imports.md Demonstrates how to use `just --usage` with a full module path to display the expected signature and arguments for a recipe. ```bash # Show recipe signature just --usage frontend::build::build ``` -------------------------------- ### Loading Environment Variables from .env Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md Use `set dotenv-load` to load environment variables from a `.env` file. The example shows accessing `DATABASE_URL`. ```just set dotenv-load recipe: echo $DATABASE_URL # From .env ``` -------------------------------- ### Displaying recipe usage with argument help Source: https://github.com/casey/just/blob/master/README.md Illustrates the output of '--usage' when arguments have associated help strings. ```console $ just --usage foo Usage: just foo bar Arguments: bar hello ``` -------------------------------- ### Recipe with Argument Validation Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md Argument validation can be configured using `set lists` and decorators like `arg()`. This example shows a `verbose` flag for the `build` recipe. ```just set unstable set lists [arg("verbose", long, flag)] build verbose: # ... ``` -------------------------------- ### Subsequent Dependencies Source: https://github.com/casey/just/blob/master/README.md Demonstrates subsequent dependencies introduced with '&&'. These run immediately after the recipe, not before. ```just a: echo 'A!' b: a && c d echo 'B!' c: echo 'C!' d: echo 'D!' ``` ```console $ just b echo 'A!' A! echo 'B!' B! echo 'C!' C! echo 'D!' D! ``` -------------------------------- ### Complex Expression Example Source: https://github.com/casey/just/blob/master/README.md Demonstrates various expression usages including command substitution, string concatenation, path joining, and function calls within recipe assignments. ```just tmpdir := `mktemp -d` version := "0.2.7" tardir := tmpdir / "awesomesauce-" + version tarball := tardir + ".tar.gz" config := quote(config_dir() / ".project-config") publish: rm -f {{tarball}} mkdir {{tardir}} cp README.md *.c {{ config }} {{tardir}} tar zcvf {{tarball}} {{tardir}} scp {{tarball}} me@server.com:release/ rm -rf {{tarball}} {{tardir}} ``` -------------------------------- ### Displaying recipe usage information Source: https://github.com/casey/just/blob/master/README.md Demonstrates how to use the '--usage' subcommand to display help information for a recipe. ```console $ just --usage foo Usage: just foo [OPTIONS] bar Arguments: bar ``` -------------------------------- ### Install Just on macOS with MacPorts Source: https://github.com/casey/just/blob/master/README.md Use this command to install 'just' on macOS via MacPorts. ```bash port install just ``` -------------------------------- ### Dynamic Recipe Compilation for Multiple Platforms Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Demonstrates dynamic recipe generation using `set lists` and parameter expansion. The `compile` recipe can build for multiple specified platforms. ```just set unstable set lists # Compile multiple targets [parallel] compile target *platforms: *(build target *platforms) [private] @build target platform: echo "Building {{target}} for {{platform}}" cargo build --target={{platform}} call-compile: just compile myapp x86_64-linux aarch64-linux ``` -------------------------------- ### Showing Specific Recipes with Module Paths Source: https://github.com/casey/just/blob/master/_autodocs/modules-and-imports.md Shows how to use `just --show` with a full module path to display the details of a specific recipe. ```bash # Show specific recipe just --show frontend::build::build ``` -------------------------------- ### Main Justfile for Multi-Module Project Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Defines modules, help, test, build, and deploy recipes for a multi-module project. Uses `set default-list` to make recipes available without module prefix. The `deploy` recipe depends on `test` and `build` and includes a confirmation prompt. ```just set default-list mod backend mod frontend [doc("Show help")] help: just --list [doc("Run all tests")] test: backend::test frontend::test @echo "✓ All tests passed" [doc("Build everything")] build: backend::build frontend::build @echo "✓ Build complete" [doc("Deploy all")] [confirm("Deploy all components?")] deploy: test build ./scripts/deploy.sh ``` -------------------------------- ### Safely Find Executable in PATH Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Searches the system's PATH for an executable, returning an empty list if not found. Requires 'set lists' and 'set unstable'. Example shows finding 'bash' optionally. ```just set unstable set lists maybe_bash := which("bash") ``` -------------------------------- ### Recipe with Dependencies Source: https://github.com/casey/just/blob/master/README.md Defines a 'test' recipe that depends on the 'build' recipe. 'build' will execute before 'test'. ```just build: cc main.c foo.c bar.c -o main test: build ./test sloc: @echo "`wc -l *.c` lines of code" ``` -------------------------------- ### Recipe with a simple parameter Source: https://github.com/casey/just/blob/master/README.md Defines a 'build' recipe that accepts a 'target' parameter and uses it in a command. ```just build target: @echo 'Building {{target}}…' cd {{target}} && make ``` -------------------------------- ### Circular Dependency Error Example Source: https://github.com/casey/just/blob/master/_autodocs/modules-and-imports.md Provides an example of a circular dependency between two modules (`foo.just` and `bar.just`) which will result in an error. ```just # In foo.just import "bar.just" # In bar.just import "foo.just" # Error: circular dependency ``` -------------------------------- ### Docker Build, Run, and Push with Just Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Manage Docker image lifecycle using Just recipes. This includes building the image, running it, and pushing it to a registry. ```just image := "myapp:latest" # Build Docker image docker-build: docker build -t {{image}} . # Run in Docker docker-run: docker run --rm -it {{image}} # Push to registry docker-push: docker push {{image}} ``` -------------------------------- ### Get Just Executable Path Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `just_executable` to get the absolute path to the `just` executable itself. This can be used for self-referential commands or version checks. ```just version: {{ just_executable() }} --version ``` -------------------------------- ### Get Justfile Path Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `justfile` to get the absolute path to the current Justfile. This can be used for logging or referencing the Justfile itself. ```just recipe: echo "Justfile at: {{ justfile() }}" ``` -------------------------------- ### Listing Recipes with Module Paths Source: https://github.com/casey/just/blob/master/_autodocs/modules-and-imports.md Demonstrates how to use `just --list` with module paths to view recipes within specific modules or submodules. ```bash # List all recipes just --list # List recipes in module just --list frontend just --list frontend::build # List all recipes recursively just --list-submodules ``` -------------------------------- ### Get Invocation Directory Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `invocation_directory` to get the absolute path of the directory from which the `just` command was initially run, before any `cd` operations. ```just initial := invocation_directory() ``` -------------------------------- ### Passing variables as arguments to dependencies Source: https://github.com/casey/just/blob/master/README.md Illustrates how to pass a variable's value as an argument to a dependency recipe. ```just target := "main" _build version: @echo 'Building {{version}}…' cd {{version}} && make build: (_build target) ``` -------------------------------- ### Dependency Caching with Just Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Implement a caching mechanism to avoid redundant dependency installations. This snippet checks if the dependency file has changed before running `npm install`. ```just set shell := ["bash", "-uc"] deps-file := ".deps.lock" # Only install if dependencies changed install: @if [ ! -f {{deps-file}} ] || ! diff -q package.json {{deps-file}} >/dev/null 2>&1; then \ npm install; \ cp package.json {{deps-file}}; \ else \ echo "Dependencies already up to date"; \ fi ``` -------------------------------- ### CI/CD Integration Recipes Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Set up recipes for CI/CD integration, including linting, testing, building, and conditional publishing. ```just set shell := ["bash", "-uc"] # Simulate CI environment ci: lint test build @echo "CI checks passed" # Check code quality lint: black --check . isort --check . flake8 . # Run tests test: pytest # Build artifact build: python -m build # Only run on CI [env("CI", "true")] publish: twine upload dist/* ``` -------------------------------- ### Get Module File Path Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `module_file` to get the absolute path of the current module file. This is useful for understanding the location of imported code. ```just module_file() ``` -------------------------------- ### Get Source File Path Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `source_file` to get the absolute path of the current source file, which is particularly relevant when dealing with imports or modules. ```just source_file() ``` -------------------------------- ### Running a Specific Recipe Source: https://github.com/casey/just/blob/master/README.md Shows how to run a specific recipe by providing its name as an argument to the 'just' command. ```console $ just another-recipe This is another recipe. ``` -------------------------------- ### Get Module Directory Path Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `module_directory` to get the absolute path of the directory containing the current module file. This aids in managing module-specific resources. ```just module_directory() ``` -------------------------------- ### Execute Shebang Recipe Source: https://github.com/casey/just/blob/master/README.md Demonstrates the output of a standard shebang recipe. ```console $ just foo Foo! ``` -------------------------------- ### Get File Stem (Filename Without Extension) Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `file_stem` to get the filename part of a path, excluding its extension. This function may throw an error if the path is invalid. ```just stem := file_stem("/path/to/file.txt") # "file" ``` -------------------------------- ### Recipe with a Parameter Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md Recipes can accept parameters, which are then used within the recipe's commands. Call this recipe with `just build main`. ```just build target: gcc {{target}}.c -o {{target}} ``` -------------------------------- ### Running Indented Recipes Source: https://github.com/casey/just/blob/master/README.md Shows how to execute recipes defined with different indentation styles (spaces vs. tabs) from the command line. ```pwsh PS > just list-space ~ Desktop Documents Downloads PS > just list-tab ~ Desktop Documents Downloads ``` -------------------------------- ### Execute Quiet Recipe Source: https://github.com/casey/just/blob/master/README.md Shows the output of a quiet recipe, where only lines starting with '@' are echoed. ```console $ just quiet hello goodbye # all done! ``` -------------------------------- ### Recipe with Comments Source: https://github.com/casey/just/blob/master/_autodocs/justfile-format.md Illustrates how to include comments within a recipe definition. Lines starting with '#' are ignored. ```just # This is a comment recipe-name: echo "hello" # Comments also work here ``` -------------------------------- ### Define Optional Module Source: https://github.com/casey/just/blob/master/README.md Shows how to declare an optional module 'foo' using 'mod? foo'. Missing source files for optional modules do not cause errors. ```just mod? foo ``` -------------------------------- ### Passing arguments on the command line Source: https://github.com/casey/just/blob/master/README.md Demonstrates how to pass arguments to a recipe when invoking Just from the console. ```console $ just build my-awesome-project Building my-awesome-project… cd my-awesome-project && make ``` -------------------------------- ### Get Required Environment Variable Source: https://github.com/casey/just/blob/master/README.md Retrieves the value of an environment variable. The recipe will abort if the variable is not set. ```just home_dir := env('HOME') ``` -------------------------------- ### Source Bash Completion Script in .bashrc Source: https://github.com/casey/just/blob/master/README.md Sources the completion script directly in your .bashrc if bash-completions is not installed. ```bash source <(just --completions bash) ``` -------------------------------- ### Default Variable Setting and Recipe Execution Source: https://github.com/casey/just/blob/master/README.md Shows default variable assignment and how recipes use these variables. Demonstrates command-line overrides. ```just os := "linux" test: build ./test --test {{os}} build: ./build {{os}} ``` ```console $ just ./build linux ./test --test linux ``` ```console $ just os=plan9 ./build plan9 ./test --test plan9 ``` ```console $ just --set os bsd ./build bsd ./test --test bsd ``` -------------------------------- ### Check if OS is Windows Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Determines if the operating system belongs to the Windows family. Example shows a boolean comparison. ```just is_windows := os_family() == "windows" ``` -------------------------------- ### Define Quiet Recipe Source: https://github.com/casey/just/blob/master/README.md Prefixing a recipe name with '@' makes it a quiet recipe, meaning only lines starting with '@' will be echoed. ```just @quiet: echo hello echo goodbye @# all done! ``` -------------------------------- ### Module with Doc Comment Source: https://github.com/casey/just/blob/master/README.md Example of adding a doc comment to a module declaration, which will be displayed in the '--list' output. ```justfile # foo is a great module! mod foo ``` -------------------------------- ### Auto-generate Documentation Source: https://github.com/casey/just/blob/master/_autodocs/examples-and-patterns.md Recipes for generating API documentation, books, and deploying documentation to cloud storage. ```just set shell := ["bash", "-uc"] # Generate API documentation docs-api: cargo doc --no-deps --open # Generate book docs-book: mdbook serve book # Generate all docs docs: docs-api docs-book # Deploy docs docs-deploy: docs aws s3 sync target/doc s3://docs.example.com ``` -------------------------------- ### Default Working Directory Behavior Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md Recipes run in the justfile directory by default. This example shows the default behavior. ```bash cd /project/subdir just recipe # Recipe runs with cwd = /project (justfile directory) ``` -------------------------------- ### Get Just Process ID Source: https://github.com/casey/just/blob/master/README.md Retrieves the Process ID (PID) of the 'just' executable. Useful for monitoring or interacting with the running Just process. ```just pid: @echo The process ID is: {{ just_pid() }} ``` -------------------------------- ### Get Invocation Directory Source: https://github.com/casey/just/blob/master/README.md Retrieves the absolute path to the directory from which 'just' was invoked. This path is converted to a Cygwin-compatible format on Windows. ```just rustfmt: find {{invocation_directory()}} -name \*.rs -exec rustfmt {} \; ``` -------------------------------- ### List All Available Recipes Source: https://github.com/casey/just/blob/master/README.md Use `just --list` to display all available recipes in alphabetical order. This command is useful for understanding the available tasks in a project. ```console $ just --list Available recipes: build test deploy lint ``` -------------------------------- ### Running Multiple Recipes Without Dependencies Source: https://github.com/casey/just/blob/master/README.md Shows how to run multiple recipes that do not depend on each other in the order they are specified. ```console $ just build sloc cc main.c foo.c bar.c -o main 1337 lines of code ``` -------------------------------- ### Positional Arguments with [positional-arguments] Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md The `[positional-arguments]` attribute enables passing arguments to shell commands as positional arguments, starting from `$0`. ```just [positional-arguments] @args a b c: echo $0 # args echo $1 # a echo $2 # b echo $3 # c ``` -------------------------------- ### Passing command arguments to a dependency Source: https://github.com/casey/just/blob/master/README.md Demonstrates how a command's arguments can be passed to a dependency by including the dependency in parentheses with the arguments. ```just build target: @echo "Building {{target}}…" push target: (build target) @echo 'Pushing {{target}}…' ``` -------------------------------- ### Print Submodule Variables Source: https://github.com/casey/just/blob/master/README.md Access and print variables from submodules using the `::` path. For example, `just --evaluate bob::bar`. ```console $ just --evaluate bob::bar x := "world" y := "hello" ``` -------------------------------- ### Listing Available Recipes Source: https://github.com/casey/just/blob/master/README.md Command to list all available recipes in the current Justfile. ```console $ just --list Available recipes: js perl polyglot python ruby ``` -------------------------------- ### Get Current Recipe Name Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Retrieves the name of the currently executing recipe. This is useful for logging or conditional logic within a recipe. ```just foo: echo "In recipe: {{ recipe_name() }}" # "foo" ``` -------------------------------- ### Module Dependencies Source: https://github.com/casey/just/blob/master/_autodocs/justfile-format.md Demonstrates how to depend on recipes defined in other modules (submodules). ```just mod foo bar: foo::baz ... ``` -------------------------------- ### Get Parent Directory Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `parent_directory` to obtain the parent directory of a given file path. An error is thrown if the path has no parent. ```just dir := parent_directory("/path/to/file.txt") # "/path/to" ``` -------------------------------- ### Default Recipe with Multiple Dependencies Source: https://github.com/casey/just/blob/master/README.md Sets the default behavior to run multiple recipes (lint, build, test) in sequence. ```just default: lint build test build: echo Building… test: echo Testing… lint: echo Linting… ``` -------------------------------- ### Run CI Checks Source: https://github.com/casey/just/blob/master/README.md Execute `just ci` to ensure all tests, lints, and checks pass. This command requires `mdBook` and `mdbook-linkcheck` to be installed. ```bash just ci ``` -------------------------------- ### List Available Recipes with Module Docs Source: https://github.com/casey/just/blob/master/README.md Shows the output of 'just --list' when modules have doc comments, displaying the module's documentation alongside its recipes. ```console $ just --list Available recipes: foo ... # foo is a great module! ``` -------------------------------- ### Define Optional Modules with Specific Paths Source: https://github.com/casey/just/blob/master/README.md Demonstrates defining multiple optional modules with the same name but different source file paths. This is allowed as long as at most one source file exists. ```just mod? foo 'bar.just' mod? foo 'baz.just' ``` -------------------------------- ### Accessing Environment Variables Source: https://github.com/casey/just/blob/master/_autodocs/recipe-execution.md Environment variables can be accessed within recipes using the `$NAME` syntax. This example shows accessing `HOME` and `USER`. ```just recipe: echo $HOME echo $USER ``` -------------------------------- ### Variadic Positional Arguments Handling Source: https://github.com/casey/just/blob/master/README.md Illustrates how to handle variadic positional arguments using `*args` in Just. It shows how arguments are passed to different recipes based on their position. ```just set unstable set lists set positional-arguments foo *args: (bar args 'bob') (baz args) @bar first second: echo first=$1 echo second=$2 @baz *args: echo '$1='$1 echo '$2='$2 ``` -------------------------------- ### Get Justfile Directory Source: https://github.com/casey/just/blob/master/README.md Retrieves the path of the parent directory of the current Justfile. Useful for running commands relative to the Justfile's location. ```just script: {{justfile_directory()}}/scripts/some_script ``` -------------------------------- ### Windows Path Handling with cygpath Source: https://github.com/casey/just/blob/master/README.md Demonstrates converting between Unix-style and Windows-style paths using cygpath.exe. Ensure paths are quoted when not using PowerShell or cmd.exe. ```just ls: echo '{{absolute_path(".")}}' ``` ```just foo_unix := '/hello/world' foo_windows := shell('cygpath --windows $1', foo_unix) bar_windows := 'C:\hello\world' bar_unix := shell('cygpath --unix $1', bar_windows) ``` -------------------------------- ### Get Just Process ID Source: https://github.com/casey/just/blob/master/_autodocs/expressions-and-functions.md Use `just_pid` to obtain the process ID (PID) of the running `just` executable as a string. This can be useful for process management or debugging. ```just recipe: echo "PID: {{ just_pid() }}" ```