packageFullTemplateDartCli function

Future<void> packageFullTemplateDartCli(
  1. List<String> args_raw
)

Implementation

Future<void> packageFullTemplateDartCli(List<String> args_raw) async {
  NotifDartApi packageFullTemplateDartApi = NotifDartApi();
  Args args = Args(args_raw);

  bool is_interactive = true;
  if (Platform.environment["no_interactive"] == "true") {
    is_interactive = false;
  }

  String command = (args.arguments.firstOrNull ?? "").toLowerCase();
  List<String> commands = [
    "build",
    "create",
    "deploy",
    "run",
  ];
  commands.sort();
  if (commands.contains(command) == false) {
    if (is_interactive) {
      command = logger.chooseOne(
        "Pilih",
        choices: commands,
        display: (choice) {
          return choice.toUpperCaseFirstData();
        },
      );
    } else {
      print("Please use command: ${commands.join("\n")}");
      exit(1);
    }
  }

  NotifDartBuildType server_universeDartBuildType = NotifDartBuildType.release;

  if (args.contains("--debug")) {
    server_universeDartBuildType = NotifDartBuildType.debug;
  }

  if (args.contains("-d")) {
    server_universeDartBuildType = NotifDartBuildType.debug;
  }

  if (command == "create") {
    Directory directory_current = Directory.current;
    String new_project_name = await Future(() async {
      String new_project_name_from_command = (args.after(command) ?? "").toLowerCase();
      if (new_project_name_from_command.isNotEmpty) {
        return new_project_name_from_command;
      }
      if (is_interactive) {
        while (true) {
          await Future.delayed(Duration(microseconds: 1));
          String server_universeDartPlatformType = logger.prompt(
            "Name New Project: ",
          );

          if (server_universeDartPlatformType.isNotEmpty) {
            return server_universeDartPlatformType;
          }
        }
      }
      return "";
    });
    if (new_project_name.isEmpty) {
      print("Failed");
      exit(1);
    }
    await packageFullTemplateDartApi.create(
      newName: new_project_name,
      directoryBase: directory_current,
    );
  }
  exit(1);
}