run method

  1. @override
Future<int> run()
override

Runs this command.

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

Implementation

@override
Future<int> run() async {
  final root = await projectRoot();

  if (root == null) {
    logger.err('Could not find project root');
    return 1;
  }

  final content = createExampleContent();

  final file = fileSystem.file(fileSystem.path.join(root, 'barreler.yaml'));

  if (await file.exists()) {
    final eraseFile = await logger.confirm(
      'The barreler config file already exists, do you want to overwrite it?',
    );

    if (!eraseFile) {
      logger.info('Aborted');
      return 0;
    }
  }

  final done = logger.progress('Creating barreler.yaml');

  try {
    await file.writeAsString(content);

    done.complete('barreler.yaml created');
  } catch (e) {
    done.fail('Failed to create barreler.yaml');
    logger.err(e.toString());

    return 1;
  }

  return 0;
}