Skip to content

Commit f060632

Browse files
committed
update: update some for cmd build
1 parent 9dace04 commit f060632

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Cmd/AbstractCmdBuilder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ public function getWorkDir(): string
240240
*/
241241
public function setWorkDir(string $workDir): static
242242
{
243-
Assert::isDir($workDir, "workdir is not exists. path: $workDir");
243+
if ($workDir) {
244+
Assert::isDir($workDir, "workdir is not exists. path: $workDir");
245+
}
246+
244247
$this->workDir = $workDir;
245248
return $this;
246249
}

src/Cmd/CmdBuilder.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ public function addArgs(...$args): static
131131
return $this;
132132
}
133133

134+
/**
135+
* Call fn on args is not empty.
136+
*
137+
* Usage:
138+
*
139+
* ```php
140+
* $c->withIf(fn($args) => $c->addArgs(...$args), $args)
141+
* ```
142+
*
143+
* @template T
144+
* @param callable(T): void $fn
145+
* @param T $args
146+
*
147+
* @return $this
148+
*/
149+
public function withIf(callable $fn, mixed $args): static
150+
{
151+
if ($args) {
152+
$fn($this);
153+
}
154+
return $this;
155+
}
156+
134157
/**
135158
* @param bool $printOutput
136159
*

0 commit comments

Comments
 (0)