API 參考資料
host
host(string ...$hostname): Host
聲明一個主機(jī)或一組主機(jī). 了解更多請移步 主機(jī).
localhost
localhost(string ...$alias = 'localhost'): Host
聲明本地主機(jī).
inventory
inventory(string $file): Host[]
載入主機(jī)清單文件
desc
desc(string $description)
設(shè)置任務(wù)描述.
task
task(string $name, string $script)task(string $name, callable $callable)task(string $name): Task
聲明一個任務(wù)或獲取一個任務(wù). 了解更多請移步 任務(wù).
before
before(string $when, string $that)
在任務(wù) $when 之前, 執(zhí)行任務(wù) $that.
after
after(string $when, string $that)
在任務(wù) $when 之后, 執(zhí)行任務(wù)$that.
fail
fail(string $what, string $that)
如果任務(wù) $what 執(zhí)行失敗, 執(zhí)行任務(wù) $that.
argument
argument($name, $mode = null, $description = '', $default = null)
添加用戶的cli參數(shù).
option
option($name, $shortcut=null, $mode=null, $description='', $default=null)
添加用戶的cli選項(xiàng).
cd
cd(string $path)
設(shè)置run函數(shù)下的工作路徑.
每個任務(wù)都會將工作路徑恢復(fù)到任務(wù)開始時的基本工作路徑.
cd('{{release_path}}');
run('npm run build');
within
within(string $path, callable $callback)
在指定的路徑 $path內(nèi)部運(yùn)行回調(diào)函數(shù)$callback.
within('{{release_path}}', function () {
run('npm run build');
});
workingPath
workingPath(): string
返回當(dāng)前工作路徑.
cd('{{release_path}}');
workingPath() == '/var/www/app/releases/1';
run
run(string $command, $options = []): string
在遠(yuǎn)程主機(jī)上運(yùn)行命令. 可用選項(xiàng):
timeout— 設(shè)置進(jìn)程超時 (最大運(yùn)行時間) . 要禁用超時, 請將此值設(shè)置為null.
超時時間(秒) 默認(rèn)值:300秒tty— 啟用或禁用TTY模式 默認(rèn)值:false
例如, 如果您的私鑰包含密碼短語, 啟用tty, 您將看到git提示輸入密碼.
run('git clone ...', ['timeout' => null, 'tty' => true]);
run函數(shù)以字符串形式返回輸出的命令:
$path = run('readlink {{deploy_path}}/current');
run("echo $path");
runLocally
runLocally($command, $options = []): string
在localhost上運(yùn)行命令. 可用選項(xiàng):
timeout— 超時時間(秒) 默認(rèn)值:300秒tty— TTY模式 默認(rèn)值:false
test
test(string $command): bool
運(yùn)行測試命令.
if (test('[ -d {{release_path}} ]')) {
...
}
testLocally
testLocally(string $command): bool
在本地運(yùn)行測試命令.
on
on(Host $host, callable $callback)on(Host[] $host, callable $callback)
在指定的主機(jī)上運(yùn)行函數(shù) $callback .
on(host('domain.com'), function ($host) {
...
});
on(roles('app'), function ($host) {
...
});
on(Deployer::get()->hosts, function ($host) {
...
});
roles
roles(string ...$role): Host[]
按角色返回主機(jī)列表.
invoke
invoke(string $task)
在當(dāng)前主機(jī)上運(yùn)行任務(wù).
task('deploy', function () {
invoke('deploy:prepare');
invoke('deploy:release');
...
});
注意 這個是實(shí)驗(yàn)功能.
upload
upload(string $source, string $destination, $config = [])
從 $source 上傳文件到遠(yuǎn)程主機(jī) $destination .
upload('build/', '{{release_path}}/public');
您可能已經(jīng)注意到, 在上述命令的第一個參數(shù)的末尾有一個斜杠(/), 意思就是 "
build下的內(nèi)容".另一種方法是不使用斜杠, 將
build這個目錄直接放到public中. 他的創(chuàng)建的層級, 是這個樣子:{{release_path}}/public/build
可用選項(xiàng):
timeout— 超時時間 默認(rèn)值: nulloptions—rsync選項(xiàng).
download
download(string $source, string $destination, $config = [])
從遠(yuǎn)程主機(jī) $source 下載文件到本地主機(jī) $destination 中.
可用選項(xiàng):
timeout— 超時時間 默認(rèn)值: nulloptions—rsync選項(xiàng).
write
在輸出中寫入消息.
您可以使用標(biāo)記格式化消息 <info>...</info>, <comment></comment> or <error></error> (參考 Symfony Console).
writeln
與 write函數(shù)相同, 但會另起一行.
set
set(string $name, string|int|bool|array $value)set(string $name, callable $value)
設(shè)置全局配置參數(shù). 如果callable作為$value傳遞, 它將在第一次獲取此配置時觸發(fā).
了解更多請移步 配置.
add
add(string $name, array $values)
向現(xiàn)有配置添加值.
了解更多請移步 配置.
get
get(string $name, $default = null): string|int|bool|array
獲取配置值.
了解更多請移步 配置.
has
has(string $name): bool
檢查配置項(xiàng)是否存在.
了解更多請移步 配置.
ask
ask(string $message, $default = null, $suggestedChoices = null)
請求用戶輸入.
askChoice
askChoice(string $message, array $availableChoices, $default = null, $multiselect = false)
要求用戶從多個鍵/值選項(xiàng)中選擇并返回一個數(shù)組. 啟用多選時, 結(jié)果使用逗號隔開選中的內(nèi)容. 默認(rèn)值將在靜默模式下使用, 否則將接受第一個可用選項(xiàng).
askConfirmation
askConfirmation(string $message, bool $default = false)
詢問用戶 “是” 或 “否” 的問題 .
askHiddenResponse
askHiddenResponse(string $message)
詢問用戶密碼.
input
input(): Input
獲取當(dāng)前控制臺輸入.
output
output(): Output
獲取當(dāng)前控制臺輸出.
isQuiet
isQuiet(): bool
檢查 dep 命令是否用 -q 選項(xiàng)啟動.
isVerbose
isVerbose(): bool
檢查 dep 命令是否用 -v 選項(xiàng)啟動.
isVeryVerbose
isVeryVerbose(): bool
檢查 dep 命令是否用 -vv 選項(xiàng)啟動.
isDebug
isDebug(): bool
檢查 dep 命令是否用 -vvv 選項(xiàng)啟動.
commandExist
commandExist(string $command): bool
檢查命令是否存在.
if (commandExist('composer')) {
...
}
parse
parse(string $line): string
解析在配置 $line 中出現(xiàn)的 {{ }}.