run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() {
  final ftRun = runner as FtRunner;
  final v = ftRun.ftVerbose;
  final logger = ftRun.ftLogger;

  late final String source;
  late final String type;
  late final bool matched;
  try {
    final args = globalResults?.arguments ?? [];
    final config = configFromArgParse(ftRun.argParser, args);
    final define = getDefine(config, globalResults);
    final env = {...Platform.environment, ...define};

    ftRun
      ..ftConfig = config
      ..ftDefine = define
      ..ftEnv = env
      ..ftPattern = getOpiton('pattern', config, gRes: globalResults)
      ..ftExcludes = getOpitons('excludes', config, gRes: globalResults)
      ..ftFields = getOpitons('fields', config,
          gRes: globalResults, datalist: fieldNames)
      ..ftSizes = getSizes(config, globalResults)
      ..ftTimes = getTimes(config, globalResults)
      ..ftErrExit =
          getFlag('errexit', config, defaultTo: true, gRes: globalResults)
      ..ftTimeType = getOpiton('time_type', ftRun.ftConfig,
          gRes: globalResults,
          defaultTo: timeTypeDefault,
          datalist: timeTypes);

    source = getSource(ftRun.ftConfig, globalResults,
        aRes: argResults, env: ftRun.ftEnv);
    type = getOpiton('$name.type', ftRun.ftConfig,
        aRes: argResults, defaultTo: typeDefault, datalist: typeNames);
    matched = getFlag('$name.matched', ftRun.ftConfig,
        aRes: argResults, defaultTo: true);
  } on UsageException catch (e, s) {
    logger.stderr('e, $name.run, $e\n $s');
    rethrow;
  } catch (e, s) {
    logger.stderr('e, $name.run, $e\n $s');
    throw UsageException(e.toString(), '');
  }

  if (v) traceGlobalParam(logger, ftRun, source);
  final action = BasicPathAction(
    source,
    pattern: ftRun.ftPattern,
    excludes: ftRun.ftExcludes,
    sizes: ftRun.ftSizes,
    times: ftRun.ftTimes,
    env: ftRun.ftEnv,
    verbose: ftRun.ftVerbose,
    cancelOnError: ftRun.ftErrExit,
    statTimeType: StatTimeType.values.byName(ftRun.ftTimeType),
  )
    ..logger = logger
    ..fmtFields = ftRun.ftFields;

  final err = action.validator();
  if (err.isNotEmpty) throw UsageException('err: chk, $err', '');
  action.argErr = err;

  final fseType = switch (type) {
    'file' => FileSystemEntityType.file,
    'directory' => FileSystemEntityType.directory,
    'link' => FileSystemEntityType.link,
    'unixDomainSock' => FileSystemEntityType.unixDomainSock,
    'pipe' => FileSystemEntityType.pipe,
    _ => FileSystemEntityType.notFound,
  };
  if (v) logger.trace('i, type:$fseType, matched:$matched.');
  action.list(matched: matched, fseType: fseType);

  // end run
}