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