cli-just

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Just Command Runner

Just Command Runner

Overview

概述

Expert guidance for Just, a command runner with syntax inspired by make. Use this skill for creating justfiles, writing recipes, configuring settings, and implementing task automation workflows.
Key capabilities:
  • Create and organize justfiles with proper structure
  • Write recipes with attributes, dependencies, and parameters
  • Configure settings for shell, modules, and imports
  • Use built-in constants for terminal formatting
  • Implement check/write patterns for code quality tools
为Just(一款语法灵感源自make的命令运行器)提供专业指导。本技能可用于创建justfiles、编写recipes、配置设置,以及实现任务自动化工作流。
核心功能:
  • 创建并组织结构规范的justfiles
  • 编写包含属性、依赖和参数的recipes
  • 配置Shell、模块与导入相关设置
  • 使用内置常量进行终端格式化
  • 为代码质量工具实现检查/修复(check/write)模式

Quick Reference

快速参考

Essential Settings

核心设置

just
set allow-duplicate-recipes       # Allow recipes to override imported ones
set allow-duplicate-variables     # Allow variables to override imported ones
set shell := ["bash", "-euo", "pipefail", "-c"]  # Strict bash with error handling
set unstable                      # Enable unstable features (modules, script attribute)
set dotenv-load                   # Auto-load .env file
set positional-arguments          # Pass recipe args as $1, $2, etc.
just
set allow-duplicate-recipes       # 允许recipes覆盖导入的同名recipes
set allow-duplicate-variables     # 允许变量覆盖导入的同名变量
set shell := ["bash", "-euo", "pipefail", "-c"]  # 带错误处理的严格bash配置
set unstable                      # 启用实验性功能(模块、script属性)
set dotenv-load                   # 自动加载.env文件
set positional-arguments          # 将recipe参数作为$1、$2等传递

Common Attributes

常用属性

AttributePurpose
[arg("p", long, ...)]
Configure parameter as
--flag
option (v1.46)
[arg("p", pattern="…")]
Constrain parameter to match regex pattern
[group("name")]
Group recipes in
just --list
output
[no-cd]
Don't change to justfile directory
[private]
Hide from
just --list
(same as
_
prefix)
[script]
Execute recipe as single script block
[script("interpreter")]
Use specific interpreter (bash, python, etc.)
[confirm("prompt")]
Require user confirmation before running
[doc("text")]
Override recipe documentation
[positional-arguments]
Enable positional args for this recipe only
Attribute(属性)用途
[arg("p", long, ...)]
将参数配置为
--flag
选项(v1.46版本)
[arg("p", pattern="…")]
限制参数匹配指定正则表达式
[group("name")]
just --list
输出中对recipes进行分组
[no-cd]
不切换到justfile所在目录
[private]
just --list
中隐藏(与
_
前缀效果相同)
[script]
将recipe作为单个脚本块执行
[script("interpreter")]
使用指定解释器(bash、python等)
[confirm("prompt")]
运行前要求用户确认
[doc("text")]
覆盖recipe的文档说明
[positional-arguments]
仅为此recipe启用位置参数

Recipe Argument Flags (v1.46.0+)

Recipe参数选项(v1.46.0+)

The
[arg()]
attribute configures parameters as CLI-style options:
just
undefined
[arg()]
属性可将参数配置为CLI风格的选项:
just
undefined

Long option (--target)

长选项(--target)

[arg("target", long)] build target: cargo build --target {{ target }}
[arg("target", long)] build target: cargo build --target {{ target }}

Short option (-v)

短选项(-v)

[arg("verbose", short="v")] run verbose="false": echo "Verbose: {{ verbose }}"
[arg("verbose", short="v")] run verbose="false": echo "Verbose: {{ verbose }}"

Combined long + short

组合长/短选项

[arg("output", long, short="o")] compile output: gcc main.c -o {{ output }}
[arg("output", long, short="o")] compile output: gcc main.c -o {{ output }}

Flag without value (presence sets to "true")

无值标志(存在即设为"true")

[arg("release", long, value="true")] build release="false": cargo build {{ if release == "true" { "--release" } else { "" } }}
[arg("release", long, value="true")] build release="false": cargo build {{ if release == "true" { "--release" } else { "" } }}

Help string (shown in
just --usage
)

帮助文本(在
just --usage
中显示)

[arg("target", long, help="Build target architecture")] build target: cargo build --target {{ target }}

**Usage examples:**

