cli_script library

Classes

BufferedScript
A Script wrapper that suppresses all output and stores it in a buffer until release is called, at which point it forwards the suppressed output to stdout and stderr.
Script
A unit of execution that behaves like a process, with stdin, stdout, and stderr streams that ultimately produces an exitCode indicating success or failure.
ScriptComponents
A struct containing the components needed to create a Script.

Extensions

ByteListExtensions on List<int>
Extensions on List<int> for piping it as input to a Script.
ByteStreamExtensions on Stream<List<int>>
Extensions on Stream<List<int>> that make it easier to consume the output of scripts in a human-friendly, easily-to-manipulate manner.
ChunkListExtensions on List<List<int>>
Extensions on List<List<int>> for piping it as input to a Script.
LineAndSpanStreamExtensions on Stream<Tuple2<String, SourceSpanWithContext>>
Extensions on Stream<Tuple2<String, SourceSpanWithContext>> that treat it as a stream of discrete lines associated with spans that indicate where the lines came from originally.
LineListExtensions on List<String>
Extensions on List<String> for piping it as input to a Script.
LineStreamExtensions on Stream<String>
Extensions on Stream<String> that treat it as a stream of discrete lines (as commonly emitted by a shell script).
StringExtensions on String
Extensions on String for piping it as input to a Script.

Properties

currentStderr IOSink
Returns a sink for writing directly to the current stderr stream.
no setter
currentStdout IOSink
Returns a sink for writing directly to the current stdout stream.
no setter
env Map<String, String>
The default environment for subprocesses spawned by Platform.environment.
no setter
teeToStderr → NamedStreamTransformer<String, String>
A transformer that emits each string exactly as it was received, but also prints each string to currentStderr.
final

Functions

append(String path) IOSink
A shorthand for opening a sink that appends to the file at path.
arg(Object argument) String
Converts argument to a string and escapes it so it's parsed as a single argument with no glob expansion by new Script and related functions.
args(Iterable<Object> arguments) String
Converts all elements of arguments to strings and escapes them so they're parsed as separate arguments with no glob expansion by new Script and related functions.
check(String executableAndArgs, {Iterable<String>? args, String? name, String? workingDirectory, Map<String, String>? environment, bool includeParentEnvironment = true, bool runInShell = false}) Future<bool>
Runs an executable and returns whether it returns exit code 0.
fail(String message, {int exitCode = 1}) → Never
Prints message to stderr and exits the current script.
grep(String regexp, {bool exclude = false, bool onlyMatching = false, bool caseSensitive = true, bool unicode = false, bool dotAll = false}) StreamTransformer<String, String>
Returns a transformer that emits only the elements of the source stream that match regexp.
lines(String executableAndArgs, {Iterable<String>? args, String? name, String? workingDirectory, Map<String, String>? environment, bool includeParentEnvironment = true, bool runInShell = false}) Stream<String>
Runs an executable and returns a stream of lines it prints to stdout.
ls(String glob, {String? root}) Stream<String>
Returns a stream of all paths on disk matching glob.
output(String executableAndArgs, {Iterable<String>? args, String? name, String? workingDirectory, Map<String, String>? environment, bool includeParentEnvironment = true, bool runInShell = false}) Future<String>
Runs an executable and returns its stdout, with trailing newlines removed.
read(String path) Stream<List<int>>
A shorthand for opening the file at path as a stream.
readWithSpans(String path) Stream<Tuple2<String, SourceSpanWithContext>>
Like read, but includes source span information for each line in path that can be used to provide better error messages and easier debugging.
replace(String regexp, String replacement, {bool all = false, bool caseSensitive = true, bool unicode = false, bool dotAll = false}) StreamTransformer<String, String>
Returns a transformer that replaces matches of regexp with replacement.
replaceMapped(String regexp, String replace(Match match), {bool all = false, bool caseSensitive = true, bool unicode = false, bool dotAll = false}) StreamTransformer<String, String>
Returns a transformer that replaces matches of regexp with the result of calling replace.
run(String executableAndArgs, {Iterable<String>? args, String? name, String? workingDirectory, Map<String, String>? environment, bool includeParentEnvironment = true, bool runInShell = false}) Future<void>
Runs an executable for its side effects.
silenceOutput<T>(T callback()) → T
Runs callback and silences all stdout and stderr emitted by Scripts or calls to print within it.
silenceStderr<T>(T callback()) → T
Runs callback and silences all stderr emitted by Scripts.
silenceStdout<T>(T callback()) → T
Runs callback and silences all stdout emitted by Scripts or calls to print within it.
silenceUntilFailure(FutureOr<void> callback(Stream<List<int>> stdin), {String? name, bool? when, bool stderrOnly = false, bool onSignal(ProcessSignal signal)?}) Script
Runs callback in a Script.capture block and silences all stdout and stderr emitted by Scripts or calls to print within it until the callback produces an error.
withEnv<T>(T callback(), Map<String, String?> environment, {bool includeParentEnvironment = true}) → T
Runs callback in a zone with its own environment variables.
withTempDir<T>(T callback(String dir), {String? prefix, String? suffix, String? parent}) → T
Creates a unique temporary directory, passes it to callback and deletes it and its contents after callback finishes.
withTempDirAsync<T>(FutureOr<T> callback(String dir), {String? prefix, String? suffix, String? parent}) Future<T>
Like withTempDir, but creates and deletes the temporary directory asynchronously.
withTempPath<T>(T callback(String path), {String? prefix, String? suffix, String? parent}) → T
Generates a unique temporary path name, passes it to callback, and deletes it after callback finishes.
withTempPathAsync<T>(FutureOr<T> callback(String path), {String? prefix, String? suffix, String? parent}) Future<T>
Like withTempPath, but deletes the temporary path asynchronously.
wrapMain(FutureOr<void> callback(), {bool chainStackTraces = true, bool? printScriptException, bool verboseTrace = false, bool debug = false}) → void
A wrapper for the body of the top-level main() method.
write(String path) IOSink
A shorthand for opening a sink that writes to the file at path.
xargs(FutureOr<void> callback(List<String> args), {int? maxArgs, String? name, void onSignal(ProcessSignal signal)?}) Script
Executes callback with arguments from standard input.

Exceptions / Errors

ScriptException
An exception indicating that a Script failed.