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 {
  if (await ConfigUtils.doesConfigExist()) {
    throw Exception("Config already exists!");
  }

  final config = ConfigUtils.createConfig();

  final configFile = await File("./glacier.yaml").create();
  await configFile.writeAsString(config.toString());

  final srcDirectory = await Directory(config.sourceDirectory).create();

  final exampleFile = await File(path.join(srcDirectory.absolute.path, "index.md")).create();
  await exampleFile.writeAsString(_getConfigMdContent(config));

  final baseDirectory = await Directory(config.baseDirectory).create();

  final baseArg = argResults!["template"] as String;

  // Get the firt 2 parts of the string as this is the repo name and author e.g. nyxx-discord/glacier
  final repoName = baseArg.split("/").sublist(0, 2).join("/");
  // Gets the rest of the repo path, could be simplifed with another options?
  final repoPath = baseArg.split("/").sublist(2).join("/");

  await downloadTemplate(repoName, repoPath, baseDirectory);

  print("Cloned template files into ${baseDirectory.path}");

  return 0;
}