mirror of
https://git.bits.team/Bits/mod-manager.git
synced 2024-11-21 13:38:21 -05:00
Use built in validation for getting MC version
This commit is contained in:
parent
90b5ac79bc
commit
76f6c2c475
@ -3,7 +3,6 @@ import axios from "axios";
|
|||||||
import ModManager from "../mod-manager.js";
|
import ModManager from "../mod-manager.js";
|
||||||
import MinecraftVersionError from "../errors/minecraft_version_error.js";
|
import MinecraftVersionError from "../errors/minecraft_version_error.js";
|
||||||
import inquirer from "inquirer";
|
import inquirer from "inquirer";
|
||||||
import PrintUtils from "./print_utils.js";
|
|
||||||
|
|
||||||
export default class MinecraftUtils {
|
export default class MinecraftUtils {
|
||||||
static async getCurrentMinecraftVersion(): Promise<string> {
|
static async getCurrentMinecraftVersion(): Promise<string> {
|
||||||
@ -37,29 +36,19 @@ export default class MinecraftUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getMinecraftVersionFromInput(question: string) {
|
public static async getMinecraftVersionFromInput(question: string) {
|
||||||
let isVersionValid = false;
|
const answer = await inquirer.prompt([{
|
||||||
|
type: "input",
|
||||||
let version: string | undefined = undefined;
|
name: "minecraft_version",
|
||||||
while (!isVersionValid) {
|
message: question,
|
||||||
const answer = await inquirer.prompt([{
|
async validate(input: any): Promise<string | boolean> {
|
||||||
type: "input",
|
const valid = await MinecraftUtils.isValidVersion(input);
|
||||||
name: "minecraft_version",
|
if (!valid) {
|
||||||
message: question
|
return "That is not a valid Minecraft Version"
|
||||||
}])
|
}
|
||||||
version = answer.minecraft_version;
|
return valid
|
||||||
|
},
|
||||||
if (await MinecraftUtils.isValidVersion(version)) {
|
}])
|
||||||
isVersionValid = true;
|
return answer.minecraft_version;
|
||||||
} else {
|
|
||||||
PrintUtils.error(`${version} is not a valid Minecraft version for a Fabric server. Please try again`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version == undefined) {
|
|
||||||
throw new MinecraftVersionError("Escaped version input without a valid version")
|
|
||||||
}
|
|
||||||
|
|
||||||
return version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user