```bash
just build --target x86_64
just build --target=x86_64
just compile -o main
just build --release
just --usage build    # Show recipe argument help
Multiple attributes can be combined:
just
[no-cd, private]
[group("checks")]
recipe:
    echo "hello"
[arg("target", long, help="Build target architecture")] build target: cargo build --target {{ target }}

**使用示例:**

```bash
just build --target x86_64
just build --target=x86_64
just compile -o main
just build --release
just --usage build    # 查看recipe参数帮助
可组合多个属性:
just
[no-cd, private]
[group("checks")]
recipe:
    echo "hello"

Built-in Constants

内置常量

Terminal formatting constants are globally available (no definition needed):
ConstantDescription
CYAN
,
GREEN
,
RED
,
YELLOW
,
BLUE
,
MAGENTA
Text colors
BOLD
,
ITALIC
,
UNDERLINE
,
STRIKETHROUGH
Text styles
NORMAL
Reset formatting
BG_*
Background colors (BG_RED, BG_GREEN, etc.)
HEX
,
HEXLOWER
Hexadecimal digits
Usage:
just
@status:
    echo -e '{{ GREEN }}Success!{{ NORMAL }}'
    echo -e '{{ BOLD + CYAN }}Building...{{ NORMAL }}'
终端格式化常量全局可用(无需定义):
常量描述
CYAN
,
GREEN
,
RED
,
YELLOW
,
BLUE
,
MAGENTA
文本颜色
BOLD
,
ITALIC
,
UNDERLINE
,
STRIKETHROUGH
文本样式
NORMAL
重置格式
BG_*
背景色(BG_RED、BG_GREEN等)
HEX
,
HEXLOWER
十六进制数字
使用示例:
just
@status:
    echo -e '{{ GREEN }}Success!{{ NORMAL }}'
    echo -e '{{ BOLD + CYAN }}Building...{{ NORMAL }}'

Key Functions

核心函数

just
undefined
just
undefined

Require executable exists (fails recipe if not found)

检查可执行文件是否存在(不存在则任务失败)

jq := require("jq")
jq := require("jq")

Get environment variable with default

获取环境变量,带默认值

log_level := env("LOG_LEVEL", "info")
log_level := env("LOG_LEVEL", "info")

Get justfile directory path

获取justfile所在目录路径

root := justfile_dir()
undefined
root := justfile_dir()
undefined

Recipe Patterns

Recipe模式

Status Reporter Pattern

状态报告模式

Display formatted status during multi-step workflows:
just
@_run-with-status recipe *args:
    echo ""
    echo -e '{{ CYAN }}→ Running {{ recipe }}...{{ NORMAL }}'
    just {{ recipe }} {{ args }}
    echo -e '{{ GREEN }}✓ {{ recipe }} completed{{ NORMAL }}'
alias rws := _run-with-status
在多步骤工作流中显示格式化状态:
just
@_run-with-status recipe *args:
    echo ""
    echo -e '{{ CYAN }}→ Running {{ recipe }}...{{ NORMAL }}'
    just {{ recipe }} {{ args }}
    echo -e '{{ GREEN }}✓ {{ recipe }} completed{{ NORMAL }}'
alias rws := _run-with-status

Check/Write Pattern

检查/修复模式

Pair check (verify) and write (fix) recipes for code quality tools:
just
[group("checks")]
@biome-check +globs=".":
    na biome check {{ globs }}
alias bc := biome-check

[group("checks")]
@biome-write +globs=".":
    na biome check --write {{ globs }}
alias bw := biome-write
为代码质量工具配对检查(verify)和修复(fix)recipes:
just
[group("checks")]
@biome-check +globs=".":
    na biome check {{ globs }}
alias bc := biome-check

[group("checks")]
@biome-write +globs=".":
    na biome check --write {{ globs }}
alias bw := biome-write

Full Check/Write Pattern

完整检查/修复模式

Aggregate all checks with status reporting:
just
[group("checks")]
@full-check:
    just _run-with-status biome-check
    just _run-with-status prettier-check
    just _run-with-status tsc-check
    echo ""
    echo -e '{{ GREEN }}All code checks passed!{{ NORMAL }}'
alias fc := full-check

[group("checks")]
@full-write:
    just _run-with-status biome-write
    just _run-with-status prettier-write
    echo ""
    echo -e '{{ GREEN }}All code fixes applied!{{ NORMAL }}'
alias fw := full-write
汇总所有检查并附带状态报告:
just
[group("checks")]
@full-check:
    just _run-with-status biome-check
    just _run-with-status prettier-check
    just _run-with-status tsc-check
    echo ""
    echo -e '{{ GREEN }}All code checks passed!{{ NORMAL }}'
alias fc := full-check

