Skip to content

Commit 42e5508

Browse files
committed
fix: additional reporters
1 parent c7723cb commit 42e5508

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

src/ui/reporters/json-reporter.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
import { SudoRequestData, SudoRequestResponseData } from 'codify-schemas';
1+
import { SudoRequestData } from 'codify-schemas';
22

33
import { Plan } from '../../entities/plan.js';
44
import { ResourceConfig } from '../../entities/resource-config.js';
5-
import { ResourceInfo } from '../../entities/resource-info.js';
65
import { ImportResult } from '../../orchestrators/import.js';
7-
import { FileModificationResult } from '../../utils/file-modification-calculator.js';
8-
import { PromptType, Reporter } from './reporter.js';
6+
import { Reporter } from './reporter.js';
97

108
export class JsonReporter implements Reporter {
11-
displayPlan(plan: Plan): void {
12-
console.log(JSON.stringify(plan.resources.map((r) => r.raw), null, 2));
13-
}
9+
displayPlan(plan: Plan): void {
10+
console.log(JSON.stringify(plan.resources.map((r) => r.raw), null, 2));
11+
}
12+
13+
promptPressKeyToContinue(message?: string): Promise<void> {
14+
throw new Error(`Press key to continue is not supported by the JsonReporter.
15+
16+
${message}`)
17+
}
1418

15-
async displayInitBanner(): Promise<void> {}
19+
async displayInitBanner(): Promise<void> {}
1620

1721
async displayProgress(): Promise<void> {}
1822

@@ -22,33 +26,33 @@ export class JsonReporter implements Reporter {
2226
return availableTypes;
2327
}
2428

25-
async promptInput(prompt: string, error?: string | undefined, validation?: (() => Promise<boolean>) | undefined, autoComplete?: ((input: string) => string[]) | undefined): Promise<string> {
29+
async promptInput(prompt: string): Promise<string> {
2630
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`);
2731
}
2832

29-
async promptConfirmation(message: string): Promise<boolean> {
33+
async promptConfirmation(): Promise<boolean> {
3034
return true;
3135
}
3236

33-
async promptOptions(message: string, options: string[]): Promise<number> {
37+
async promptOptions(): Promise<number> {
3438
throw new Error('Json reporter error: this reporter does not support prompting options. Use another reporter.')
3539
}
3640

37-
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
41+
async promptSudo(pluginName: string, data: SudoRequestData): Promise<string | undefined> {
3842
throw new Error(`Json reporter error: sudo required for command: ${data.command}. Make sure to preconfigure the sudo password for the Json reporter using --sudoPassword`);
3943
}
4044

41-
async promptUserForValues(resources: ResourceInfo[], promptType: PromptType): Promise<ResourceConfig[]> {
45+
async promptUserForValues(): Promise<ResourceConfig[]> {
4246
throw new Error('Json reporter error: cannot prompt user for values while using Json reporter. Use a different reporter.');
4347
}
4448

45-
async displayImportResult(importResult: ImportResult, showConfigs: boolean): void {
49+
async displayImportResult(importResult: ImportResult): Promise<void> {
4650
console.log(JSON.stringify(importResult.result.map((r) => r.raw)));
4751
}
4852

49-
async displayFileModifications(diff: { file: string; modification: FileModificationResult; }[]): void {}
53+
async displayFileModifications(): Promise<void> {}
5054

51-
displayMessage(message: string): void {}
55+
displayMessage(): void {}
5256

53-
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {}
57+
async displayImportWarning(): Promise<void> {}
5458
}

src/ui/reporters/plain-reporter.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import chalk from 'chalk';
2-
import { SudoRequestData, SudoRequestResponseData } from 'codify-schemas';
2+
import { SudoRequestData } from 'codify-schemas';
33
import readline from 'node:readline';
44

55
import { Plan } from '../../entities/plan.js';
@@ -8,7 +8,6 @@ import { ResourceInfo } from '../../entities/resource-info.js';
88
import { Event, ctx } from '../../events/context.js';
99
import { ImportResult } from '../../orchestrators/import.js';
1010
import { FileModificationResult } from '../../utils/file-modification-calculator.js';
11-
import { SudoUtils } from '../../utils/sudo.js';
1211
import { prettyFormatPlan } from '../plan-pretty-printer.js';
1312
import { PromptType, Reporter } from './reporter.js';
1413

@@ -25,9 +24,21 @@ export class PlainReporter implements Reporter {
2524
}
2625
}
2726

27+
promptPressKeyToContinue(message?: string | undefined): Promise<void> {
28+
console.log(message);
29+
console.log(chalk.dim.gray('<press any key to continue>'))
30+
process.stdin.setRawMode(true)
31+
return new Promise((resolve) => {
32+
process.stdin.once('data', () => {
33+
process.stdin.setRawMode(false)
34+
resolve()
35+
})
36+
})
37+
}
38+
2839
async hide(): Promise<void> {}
2940

30-
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {
41+
async displayImportWarning(): Promise<void> {
3142
console.log(chalk.bold('Additional information is required to continue import'))
3243
console.log('Some of the resources specified in the import support multiple instances. Additional information is required to identify the specific instance to import. If importing multiple instances is desired (for ex: multiple git clones) additional imports can be added in the prompt.')
3344
}

0 commit comments

Comments
 (0)