feat: emulate rust's process api more closely

Yoink some docs as well
This commit is contained in:
2025-08-17 17:16:56 +02:00
parent 34e1b0b791
commit 6b1b98b662
4 changed files with 335 additions and 71 deletions

View File

@@ -6,6 +6,10 @@ namespace Nih\CommandBuilder;
use Stringable;
/**
* Describes what to do with a standard I/O stream for a child process when
* passed to the stdin, stdout, and stderr methods of {@see Command}.
*/
final class Stdio
{
public const INHERIT = 0;
@@ -25,27 +29,44 @@ final class Stdio
) {
}
/**
* The child inherits from the corresponding parent descriptor.
*/
public static function inherit(): self
{
return new self(self::INHERIT, null);
}
/**
* A new pipe should be arranged to connect the parent and child processes.
*/
public static function piped(): self
{
return new self(self::PIPE, ['pipe', 'r']);
}
/**
* This stream will be ignored. This is the equivalent of attaching the
* stream to `/dev/null`.
*/
public static function null(): self
{
return self::file('/dev/null', 'a+');
}
/**
* Like piped, but instead of capturing the stream into a handle, read
* and/or write from/to a file.
*/
public static function file(string|Stringable $file, string $mode): self
{
return new self(self::FILE, ['file', (string) $file, $mode]);
}
/**
* Like piped, but instead of capturing the stream into a handle, read
* and/or write from/to a stream.
*
* @param resource|StreamReadable|StreamWritable $stream
*/
public static function stream($stream): self