@hangtime/grip-connect-cli
Version:
CLI tool for Grip Connect devices
37 lines • 1.54 kB
JavaScript
/**
* `grip-connect download [device]` -- exports session data to a file.
*/
import { resolveDeviceKey, createDevice, connectAndRun, resolveContext, printSuccess, fail } from "../utils.js";
/**
* Registers the `download` command on the Commander program.
*
* @param program - The root Commander program.
*/
export function registerDownload(program) {
program
.command("download [device]")
.description("Connect and export session data")
.option("-f, --format <format>", "Export format: csv, json, xml", "csv")
.option("-o, --output <dir>", "Output directory for the exported file")
.action(async (deviceKey, options) => {
const ctx = resolveContext(program);
const format = options.format.toLowerCase();
if (!["csv", "json", "xml"].includes(format)) {
fail("Format must be csv, json, or xml.");
}
const key = await resolveDeviceKey(deviceKey);
const { device, name } = createDevice(key);
await connectAndRun(device, name, async (d) => {
if (typeof d.download !== "function") {
fail("Download not supported on this device.");
}
const filePath = await d.download(format);
if (!ctx.json) {
printSuccess(typeof filePath === "string"
? `Session data exported to ${filePath}`
: `Session data exported as ${format.toUpperCase()}.`);
}
}, ctx);
});
}
//# sourceMappingURL=download.js.map