Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3ace8a3ea |
41
src/ExecutableArguments.php
Normal file
41
src/ExecutableArguments.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Droath\RoboDockerCompose;
|
||||||
|
|
||||||
|
use Robo\Common\CommandArguments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define command executable arguments.
|
||||||
|
*/
|
||||||
|
trait ExecutableArguments
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Executable arguments.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $executableArgs = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add executable options.
|
||||||
|
*
|
||||||
|
* @param string $option
|
||||||
|
* The executable option name.
|
||||||
|
* @param string $value
|
||||||
|
* The executable option value.
|
||||||
|
*/
|
||||||
|
protected function execOption($option, $value = null)
|
||||||
|
{
|
||||||
|
if (isset($option)) {
|
||||||
|
if (strpos($option, '-') !== 0) {
|
||||||
|
$option = "--$option";
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->executableArgs .= null == $option ? '' : ' ' . $option;
|
||||||
|
$this->executableArgs .= null == $value ? '' : ' ' . CommandArguments::escape($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Droath\RoboDockerCompose\Task;
|
namespace Droath\RoboDockerCompose\Task;
|
||||||
|
|
||||||
|
use Droath\RoboDockerCompose\ExecutableArguments;
|
||||||
use Robo\Common\ExecOneCommand;
|
use Robo\Common\ExecOneCommand;
|
||||||
use Robo\Exception\TaskException;
|
use Robo\Exception\TaskException;
|
||||||
use Robo\Task\BaseTask;
|
use Robo\Task\BaseTask;
|
||||||
@@ -12,6 +13,7 @@ use Robo\Task\BaseTask;
|
|||||||
abstract class Base extends BaseTask
|
abstract class Base extends BaseTask
|
||||||
{
|
{
|
||||||
use ExecOneCommand;
|
use ExecOneCommand;
|
||||||
|
use ExecutableArguments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executable.
|
* Executable.
|
||||||
@@ -35,11 +37,9 @@ abstract class Base extends BaseTask
|
|||||||
*/
|
*/
|
||||||
public function __construct($pathToDockerCompose = null)
|
public function __construct($pathToDockerCompose = null)
|
||||||
{
|
{
|
||||||
$this->executable = $pathToDockerCompose;
|
$this->executable = isset($pathToDockerCompose)
|
||||||
|
? $pathToDockerCompose
|
||||||
if (!$this->executable) {
|
: $this->findExecutablePhar('docker-compose');
|
||||||
$this->executable = $this->findExecutablePhar('docker-compose');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->executable) {
|
if (!$this->executable) {
|
||||||
throw new TaskException(
|
throw new TaskException(
|
||||||
@@ -49,6 +49,66 @@ abstract class Base extends BaseTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify an alternate compose file.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* An alternative docker composer file
|
||||||
|
*/
|
||||||
|
public function file($filename)
|
||||||
|
{
|
||||||
|
if (!file_exists($filename)) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
sprintf("File %s wasn't found on the filesystem", $filename)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->execOption('file', $filename);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify multiple composer files.
|
||||||
|
*
|
||||||
|
* @param array $files
|
||||||
|
* An array of alternative composer files.
|
||||||
|
*/
|
||||||
|
public function files(array $files)
|
||||||
|
{
|
||||||
|
foreach ($files as $filename) {
|
||||||
|
$this->file($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify an alternate project name.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* An alternative docker compose project name.
|
||||||
|
*/
|
||||||
|
public function projectName($name)
|
||||||
|
{
|
||||||
|
$this->execOption('project-name', $name);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daemon socket to connect to.
|
||||||
|
*
|
||||||
|
* @param string $hostname
|
||||||
|
* The name of the host to connect to.
|
||||||
|
*/
|
||||||
|
public function host($hostname)
|
||||||
|
{
|
||||||
|
$this->execOption('host', $hostname);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -70,6 +130,6 @@ abstract class Base extends BaseTask
|
|||||||
*/
|
*/
|
||||||
protected function getCommand()
|
protected function getCommand()
|
||||||
{
|
{
|
||||||
return "{$this->executable} {$this->action} {$this->arguments}";
|
return "{$this->executable} {$this->executableArgs} {$this->action} {$this->arguments}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user