server_universeDartCli function
ServerUniverseUncompleteDocumentation
Implementation
Future<void> server_universeDartCli(List<String> args_raw) async {
ServerUniverseApi serverUniverseApi = ServerUniverseApi();
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",
"init",
"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);
}
}
ServerUniverseBuildType server_universeDartBuildType =
ServerUniverseBuildType.release;
if (args.contains("--debug")) {
server_universeDartBuildType = ServerUniverseBuildType.debug;
}
if (args.contains("-d")) {
server_universeDartBuildType = ServerUniverseBuildType.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 serverUniverseApi
.create(newName: new_project_name, directoryBase: directory_current)
.listen((event) {
printed(event);
}).asFuture();
exit(0);
}
if (["run", "build"].contains(command)) {
ServerUniversePlatformType? server_universeDartPlatformType =
await Future(() async {
String platform_type = (args.after(command) ?? "").toLowerCase();
List<ServerUniversePlatformType> server_universeDartPlatformTypes =
ServerUniversePlatformType.values.toList();
server_universeDartPlatformTypes.sort((a, b) => a.name.compareTo(b.name));
for (ServerUniversePlatformType server_universeDartPlatformType
in server_universeDartPlatformTypes) {
if (server_universeDartPlatformType.name.toLowerCase() ==
platform_type) {
return server_universeDartPlatformType;
}
}
if (is_interactive) {
while (true) {
await Future.delayed(Duration(microseconds: 1));
ServerUniversePlatformType server_universeDartPlatformType =
logger.chooseOne(
"Pilih Platform: ",
choices: server_universeDartPlatformTypes,
display: (choice) {
return choice.name.toLowerCase();
},
);
return server_universeDartPlatformType;
}
}
// ignore: dead_code
return null;
});
if (server_universeDartPlatformType == null) {
print(
"Please select platform type: ${ServerUniversePlatformType.values.map((e) => e.name).join(", ")}");
exit(1);
}
Directory directory_current = Directory.current;
if ([
"build",
"run",
"deploy",
].contains(command)) {
String? inputFileName = () {
String input = (args.after("-i") ?? args.after("--input") ?? "").trim();
if (input.isNotEmpty) {
return input;
}
return null;
}();
Directory? directoryOutputBuildServerUniverse = () {
String output =
(args.after("-o") ?? args.after("--output") ?? "").trim();
if (output.isNotEmpty) {
return Directory(output);
}
return null;
}();
await serverUniverseApi
.build(
directoryBase: directory_current,
inputFileName: inputFileName,
directoryOutputBuildServerUniverse:
directoryOutputBuildServerUniverse,
server_universeDartBuildType: server_universeDartBuildType,
server_universeDartPlatformType: server_universeDartPlatformType)
.listen((event) {
printed(event);
}).asFuture();
if (command == "build") {
print("Finished");
exit(0);
}
if (command == "run") {
logger
.info("Starting running: ${server_universeDartPlatformType.name}");
int exit_code = await serverUniverseApi.run(
directoryBase: directory_current,
inputFileName: inputFileName,
directoryOutputBuildServerUniverse:
directoryOutputBuildServerUniverse,
server_universeDartBuildType: server_universeDartBuildType,
server_universeDartPlatformType: server_universeDartPlatformType,
onBuild: (serverUniverseApiStatus) {
printed(serverUniverseApiStatus);
},
);
exit(exit_code);
}
}
}
exit(1);
}