X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Frobo%2Fsrc%2FCommon%2FCommandArguments.php;fp=vendor%2Fconsolidation%2Frobo%2Fsrc%2FCommon%2FCommandArguments.php;h=12c2e89fd2badf9ba0c653e3694be2663d2116c5;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/consolidation/robo/src/Common/CommandArguments.php b/vendor/consolidation/robo/src/Common/CommandArguments.php new file mode 100644 index 000000000..12c2e89fd --- /dev/null +++ b/vendor/consolidation/robo/src/Common/CommandArguments.php @@ -0,0 +1,130 @@ +args($arg); + } + + /** + * Pass methods parameters as arguments to executable. Argument values + * are automatically escaped. + * + * @param string|string[] $args + * + * @return $this + */ + public function args($args) + { + if (!is_array($args)) { + $args = func_get_args(); + } + $this->arguments .= ' ' . implode(' ', array_map('static::escape', $args)); + return $this; + } + + /** + * Pass the provided string in its raw (as provided) form as an argument to executable. + * + * @param string $arg + * + * @return $this + */ + public function rawArg($arg) + { + $this->arguments .= " $arg"; + + return $this; + } + + /** + * Escape the provided value, unless it contains only alphanumeric + * plus a few other basic characters. + * + * @param string $value + * + * @return string + */ + public static function escape($value) + { + if (preg_match('/^[a-zA-Z0-9\/\.@~_-]+$/', $value)) { + return $value; + } + return ProcessUtils::escapeArgument($value); + } + + /** + * Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. + * Option values are automatically escaped. + * + * @param string $option + * @param string $value + * @param string $separator + * + * @return $this + */ + public function option($option, $value = null, $separator = ' ') + { + if ($option !== null and strpos($option, '-') !== 0) { + $option = "--$option"; + } + $this->arguments .= null == $option ? '' : " " . $option; + $this->arguments .= null == $value ? '' : $separator . static::escape($value); + return $this; + } + + /** + * 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. + */ + public function options(array $options, $separator = ' ') + { + foreach ($options as $option => $value) { + $this->option($option, $value, $separator); + } + return $this; + } + + /** + * Pass an option with multiple values to executable. Value can be a string or array. + * Option values are automatically escaped. + * + * @param string $option + * @param string|array $value + * @param string $separator + * + * @return $this + */ + public function optionList($option, $value = array(), $separator = ' ') + { + if (is_array($value)) { + foreach ($value as $item) { + $this->optionList($option, $item, $separator); + } + } else { + $this->option($option, $value, $separator); + } + + return $this; + } +}