[group("checks")]
@full-write:
    just _run-with-status biome-write
    just _run-with-status prettier-write
    echo ""
    echo -e '{{ GREEN }}All code fixes applied!{{ NORMAL }}'
alias fw := full-write

Standard Alias Conventions

标准别名约定

RecipeAliasRecipeAlias
full-checkfcfull-writefw
biome-checkbcbiome-writebw
prettier-checkpcprettier-writepw
mdformat-checkmcmdformat-writemw
tsc-checktcruff-checkrc
testtbuildb
Recipe别名Recipe别名
full-checkfcfull-writefw
biome-checkbcbiome-writebw
prettier-checkpcprettier-writepw
mdformat-checkmcmdformat-writemw
tsc-checktcruff-checkrc
testtbuildb

Inline Scripts

内联脚本

Just supports inline scripts in any language via two methods:
Just支持通过两种方式在任意语言中编写内联脚本:

Script Attribute (Recommended)

Script属性(推荐)

Use
[script("interpreter")]
for cross-platform compatibility:
just
[script("node")]
fetch-data:
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    console.log(data);

[script("python3")]
analyze:
    import json
    with open('package.json') as f:
        pkg = json.load(f)
    print(f"Package: {pkg['name']}@{pkg['version']}")

[script("bash")]
deploy:
    set -e
    npm run build
    aws s3 sync dist/ s3://bucket/
使用
[script("interpreter")]
实现跨平台兼容:
just
[script("node")]
fetch-data:
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    console.log(data);

[script("python3")]
analyze:
    import json
    with open('package.json') as f:
        pkg = json.load(f)
    print(f"Package: {pkg['name']}@{pkg['version']}")

[script("bash")]
deploy:
    set -e
    npm run build
    aws s3 sync dist/ s3://bucket/

Shebang Method

Shebang方式

Use
#!/usr/bin/env interpreter
at the recipe start:
just
node-script:
    #!/usr/bin/env node
    console.log(`Node ${process.version}`);
    console.log(JSON.stringify(process.env, null, 2));

python-script:
    #!/usr/bin/env python3
    import sys
    print(f"Python {sys.version}")

bash-script:
    #!/usr/bin/env bash
    set -euo pipefail
    echo "Running on $(uname -s)"
When to use which:
  • [script()]
    - Better cross-platform support, cleaner syntax
  • Shebang - Traditional Unix approach, works without
    set unstable
在recipe开头使用
#!/usr/bin/env interpreter
just
node-script:
    #!/usr/bin/env node
    console.log(`Node ${process.version}`);
    console.log(JSON.stringify(process.env, null, 2));

python-script:
    #!/usr/bin/env python3
    import sys
    print(f"Python {sys.version}")

bash-script:
    #!/usr/bin/env bash
    set -euo pipefail
    echo "Running on $(uname -s)"
使用场景对比:
  • [script()]
    - 跨平台支持更好,语法更简洁
  • Shebang - 传统Unix方式,无需设置
    set unstable
    即可使用

Modules & Imports

模块与导入

Import Pattern

导入模式

Include recipes from another file:
just
import "./just/settings.just"
import "./just/base.just"
import? "./local.just"    # Optional (no error if missing)
从其他文件导入recipes:
just
import "./just/settings.just"
import "./just/base.just"
import? "./local.just"    # 可选导入(文件不存在时不报错)

Module Pattern

模块模式

Load submodule (requires
set unstable
):
just
mod foo                   # Loads foo.just or foo/justfile
mod bar "path/to/bar"     # Custom path
mod? optional             # Optional module
加载子模块(需设置
set unstable
):
just
mod foo                   # 加载foo.just或foo/justfile
mod bar "path/to/bar"     # 自定义路径
mod? optional             # 可选模块

Call module recipes

调用模块中的recipes

just foo::build
undefined
just foo::build
undefined

Devkit Import Pattern

Devkit导入模式

For projects using
@sablier/devkit
:
just
import "./node_modules/@sablier/devkit/just/base.just"
import "./node_modules/@sablier/devkit/just/npm.just"
对于使用
@sablier/devkit
的项目:
just
import "./node_modules/@sablier/devkit/just/base.just"
import "./node_modules/@sablier/devkit/just/npm.just"

Section Organization

章节组织

Standard section header format:
just
undefined
标准章节标题格式:
just
undefined

----------------------------------------------------------------------------

----------------------------------------------------------------------------

DEPENDENCIES

DEPENDENCIES

----------------------------------------------------------------------------

----------------------------------------------------------------------------


Common sections (in order):

