execute method

  1. @override
Future<int> execute(
  1. List<String> arguments
)
override

Implementation

@override
Future<int> execute(List<String> arguments) async {
  final parsed = _parse(arguments);
  if (parsed == null) return ExitCode.usage;

  final relativePath = pathFor(parsed.name);
  final file = File('${workingDirectory.path}/$relativePath');
  if (file.existsSync() && !parsed.force) {
    Console.error('$label already exists at $relativePath.');
    Console.line(Console.dim('Pass --force to overwrite it.'));
    return ExitCode.failure;
  }

  await file.create(recursive: true);
  await file.writeAsString(render(parsed.name, [parsed.name]));
  Console.success('$label created at ${Console.cyan(relativePath)}');
  return ExitCode.success;
}