import * as AeroflyFlightFormatter from "../../core/formatter/AeroflyFlightFormatter.js"; import { writeln, writeSuccess, writeCatch } from "../formatter/writeCli.js"; import { ControllerCommand } from "./Command.js"; import { input } from "@inquirer/prompts"; export class SimbriefCommand extends ControllerCommand { async execute(): Promise { let returnState = 0; let simBriefUserName = this.controller.config.simBriefUserName; if (simBriefUserName === undefined || simBriefUserName.trim() === "") { simBriefUserName = await input({ message: "SimBrief username (for flightplan import)", default: simBriefUserName, required: true, validate(value) { if (!/^[a-zA-Z0-9_]+$/.test(value)) { return "Please enter a valid SimBrief username (alphanumeric and underscores only)"; } return true; }, }); this.controller.config.simBriefUserName = simBriefUserName; } writeln(`Importing flightplan from SimBrief for user ${simBriefUserName}...`); try { await this.controller.importFlightplanFromSimBrief( simBriefUserName, this.controller.config.useSimBriefWeather, ); writeSuccess("Flightplan imported successfully"); writeln( `Imported flightplan: ${AeroflyFlightFormatter.getFlightplanWaypoints(this.controller.getAeroflyFlight())}`, ); } catch (error) { writeCatch(error); returnState = 1; } return returnState; } }