also looking at this
feat: run configured modeled cargo delivery and phase failures
#97
38 files
+2114
-30
| @@ -0,0 +1,25 @@ | ||
| 1 | import { defineCommand } from '@stacksjs/cli' | |
| 2 | import { printAsync, printErrorAsync } from '../../resources/functions/cli/output' | |
| 3 | import { cargoDeliveryScenarios, cargoDeliverySummary, simulateCargoDelivery } from '../../resources/functions/drone/cargo/delivery' | |
| 4 | import { readMissionFile } from '../../resources/functions/drone/missions/files' | |
| 5 | ||
| 6 | export default defineCommand({ | |
| 7 | name: 'cargo:mission <request>', | |
| 8 | description: 'Execute an explicitly configured modeled cargo mission without physical dispatch', | |
| 9 | options: { | |
| 10 | '--scenario <name>': { description: cargoDeliveryScenarios.join(', '), default: 'nominal' }, | |
| 11 | }, | |
| 12 | async handle(options, path) { | |
| 13 | try { | |
| 14 | const input = await readMissionFile(path, { maxBytes: 16384, preserveBom: true }) | |
| 15 | const summary = cargoDeliverySummary(simulateCargoDelivery({ configuration: JSON.parse(input), scenario: options.scenario })) | |
| 16 | if (!summary.demonstrationMatched || summary.status !== 'completed' || summary.delivery.outcome !== 'received' || !summary.landingContact) process.exitCode = 2 | |
| 17 | await printAsync(JSON.stringify(summary)) | |
| 18 | } | |
| 19 | catch { | |
| 20 | process.exitCode = 1 | |
| 21 | try { await printErrorAsync('Cargo mission simulation unavailable: invalid declaration, rejected route or output failure') } | |
| 22 | catch { /* Failed output remains failure even if its diagnostic pipe is closed. */ } | |
| 23 | } | |
| 24 | }, | |
| 25 | }) | |