1. **DEPENDENCIES** - Required tools with URLs
2. **CONSTANTS** - Glob patterns, environment vars
3. **RECIPES / COMMANDS** - Main entry points
4. **CHECKS** - Code quality recipes
5. **UTILITIES / INTERNAL HELPERS** - Private helpers

常见章节(按顺序):

1. **DEPENDENCIES** - 所需工具及对应URL
2. **CONSTANTS** - 全局模式、环境变量
3. **RECIPES / COMMANDS** - 主入口
4. **CHECKS** - 代码质量相关recipes
5. **UTILITIES / INTERNAL HELPERS** - 私有辅助工具

Default Recipe

默认Recipe

Always define a default recipe:
just
undefined
务必定义默认Recipe:
just
undefined

Show available commands

显示可用命令

default: @just --list
undefined
default: @just --list
undefined

Dependencies Declaration

依赖声明

Document required tools at the top:
just
undefined
在顶部文档化所需工具:
just
undefined

----------------------------------------------------------------------------

----------------------------------------------------------------------------

DEPENDENCIES

DEPENDENCIES

----------------------------------------------------------------------------

----------------------------------------------------------------------------

bun := require("bun")
bun := require("bun")
na := require("na") ni := require("ni") nlx := require("nlx")
na := require("na") ni := require("ni") nlx := require("nlx")

Usage: invoke directly in recipes (not with interpolation)

使用方式:在recipes中直接调用(无需插值)

build: bun next build

**Note:** `require()` validates the tool exists at recipe evaluation time. Use the variable name directly (e.g., `bun`), not with interpolation (`{{ bun }}`).
build: bun next build

**注意:** `require()`会在recipe评估时验证工具是否存在。直接使用变量名(如`bun`),而非插值形式(`{{ bun }}`)。

Context7 Fallback

Context7 回退方案

For Just features not covered in this skill (new attributes, advanced functions, edge cases), fetch the latest documentation:
Use context7 MCP with library ID `/websites/just_systems-man` to get up-to-date Just documentation.
Example topics to search:
  • modules import mod
    - Module system details
  • settings
    - All available settings
  • attributes
    - Recipe attributes
  • functions
    - Built-in functions
  • script recipes
    - Script block syntax
对于本技能未覆盖的Just功能(新属性、高级函数、边缘场景),可获取最新文档:
使用context7 MCP,指定库ID为`/websites/just_systems-man`,以获取Just的最新文档。
示例搜索主题:
  • modules import mod
    - 模块系统细节
  • settings
    - 所有可用设置
  • attributes
    - Recipe属性
  • functions
    - 内置函数
  • script recipes
    - 脚本块语法

Additional Resources

额外资源

Reference Files

参考文件

For detailed patterns and comprehensive coverage, consult:
  • references/settings.md
    - Settings configuration and module system
  • references/recipes.md
    - Recipe attributes, parameters, dependencies, and prefixes
  • references/syntax.md
    - Constants, functions, variables, and CLI options
  • references/patterns.md
    - Established conventions, section organization, helper patterns
如需详细模式和全面说明,请参考:
  • references/settings.md
    - 设置配置与模块系统
  • references/recipes.md
    - Recipe属性、参数、依赖及前缀
  • references/syntax.md
    - 常量、函数、变量及CLI选项
  • references/patterns.md
    - 既定约定、章节组织、辅助模式

Example Templates

示例模板

Working justfile templates in
examples/
:
  • devkit.just
    - Minimal template importing @sablier/devkit
  • standalone.just
    - Full standalone template with all patterns
examples/
目录下的可用justfile模板:
  • devkit.just
    - 导入@sablier/devkit的极简模板
  • standalone.just
    - 包含所有模式的完整独立模板

External Documentation

外部文档

Tips

小贴士

  1. Use
    @
    prefix to suppress command echo:
    @echo "quiet"
  2. Use
    +
    for variadic parameters:
    test +args
  3. Use
    *
    for optional variadic:
    build *flags
  4. Quote glob patterns in variables:
    GLOBS := "\"**/*.json\""
  5. Use
    [no-cd]
    in monorepos to stay in current directory
  6. Private recipes start with
    _
    or use
    [private]
  7. Always define aliases after recipe names for discoverability
  1. 使用
    @
    前缀抑制命令回显:
    @echo "quiet"
  2. 使用
    +
    定义可变参数:
    test +args
  3. 使用
    *
    定义可选可变参数:
    build *flags
  4. 变量中的全局模式需加引号:
    GLOBS := "\"**/*.json\""
  5. 在单体仓库中使用
    [no-cd]
    以保持当前目录不变
  6. 私有Recipe以
    _
    开头或使用
    [private]
    属性
  7. 为提升可发现性,务必在Recipe名称后定义别名