list method

Stream<Es> list({
  1. bool matched = true,
  2. FileSystemEntityType fseType = FileSystemEntityType.file,
})

list source path.

  • matched: Show all matches if enabled, otherwise, show non-matches.
  • fseType: match type (file, directory, link).
final excludes = [r'.**'];
final source = '.';
final action = BasicPathAction(source, excludes: excludes);

action.list();

Implementation

Stream<Es> list({
  // String renAction = 'list',
  bool matched = true,
  FileSystemEntityType fseType = FileSystemEntityType.file,
}) {
  final action = PathAction.list.name, chk = 'validator';
  argErr ??= validator();
  if (argErr!.isNotEmpty) throw ArgumentError.value(argErr, action, chk);

  final fields = fieldsFromOptions(
    matched ? fmtFields : [FormatField.extra.toString(), ...fmtFields],
  );

  final stream = matched ? scEntity.stream : scFilted.stream;
  final fStream =
      stream.where((event) => event.fs.type == fseType).asBroadcastStream();

  late StreamSubscription subs;
  subs = fStream.listen(
    (event) {
      final (entity, stat, extra) = event.asRecord;
      final ok = stat.type == FileSystemEntityType.notFound ? false : true;
      final line =
          Formatter(entity, stat, extra, action, shows: fields, ok: ok);
      logger.stdout(line.toString());
    },
    cancelOnError: cancelOnError,
    onDone: () => logger.trace('d, $action, done.'),
    onError: (e, s) {
      if (cancelOnError) {
        exitCode = ExitCodeExt.error.code;
        subs.cancel();
      }

      logger
        ..trace('d, $action, cancelOnError:$cancelOnError')
        ..stderr('e, $action, error. $e')
        ..stderr(kIsDebug ? '$s' : '');
    },
  );
  return fStream;
}