ExecOneCommand
trait ExecOneCommand (View source)
This task specifies exactly one shell command.
It can take additional arguments and options as config parameters.
Traits
This task is supposed to be executed as shell command.
Use this to add arguments and options to the $arguments property.
Class ExecTrait
Properties
protected bool | $background | from ExecTrait | |
protected null|int | $timeout | from ExecTrait | |
protected null|int | $idleTimeout | from ExecTrait | |
protected null|array | $env | from ExecTrait | |
protected Process | $process | from ExecTrait | |
protected resource|string | $input | from ExecTrait | |
protected bool | $interactive | from ExecTrait | |
protected bool | $isPrinted | from ExecTrait | |
protected bool | $isMetadataPrinted | from ExecTrait | |
protected string | $workingDirectory | from ExecTrait | |
protected TimeKeeper | $execTimer | from ExecCommand | |
protected string | $arguments | from CommandArguments |
Methods
Executes command in background mode (asynchronously)
Stops command if it does not output something for a while
Set a single environment variable, or multiple.
Pass an input to the process. Can be resource created with fopen() or string
Pass an input to the process. Can be resource created with fopen() or string
Attach tty to process for interactive input
Shortcut for setting isPrinted() and isMetadataPrinted() to false.
Should command metadata be printed. I,e., command and timer.
Look for a "{$cmd}.phar" in the current working directory; return a string to exec it if it is found. Otherwise, look for an executable command of the same name via findExecutable.
Return the best path to the executable program with the provided name. Favor vendor/bin in the current project. If not found there, use whatever is on the $PATH.
Wrap Windows executables in 'call' per 7a88757d
Pass argument to executable. Its value will be automatically escaped.
Pass methods parameters as arguments to executable. Argument values are automatically escaped.
Pass the provided string in its raw (as provided) form as an argument to executable.
Escape the provided value, unless it contains only alphanumeric plus a few other basic characters.
Pass option to executable. Options are prefixed with --
, value can be provided in second parameter.
Pass multiple options to executable. The associative array contains
the key:value pairs that become --key value
, for each item in the array.
Pass an option with multiple values to executable. Value can be a string or array.
Details
abstract string
getCommandDescription()
No description
abstract protected
startTimer()
No description
abstract protected
stopTimer()
No description
abstract protected null|float
getExecutionTime()
No description
abstract protected bool
hideTaskProgress()
No description
abstract protected
showTaskProgress(bool $inProgress)
No description
abstract protected
printTaskInfo(string $text, null|array $context = null)
No description
abstract bool
verbosityMeetsThreshold()
No description
abstract
writeMessage(string $message)
No description
$this
detectInteractive()
Sets $this->interactive() based on posix_isatty().
$this
background(bool $arg = true)
Executes command in background mode (asynchronously)
$this
timeout(int $timeout)
Stop command if it runs longer then $timeout in seconds
$this
idleTimeout(int $timeout)
Stops command if it does not output something for a while
$this
env(string|array $env, bool|string $value = null)
Set a single environment variable, or multiple.
$this
envVars(array $env)
Sets the environment variables for the command
$this
setProcessInput(resource|string $input)
Pass an input to the process. Can be resource created with fopen() or string
$this
setInput(resource|string $input)
deprecated
deprecated
Pass an input to the process. Can be resource created with fopen() or string
$this
interactive(bool $interactive = true)
Attach tty to process for interactive input
bool
getPrinted()
Is command printing its output to screen
$this
dir(string $dir)
Changes working directory of command
$this
silent(bool $arg)
Shortcut for setting isPrinted() and isMetadataPrinted() to false.
$this
printed(bool $arg)
deprecated
deprecated
Should command output be printed
$this
printOutput(bool $arg)
Should command output be printed
$this
printMetadata(bool $arg)
Should command metadata be printed. I,e., command and timer.
protected ResultData
execute(Process $process, callable $output_callback = null)
No description
protected
stop()
No description
protected
printAction(array $context = [])
No description
protected string
formatCommandDisplay(string $command)
No description
protected array
getResultData()
Gets the data array to be passed to Result().
protected TimeKeeper
getExecTimer()
No description
protected bool|string
findExecutablePhar(string $cmd)
Look for a "{$cmd}.phar" in the current working directory; return a string to exec it if it is found. Otherwise, look for an executable command of the same name via findExecutable.
protected bool|string
findExecutable(string $cmd)
Return the best path to the executable program with the provided name. Favor vendor/bin in the current project. If not found there, use whatever is on the $PATH.
protected bool|string
findProjectBin()
No description
protected string
useCallOnWindows(string $cmd)
Wrap Windows executables in 'call' per 7a88757d
protected Result
executeCommand(string $command)
No description
$this
arg(string $arg)
Pass argument to executable. Its value will be automatically escaped.
$this
args(string|string[] $args)
Pass methods parameters as arguments to executable. Argument values are automatically escaped.
$this
rawArg(string $arg)
Pass the provided string in its raw (as provided) form as an argument to executable.
static string
escape(string $value)
Escape the provided value, unless it contains only alphanumeric plus a few other basic characters.
$this
option(string $option, string $value = null, string $separator = ' ')
Pass option to executable. Options are prefixed with --
, value can be provided in second parameter.
Option values are automatically escaped.
$this
options(array $options, string $separator = ' ')
Pass multiple options to executable. The associative array contains
the key:value pairs that become --key value
, for each item in the array.
Values are automatically escaped.
$this
optionList(string $option, string|array $value = array(), string $separator = ' ')
Pass an option with multiple values to executable. Value can be a string or array.
Option values are automatically escaped.