From 1feca783d60c0fdf0c60dd65801eed07b09cb4b7 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 18 Jul 2023 19:21:56 +0200 Subject: support varags in it::pipe like in it::exec --- it.class | 8 ++++++-- test/it_pipe.t | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/it.class b/it.class index 13e3aa0..6e294c3 100644 --- a/it.class +++ b/it.class @@ -1226,9 +1226,13 @@ static function cat($p = null) * @param $cmd command to execute, or if it is an array, the lines to use * @param $args named arguments to fill into cmd. see it::exec for usage */ -static function pipe($cmd, $args = array()) +static function pipe($cmd, ...$args) { - return new it_pipe(is_string($cmd) ? array('cmd' => $cmd, 'args' => $args) : array('data' => $cmd)); + $values = []; + foreach ($args as $arg) + $values = array_merge($values, (array)$arg); + + return new it_pipe(is_string($cmd) ? array('cmd' => $cmd, 'args' => $values) : array('data' => $cmd)); } /** diff --git a/test/it_pipe.t b/test/it_pipe.t index 15e51f6..f6b069a 100755 --- a/test/it_pipe.t +++ b/test/it_pipe.t @@ -5,6 +5,7 @@ is(it::cat("test/it_pipe.t")->lines[1], " "foo"])->lines(), ["foo"]); is(it::pipe('echo {x}', ['x' => "foo"])->lines(), ["foo"]); +is(it::pipe('echo {0}{1}', "f", "oo")->lines(), ["foo"]); is(it::pipe(['foo'])->lines(), ["foo"]); # csv() -- cgit v1.2.3