checkForAlreadyExists method

void checkForAlreadyExists(
  1. String? name
)

Implementation

void checkForAlreadyExists(String? name) {
  var newFileModel =
      Structure.model(name, 'page', true, on: onCommand, folderName: name);
  var pathSplit = Structure.safeSplitPath(newFileModel.path!);

  pathSplit.removeLast();
  var path = pathSplit.join('/');
  path = Structure.replaceAsExpected(path: path);
  if (Directory(path).existsSync()) {
    final menu = Menu(
      [
        LocaleKeys.options_yes.tr,
        LocaleKeys.options_no.tr,
        LocaleKeys.options_rename.tr,
      ],
      title:
          Translation(LocaleKeys.ask_existing_page.trArgs([name])).toString(),
    );
    final result = menu.choose();
    if (result.index == 0) {
      _writeFiles(path, name!, overwrite: true);
    } else if (result.index == 2) {
      // final dialog = CLI_Dialog();
      // dialog.addQuestion(LocaleKeys.ask_new_page_name.tr, 'name');
      // name = dialog.ask()['name'] as String?;
      var name = ask(LocaleKeys.ask_new_page_name.tr);
      checkForAlreadyExists(name.trim().snakeCase);
    }
  } else {
    Directory(path).createSync(recursive: true);
    _writeFiles(path, name!, overwrite: false);
  }
}