cli-just
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJust 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
常用属性
| Attribute | Purpose |
|---|---|
| Configure parameter as |
| Constrain parameter to match regex pattern |
| Group recipes in |
| Don't change to justfile directory |
| Hide from |
| Execute recipe as single script block |
| Use specific interpreter (bash, python, etc.) |
| Require user confirmation before running |
| Override recipe documentation |
| Enable positional args for this recipe only |
| Attribute(属性) | 用途 |
|---|---|
| 将参数配置为 |
| 限制参数匹配指定正则表达式 |
| 在 |
| 不切换到justfile所在目录 |
| 在 |
| 将recipe作为单个脚本块执行 |
| 使用指定解释器(bash、python等) |
| 运行前要求用户确认 |
| 覆盖recipe的文档说明 |
| 仅为此recipe启用位置参数 |
Recipe Argument Flags (v1.46.0+)
Recipe参数选项(v1.46.0+)
The attribute configures parameters as CLI-style options:
[arg()]just
undefined[arg()]just
undefinedLong 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帮助文本(在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 helpMultiple 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):
| Constant | Description |
|---|---|
| Text colors |
| Text styles |
| Reset formatting |
| Background colors (BG_RED, BG_GREEN, etc.) |
| Hexadecimal digits |
Usage:
just
@status:
echo -e '{{ GREEN }}Success!{{ NORMAL }}'
echo -e '{{ BOLD + CYAN }}Building...{{ NORMAL }}'终端格式化常量全局可用(无需定义):
| 常量 | 描述 |
|---|---|
| 文本颜色 |
| 文本样式 |
| 重置格式 |
| 背景色(BG_RED、BG_GREEN等) |
| 十六进制数字 |
使用示例:
just
@status:
echo -e '{{ GREEN }}Success!{{ NORMAL }}'
echo -e '{{ BOLD + CYAN }}Building...{{ NORMAL }}'Key Functions
核心函数
just
undefinedjust
undefinedRequire 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()
undefinedroot := justfile_dir()
undefinedRecipe 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-statusCheck/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-writeFull 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-writeStandard Alias Conventions
标准别名约定
| Recipe | Alias | Recipe | Alias |
|---|---|---|---|
| full-check | fc | full-write | fw |
| biome-check | bc | biome-write | bw |
| prettier-check | pc | prettier-write | pw |
| mdformat-check | mc | mdformat-write | mw |
| tsc-check | tc | ruff-check | rc |
| test | t | build | b |
| Recipe | 别名 | Recipe | 别名 |
|---|---|---|---|
| full-check | fc | full-write | fw |
| biome-check | bc | biome-write | bw |
| prettier-check | pc | prettier-write | pw |
| mdformat-check | mc | mdformat-write | mw |
| tsc-check | tc | ruff-check | rc |
| test | t | build | b |
Inline Scripts
内联脚本
Just supports inline scripts in any language via two methods:
Just支持通过两种方式在任意语言中编写内联脚本:
Script Attribute (Recommended)
Script属性(推荐)
Use for cross-platform compatibility:
[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/使用实现跨平台兼容:
[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 at the recipe start:
#!/usr/bin/env interpreterjust
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:
- - Better cross-platform support, cleaner syntax
[script()] - Shebang - Traditional Unix approach, works without
set unstable
在recipe开头使用:
#!/usr/bin/env interpreterjust
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 unstablejust
mod foo # Loads foo.just or foo/justfile
mod bar "path/to/bar" # Custom path
mod? optional # Optional module加载子模块(需设置):
set unstablejust
mod foo # 加载foo.just或foo/justfile
mod bar "path/to/bar" # 自定义路径
mod? optional # 可选模块Call module recipes
调用模块中的recipes
just foo::build
undefinedjust foo::build
undefinedDevkit Import Pattern
Devkit导入模式
For projects using :
@sablier/devkitjust
import "./node_modules/@sablier/devkit/just/base.just"
import "./node_modules/@sablier/devkit/just/npm.just"对于使用的项目:
@sablier/devkitjust
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
undefinedShow available commands
显示可用命令
default:
@just --list
undefineddefault:
@just --list
undefinedDependencies Declaration
依赖声明
Document required tools at the top:
just
undefined在顶部文档化所需工具:
just
undefined----------------------------------------------------------------------------
----------------------------------------------------------------------------
DEPENDENCIES
DEPENDENCIES
----------------------------------------------------------------------------
----------------------------------------------------------------------------
Bun: https://bun.sh
Bun: https://bun.sh
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:
- - Module system details
modules import mod - - All available settings
settings - - Recipe attributes
attributes - - Built-in functions
functions - - Script block syntax
script recipes
对于本技能未覆盖的Just功能(新属性、高级函数、边缘场景),可获取最新文档:
使用context7 MCP,指定库ID为`/websites/just_systems-man`,以获取Just的最新文档。示例搜索主题:
- - 模块系统细节
modules import mod - - 所有可用设置
settings - - Recipe属性
attributes - - 内置函数
functions - - 脚本块语法
script recipes
Additional Resources
额外资源
Reference Files
参考文件
For detailed patterns and comprehensive coverage, consult:
- - Settings configuration and module system
references/settings.md - - Recipe attributes, parameters, dependencies, and prefixes
references/recipes.md - - Constants, functions, variables, and CLI options
references/syntax.md - - Established conventions, section organization, helper patterns
references/patterns.md
如需详细模式和全面说明,请参考:
- - 设置配置与模块系统
references/settings.md - - Recipe属性、参数、依赖及前缀
references/recipes.md - - 常量、函数、变量及CLI选项
references/syntax.md - - 既定约定、章节组织、辅助模式
references/patterns.md
Example Templates
示例模板
Working justfile templates in :
examples/- - Minimal template importing @sablier/devkit
devkit.just - - Full standalone template with all patterns
standalone.just
examples/- - 导入@sablier/devkit的极简模板
devkit.just - - 包含所有模式的完整独立模板
standalone.just
External Documentation
外部文档
- Official Manual: https://just.systems/man/en/
- GitHub Repository: https://github.com/casey/just
- Context7 Library ID:
/websites/just_systems-man
- 官方手册: https://just.systems/man/en/
- GitHub仓库: https://github.com/casey/just
- Context7库ID:
/websites/just_systems-man
Tips
小贴士
- Use prefix to suppress command echo:
@@echo "quiet" - Use for variadic parameters:
+test +args - Use for optional variadic:
*build *flags - Quote glob patterns in variables:
GLOBS := "\"**/*.json\"" - Use in monorepos to stay in current directory
[no-cd] - Private recipes start with or use
_[private] - Always define aliases after recipe names for discoverability
- 使用前缀抑制命令回显:
@@echo "quiet" - 使用定义可变参数:
+test +args - 使用定义可选可变参数:
*build *flags - 变量中的全局模式需加引号:
GLOBS := "\"**/*.json\"" - 在单体仓库中使用以保持当前目录不变
[no-cd] - 私有Recipe以开头或使用
_属性[private] - 为提升可发现性,务必在Recipe名称后定义别名