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() async {
  List<String> args = argResults!.rest;

  showUsage(args.length != 2, () => printUsage());

  final oldPath = args[0];
  final newPath = args[1];

  final run = Run();
  final copied = await run.copy(
    oldPath,
    newPath,
    sudo: argResults!['sudo'],
    recursive: argResults!['recursive'],
    force: argResults!['force'],
    preserve: argResults!['preserve'],
  );

  final file = File(newPath);
  if (!copied || !file.existsSync()) {
    out("{@red}File '$newPath' not found{@end}");
    exit(unableToOpenOutputFile);
  }

  if (argResults!['verbose']) {
    out("{@green}File copied to '$newPath'{@end}");
  }

  print(file.absolute.path);
  exit(success);
}