|
| 1 | +import { SudoRequestData, SudoRequestResponseData } from 'codify-schemas'; |
| 2 | + |
| 3 | +import { Plan } from '../../entities/plan.js'; |
| 4 | +import { ResourceConfig } from '../../entities/resource-config.js'; |
| 5 | +import { ResourceInfo } from '../../entities/resource-info.js'; |
| 6 | +import { ImportResult } from '../../orchestrators/import.js'; |
| 7 | +import { FileModificationResult } from '../../utils/file-modification-calculator.js'; |
| 8 | +import { PromptType, Reporter } from './reporter.js'; |
| 9 | + |
| 10 | +export class JsonReporter implements Reporter { |
| 11 | + displayPlan(plan: Plan): void { |
| 12 | + console.log(JSON.stringify(plan.resources.map((r) => r.raw), null, 2)); |
| 13 | + } |
| 14 | + |
| 15 | + async displayInitBanner(): Promise<void> {} |
| 16 | + |
| 17 | + async displayProgress(): Promise<void> {} |
| 18 | + |
| 19 | + async hide(): Promise<void> {} |
| 20 | + |
| 21 | + async promptInitResultSelection(availableTypes: string[]): Promise<string[]> { |
| 22 | + return availableTypes; |
| 23 | + } |
| 24 | + |
| 25 | + async promptInput(prompt: string, error?: string | undefined, validation?: (() => Promise<boolean>) | undefined, autoComplete?: ((input: string) => string[]) | undefined): Promise<string> { |
| 26 | + throw new Error(`Json reporter error: user input is required for prompt: ${prompt}. The Json reporter doesn't support user input. Make sure to have parameters preconfigured`); |
| 27 | + } |
| 28 | + |
| 29 | + async promptConfirmation(message: string): Promise<boolean> { |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + async promptOptions(message: string, options: string[]): Promise<number> { |
| 34 | + throw new Error('Json reporter error: this reporter does not support prompting options. Use another reporter.') |
| 35 | + } |
| 36 | + |
| 37 | + async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> { |
| 38 | + throw new Error(`Json reporter error: sudo required for command: ${data.command}. Make sure to preconfigure the sudo password for the Json reporter`); |
| 39 | + } |
| 40 | + |
| 41 | + async promptUserForValues(resources: ResourceInfo[], promptType: PromptType): Promise<ResourceConfig[]> { |
| 42 | + throw new Error('Json reporter error: cannot prompt user for values while using Json reporter. Use a different reporter.'); |
| 43 | + } |
| 44 | + |
| 45 | + async displayImportResult(importResult: ImportResult, showConfigs: boolean): void { |
| 46 | + console.log(JSON.stringify(importResult.result.map((r) => r.raw))); |
| 47 | + } |
| 48 | + |
| 49 | + async displayFileModifications(diff: { file: string; modification: FileModificationResult; }[]): void {} |
| 50 | + |
| 51 | + displayMessage(message: string): void {} |
| 52 | + |
| 53 | + async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {} |
| 54 | +} |
0 commit comments