just
为您提供一种保存和运行项目特有命令的便捷方式
入门
简单的 justfile
1 2 3 4 5
| #!/usr/bin/env just --justfile
hello: echo "Hello World!"
|
带参数的配方
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| filter PATTERN: echo {{PATTERN}}
email address='master@example.com': echo {{address}}
test triple=(arch() + "-unknown-unknown"): ./test {{triple}}
backup +FILES: scp {{FILES}} me@example.com
commit MESSAGE *FLAGS: git commit {{FLAGS}} -m "{{MESSAGE}}"
|
变量和子变量
1 2 3 4 5 6 7 8 9
| version := "0.2.7" tardir := "awesomesauce-" + version tarball := tardir + ".tar.gz"
test: echo {{version}}
$ just --set version 1.1.0
|
默认配置
1 2 3 4 5
| default: lint build test
default: @just --list
|
命令的环境变量
1 2 3 4 5
| export RUST_BACKTRACE := "1"
test: cargo test
|
backtick-从评估中捕获输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| JAVA_HOME := `jbang jdk home 11`
stuff := \``` foo="hello" echo $foo "world" \```
done BRANCH=`git rev-parse --abbrev-ref HEAD`: git checkout master
sloc: @echo "`wc -l *.c` lines of code"
|
注意: 上面示例中 \`
没有转义过来
别名
1 2
| alias t := test alias c := check
|
带有命令 env 变量配置
1 2 3
| hello $name: echo $name
|
设置
1 2 3 4 5 6 7 8 9 10
| set shell := ["zsh", "-cu"]
set dotenv-load := true serv: echo "$DATABASE_ADDRESS from .env"
set positional-arguments := true foo: echo $0 echo $1
|
配置依赖性-之前、之后和周围
1 2 3 4 5 6 7 8 9 10 11 12
| b: a && c d
b: echo 'B start!' just a echo 'B end!'
default: (build "main")
build target: @echo 'Building {{target}}...'
|
Just 函数
1 2 3 4 5 6 7 8 9 10 11 12
| hello name: echo {{os()}} echo {{uppercase(name)}}
# 函数类别 * 系统信息 * 系统信息 * Justfile 和 Justfile目录 * 字符串操纵 * 路径操纵
# String contact: (key + ":" + value)
|
字符串-用双引号转义
1 2 3 4 5 6 7 8 9
| tring-with-tab := "\t" string-with-newline := "\n" escapes := '\t\n\r\"\\'
x := ''' foo bar '''
|
命令注释:quiet(@)、suppress(-)、invert(!)
1 2 3 4 5 6 7 8 9 10 11
| hello: @ echo "command will not be echoed" - echo "ignore none-zero exit status and continue"
@hello2: echo "command will not be echoed"
hello3: ! git branch | grep '* master'
|
条件表达式:if、loop 和 while
1 2 3 4 5 6 7 8 9 10
| # 正则表达匹配 fo := if "hi" =~ 'h.+' { "match" } else { "mismatch" }
test: if true; then echo 'True!'; fi for file in `ls .`; do echo $file; done while `server-is-dead`; do ping -c 1 server; done
foo bar: echo {{ if bar == "bar" { "hello" } else { "bye" } }}
|
Just 命令行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $ just hello param1
$ just --list $ just --summary
just --show test
$ just --choose
just --completions zsh
|
其他语言的配置
1 2 3 4 5
| bash-test: set -euxo pipefail hello='Yo' echo "$hello from bash!"
|
私人配置 - 名称以开头 _
1 2 3 4 5 6
| test: _test-helper ./bin/test
_test-helper: ./bin/super-secret-test-helper-stuff
|
注意
1 2 3 4 5 6 7 8 9 10 11 12 13
|
change-working-dir: cd bar && pwd if true; then \ echo 'True!'; \ fi
|
作为 shell 别名的配置
1 2 3
| for recipe in `just -f ~/.justfile --summary`; do alias $recipe="just -f ~/.justfile -d. $recipe" done
|
IDE 集成