diff --git a/packages/ctl/src/commands.js b/packages/ctl/src/commands.js index 70644707..c5f3fe9d 100644 --- a/packages/ctl/src/commands.js +++ b/packages/ctl/src/commands.js @@ -1004,6 +1004,30 @@ modPackCommands.add(new libCommand.Command({ }, })); +modPackCommands.add(new libCommand.Command({ + definition: ["import ", "Import mod pack string", (yargs) => { + yargs.positional("string", { describe: "Mod pack string to import", type: "string" }); + }], + handler: async function(args, control) { + const modPack = libData.ModPack.fromModPackString(args.string); + await libLink.messages.createModPack.send(control, { mod_pack: modPack.toJSON() }); + print(`Created mod pack ${modPack.name} (${modPack.id})`); + }, +})); + +modPackCommands.add(new libCommand.Command({ + definition: ["export ", "Export mod pack string", (yargs) => { + yargs.positional("string", { describe: "Mod pack to export", type: "string" }); + }], + handler: async function(args, control) { + const response = await libLink.messages.getModPack.send(control, { + id: await libCommand.resolveModPack(control, args.modPack), + }); + const modPack = new libData.ModPack(response.mod_pack); + print(modPack.toModPackString()); + }, +})); + modPackCommands.add(new libCommand.Command({ definition: ["edit ", "Edit mod pack", (yargs) => { yargs.positional("mod-pack", { describe: "Mod pack to remove from", type: "string" }); diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index b54d9390..e5da8157 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -866,6 +866,25 @@ describe("Integration of Clusterio", function() { }); }); + describe("mod-pack import/export", function() { + it("should should roundtrip a mod-pack", async function() { + let reference = new libData.ModPack(); + reference.name = "imported-pack"; + reference.description = "Description"; + reference.factorioVersion = "0.17.59"; + reference.mods.set("empty_mod", { name: "empty_mod", enabled: true, version: "1.0.0" }); + reference.settings["startup"].set("MyBool", { value: true }); + reference.settings["runtime-global"].set("MyInt", { value: 1235 }); + reference.settings["runtime-global"].set("MyDouble", { value: 12.25 }); + reference.settings["runtime-per-user"].set("MyString", { value: "a-string" }); + await execCtl(`mod-pack import ${reference.toModPackString()}`); + const result = await execCtl("mod-pack export imported-pack"); + const roundtrip = libData.ModPack.fromModPackString(result.stdout.trim()); + roundtrip.id = reference.id; + assert.deepEqual(roundtrip, reference); + }); + }); + describe("mod-pack edit", function() { it("runs", async function() { await execCtl("mod-pack edit full-pack --factorio-version 1.2.0");