cli_script
library
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 Script s or
calls to print within it.
silenceStderr <T > (T callback () )
→ T
Runs callback
and silences all stderr emitted by Script s.
silenceStdout <T > (T callback () )
→ T
Runs callback
and silences all stdout emitted by Script s 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 Script s 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.