Skip to content

Command

25 exports Added in v1.0.0 Source

Combinators

env

Added in v1.0.0 Source

Specify the environment variables that will be used when running this command.

By default, the configured variables extend the parent process environment. Set extendEnv to false to use only the configured variables.

Signature

declare const env: {
  (
    environment: Record<string, string | undefined>,
    options?: {
      readonly extendEnv?: boolean;
    },
  ): (self: Command) => Command;
  (
    self: Command,
    environment: Record<string, string | undefined>,
    options?: {
      readonly extendEnv?: boolean;
    },
  ): Command;
};

feed

Added in v1.0.0 Source

Feed a string to standard input (default encoding of UTF-8).

Signature

declare const feed: {
  (input: string): (self: Command) => Command;
  (self: Command, input: string): Command;
};

flatten

Added in v1.0.0 Source

Flatten this command to a non-empty array of standard commands.

For a StandardCommand, this simply returns a 1 element array For a PipedCommand, all commands in the pipe will be extracted out into a array from left to right

Signature

declare const flatten: (self: Command) => NonEmptyReadonlyArray<StandardCommand>;

pipeTo

Added in v1.0.0 Source

Pipe one command to another command from left to right.

Conceptually, the equivalent of piping one shell command to another:

``sh command1 | command2 ``

Signature

declare const pipeTo: {
  (into: Command): (self: Command) => Command;
  (self: Command, into: Command): Command;
};

runInShell

Added in v1.0.0 Source

Allows for specifying whether or not a Command should be run inside a shell.

Signature

declare const runInShell: {
  (shell: string | boolean): (self: Command) => Command;
  (self: Command, shell: string | boolean): Command;
};

stderr

Added in v1.0.0 Source

Specify the standard error stream for a command.

Signature

declare const stderr: {
  (stderr: CommandOutput): (self: Command) => Command;
  (self: Command, stderr: CommandOutput): Command;
};

stdin

Added in v1.0.0 Source

Specify the standard input stream for a command.

Signature

declare const stdin: {
  (stdin: CommandInput): (self: Command) => Command;
  (self: Command, stdin: CommandInput): Command;
};

stdout

Added in v1.0.0 Source

Specify the standard output stream for a command.

Signature

declare const stdout: {
  (stdout: CommandOutput): (self: Command) => Command;
  (self: Command, stdout: CommandOutput): Command;
};

Set the working directory that will be used when this command will be run.

For piped commands, the working directory of each command will be set to the specified working directory.

Signature

declare const workingDirectory: {
  (cwd: string): (self: Command) => Command;
  (self: Command, cwd: string): Command;
};

Constructors

make

Added in v1.0.0 Source

Create a command with the specified process name and an optional list of arguments.

Signature

declare const make: (command: string, ...args: Array<string>) => Command;

Execution

exitCode

Added in v1.0.0 Source

Returns the exit code of the command after the process has completed execution.

Signature

declare const exitCode: (self: Command) => Effect<ExitCode, PlatformError, CommandExecutor>;

lines

Added in v1.0.0 Source

Runs the command returning the output as an array of lines with the specified encoding.

Signature

declare const lines: (
  command: Command,
  encoding?: string,
) => Effect<Array<string>, PlatformError, CommandExecutor>;

start

Added in v1.0.0 Source

Start running the command and return a handle to the running process.

Signature

declare const start: (command: Command) => Effect<Process, PlatformError, CommandExecutor | Scope>;

stream

Added in v1.0.0 Source

Start running the command and return the output as a Stream.

Signature

declare const stream: (command: Command) => Stream<Uint8Array, PlatformError, CommandExecutor>;

streamLines

Added in v1.0.0 Source

Runs the command returning the output as an stream of lines with the specified encoding.

Signature

declare const streamLines: (
  command: Command,
  encoding?: string,
) => Stream<string, PlatformError, CommandExecutor>;

string

Added in v1.0.0 Source

Runs the command returning the entire output as a string with the specified encoding.

If an encoding is not specified, the encoding will default to utf-8.

Signature

declare const string: {
  (encoding?: string): (command: Command) => Effect<string, PlatformError, CommandExecutor>;
  (command: Command, encoding?: string): Effect<string, PlatformError, CommandExecutor>;
};

Models

Command type

Added in v1.0.0 Source

Signature

type Command = StandardCommand | PipedCommand;

CommandInput type

Added in v1.0.0 Source

Configures the pipe that is established between the parent and child processes' stdin stream.

Defaults to "pipe"

Signature

type CommandInput = "inherit" | "pipe" | Stream<Uint8Array, PlatformError>;

CommandOutput type

Added in v1.0.0 Source

Configures the pipes that are established between the parent and child processes stderr and stdout streams.

Defaults to "pipe"

Signature

type CommandOutput = "inherit" | "pipe" | Sink<Uint8Array, Uint8Array>;

PipedCommand interface

Added in v1.0.0 Source

Signature

interface PipedCommand extends Proto {
  readonly _tag: "PipedCommand";
  readonly left: Command;
  readonly right: Command;
}

StandardCommand interface

Added in v1.0.0 Source

Signature

interface StandardCommand extends Proto {
  readonly _tag: "StandardCommand";
  readonly args: readonly Array<string>;
  readonly command: string;
  readonly cwd: Option<string>;
  readonly env: HashMap<string, string>;
  readonly extendEnv: boolean;
  readonly gid: Option<number>;
  readonly shell: string | boolean;
  readonly stderr: CommandOutput;
  readonly stdin: CommandInput;
  readonly stdout: CommandOutput;
  readonly uid: Option<number>;
}

Other

Command

Added in v1.0.0 Source

Signature

declare const CommandTypeId: unique symbol;

CommandTypeId type

Added in v1.0.0 Source

Signature

type CommandTypeId = typeof CommandTypeId;

Refinements

isCommand

Added in v1.0.0 Source

Returns true if the specified value is a Command, otherwise returns false.

Signature

declare const isCommand: (u: unknown) => u is Command;