summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it.class6
-rwxr-xr-xtest/it_pipe.t11
2 files changed, 8 insertions, 9 deletions
diff --git a/it.class b/it.class
index 6e294c3..098e57d 100644
--- a/it.class
+++ b/it.class
@@ -1228,11 +1228,9 @@ static function cat($p = null)
*/
static function pipe($cmd, ...$args)
{
- $values = [];
- foreach ($args as $arg)
- $values = array_merge($values, (array)$arg);
+ $args = array_reduce($args, fn($carry, $v) => array_merge($carry, (array)$v), []); # varargs to single arr
- return new it_pipe(is_string($cmd) ? array('cmd' => $cmd, 'args' => $values) : array('data' => $cmd));
+ return new it_pipe(is_string($cmd) ? array('cmd' => $cmd, 'args' => $args) : array('data' => $cmd));
}
/**
diff --git a/test/it_pipe.t b/test/it_pipe.t
index f6b069a..79c27b2 100755
--- a/test/it_pipe.t
+++ b/test/it_pipe.t
@@ -2,11 +2,12 @@
<?php
# it::cat frontend
-is(it::cat("test/it_pipe.t")->lines[1], "<?php");
-is(it::cat(['data' => "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"]);
+is(it::cat("test/it_pipe.t")->lines[1], "<?php");
+is(it::cat(['data' => "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('echo {f}', ['f' => 1, 'f' => 2])->lines(), [2]);
+is(it::pipe(['foo'])->lines(), ["foo"]);
# csv()
is(json_encode((new it_pipe(['data' => ["a\tb", "1\t2"]]))->csv()), '[{"a":"1","b":"2"}]');