Made essential command toggle essential status

This commit is contained in:
Kallum Jones 2022-08-04 16:17:57 +01:00
parent e808a4f414
commit 935262ec0f
No known key found for this signature in database
GPG Key ID: D7F4589C4D7F81A9
2 changed files with 11 additions and 8 deletions

View File

@ -6,12 +6,12 @@ import Mods from "../mods/mods.js";
export default class EssentialCommand implements Subcommand { export default class EssentialCommand implements Subcommand {
registerCommand(program: Command): void { registerCommand(program: Command): void {
program.command("essential") program.command("essential")
.description("Marks mods as essential") .description("Toggles the mods essential statuses")
.argument("<mods...>", "The mods to mark as essential (as names or ids)") .argument("<mods...>", "The mods to toggle the essential status of (as names or ids)")
.action((mods) => { .action((mods) => {
ModManager.execute(() => { ModManager.execute(() => {
for (let mod of mods) { for (let mod of mods) {
Mods.markEssential(mod) Mods.toggleEssential(mod)
} }
}) })
}) })

View File

@ -119,7 +119,7 @@ export default class Mods {
return mod1.id === mod2.id; return mod1.id === mod2.id;
} }
static markEssential(mod: string) { static toggleEssential(mod: string) {
const modToMark = this.findMod(mod); const modToMark = this.findMod(mod);
if (modToMark != undefined) { if (modToMark != undefined) {
@ -127,13 +127,16 @@ export default class Mods {
// Remove mod from list // Remove mod from list
mods = mods.filter(item => !Mods.areModsEqual(item, modToMark)); mods = mods.filter(item => !Mods.areModsEqual(item, modToMark));
// Mark is as essential, and read it // Toggle essnetial status, and write back to file
modToMark.essential = true; modToMark.essential = !modToMark.essential;
mods.push(modToMark) mods.push(modToMark)
this.writeFile(mods); this.writeFile(mods);
PrintUtils.success(`Marked ${modToMark.name} as essential`) if (modToMark.essential) {
PrintUtils.success(`Marked ${modToMark.name} as essential`)
} else {
PrintUtils.success(`Marked ${modToMark.name} as inessential`)
}
} else { } else {
PrintUtils.error(`${mod} not found.`) PrintUtils.error(`${mod} not found.`)
} }