cmdRunner function

FtRunner cmdRunner(
  1. List<String> args
)

filetool run

Implementation

FtRunner cmdRunner(List<String> args) {
  final verbose = args.contains('-v') || args.contains('--verbose');

  final cliAnsi = CliAnsi(Ansi.terminalSupportsAnsi);
  final logger = verbose
      ? CliVerboseLogger(ansi: cliAnsi)
      : CliStandardLogger(ansi: cliAnsi);

  final ftRun = FtRunner("ft", "FileTools: cross-platform glob & streams. \n")
    ..ftVerbose = verbose
    ..ftLogger = logger;

  // ignore: unused_local_variable
  final parser = ftRun.argParser
    ..addFlag(
      'verbose',
      abbr: 'v',
      negatable: false,
      help: 'Show additional command output.',
    )
    ..addFlag(
      'version',
      negatable: false,
      help: 'Print the tool version.',
    )
    ..addOption(
      'source',
      valueHelp: 'path',
      help: 'Specify the source (file|directory)',
    )
    ..addOption(
      'config',
      valueHelp: 'file',
      help: 'Loads a config file for variable referencing',
    )
    ..addOption(
      'config_txt',
      valueHelp: 'yaml',
      help: 'Loads a yaml text for variable referencing',
    )
    ..addFlag(
      'config_gen',
      negatable: false,
      defaultsTo: false,
      help: 'Generate a custom config on curdir.',
    )
    ..addFlag(
      'errexit',
      negatable: true,
      defaultsTo: true,
      help: 'exit on error.',
    )
    ..addMultiOption(
      'define',
      help: 'Define or override a variable from command line',
    )
    ..addOption(
      'pattern',
      defaultsTo: '**',
      help: 'Glob pattern',
    )
    ..addMultiOption(
      'excludes',
      help: "Glob pattern after exclusion (e.g. --excludes='.**')",
    )
    ..addMultiOption(
      'fields',
      help: "show fields (ok, action, type, mime, perm, time, size, extra)",
    )
    ..addOption(
      'size_le',
      help: 'file size less than (in bytes, unit:B|K|M|G|T|P)',
    )
    ..addOption(
      'size_ge',
      help: 'file size greater than (in bytes, unit:B|K|M|G|T|P)',
    )
    ..addOption(
      'time_le',
      help: 'file time before (yyyyMMddTHHmmss | yyyyMMdd)',
    )
    ..addOption(
      'time_ge',
      help: 'file time after (yyyyMMddTHHmmss | yyyyMMdd)',
    )
    ..addOption(
      'time_type',
      defaultsTo: 'modified',
      allowed: StatTimeType.values.asNameMap().keys.toList(),
      allowedHelp: {
        'changed': 'ctime - change time',
        'modified': 'mtime - modification time',
        'accessed': 'atime - access time',
      },
      valueHelp: 'modified',
      help: 'file time type (changed | modified | accessed)',
    );

  ftRun
    ..addCommand(ListCommand())
    ..addCommand(SearchCommand())
    ..addCommand(MirrorCommand())
    ..addCommand(CleanCommand())
    ..addCommand(WipeCommand())
    ..addCommand(RmDirCommand())
    ..addCommand(FdupsCommand())
    ..addCommand(ArchiveCommand())
    ..addCommand(UnArchiveCommand())
    ..addCommand(ExecuteCommand())
    ..addCommand(ShellCommand());

  return ftRun;
}