append function

IOSink append(
  1. String path
)

A shorthand for opening a sink that appends to the file at path.

With Script.operator >, this can be used to append the output of a script to a file:

import 'dart:io';

import 'package:cli_script/cli_script.dart';

void main() {
  wrapMain(() {
    Script.capture((_) async {
      await for (var file in lines("find . -type f -maxdepth 1")) {
        var contents = await output("cat", args: [file]);
        if (contents.contains("needle")) print(file);
      }
    }) > append("needles.txt");
  });
}

Implementation

IOSink append(String path) => File(path).openWrite(mode: FileMode.append);