Skip to content

Commit

Permalink
update cli command builder
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 12, 2021
1 parent e673071 commit 352a273
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 42 deletions.
36 changes: 0 additions & 36 deletions app/Common/Cmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,6 @@
*/
class Cmd extends CmdBuilder
{
/**
* @var string
*/
protected string $cmdline = '';

/**
* @param string $cmdline
*
* @return Cmd
*/
public function setCmdline(string $cmdline): Cmd
{
$this->cmdline = $cmdline;
return $this;
}

/**
* @return string
*/
public function getCmdline(): string
{
return $this->cmdline;
}

/**
* @return string
*/
protected function buildCommandLine(): string
{
if ($this->cmdline) {
return $this->cmdline;
}

return parent::buildCommandLine();
}

/**
* @param string $msg
* @param string $scene
Expand Down
12 changes: 6 additions & 6 deletions app/Common/CmdRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($command = null, string $workDir = '')
parent::__construct('', $workDir);

if (is_string($command)) {
$this->command = $command;
$this->cmdline = $command;
} elseif (is_array($command)) {
$this->commands = (array)$command;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function do(bool $printOutput = false): self
*/
public function afterDo(string $cmd): self
{
return $this->setCommand($cmd)->do($this->printOutput);
return $this->setCmdline($cmd)->do($this->printOutput);
}

/**
Expand All @@ -112,7 +112,7 @@ public function whereDo(string $cmd, callable $whereFunc): self
{
// only run on return TRUE
if (true === $whereFunc()) {
$this->setCommand($cmd)->do($this->printOutput);
$this->setCmdline($cmd)->do($this->printOutput);
}

return $this;
Expand All @@ -134,7 +134,7 @@ public function afterOkDo(string $cmd, string $workDir = null): self
$this->workDir = $workDir;
}

return $this->setCommand($cmd)->do($this->printOutput);
return $this->setCmdline($cmd)->do($this->printOutput);
}

/**************************************************************************
Expand Down Expand Up @@ -251,10 +251,10 @@ public function addByArray(array $config, string $key = ''): self
*
* @return $this
*/
public function run(bool $printOutput = false): AbstractCmdBuilder
public function run(bool $printOutput = false): static
{
$this->printOutput = $printOutput;
if ($command = $this->command) {
if ($command = $this->cmdline) {
$this->innerExecute($command, $this->workDir);

// stop on error
Expand Down

0 comments on commit 352a273

Please sign in to comment.