11import chalk from 'chalk' ;
2- import { CommandRequestData , ResourceOperation } from '@codifycli/schemas' ;
2+ import { CommandRequestData } from '@codifycli/schemas' ;
33import readline from 'node:readline' ;
44
55import { PluginError } from '../../common/errors.js' ;
6- import { ApplyResult , ApplyResultEntry } from '../../entities/apply-result.js' ;
6+ import { ApplyResult } from '../../entities/apply-result.js' ;
77import { Plan } from '../../entities/plan.js' ;
8+ import { applyEntryChalkColor , applyEntryLabel } from '../apply-result-formatter.js' ;
89import { formatApplyValidationError } from '../plugin-error-formatter.js' ;
910import { ResourceConfig } from '../../entities/resource-config.js' ;
1011import { ResourceInfo } from '../../entities/resource-info.js' ;
@@ -14,30 +15,6 @@ import { ImportResult } from '../../orchestrators/import.js';
1415import { prettyFormatPlan } from '../plan-pretty-printer.js' ;
1516import { PromptType , Reporter } from './reporter.js' ;
1617
17- function plainEntryLabel ( entry : ApplyResultEntry ) : string {
18- if ( entry . status === 'failed' ) return 'failed' ;
19- if ( entry . status === 'skipped' ) return 'skipped' ;
20- switch ( entry . operation ) {
21- case ResourceOperation . CREATE : return 'installed' ;
22- case ResourceOperation . DESTROY : return 'destroyed' ;
23- case ResourceOperation . MODIFY :
24- case ResourceOperation . RECREATE : return 'modified' ;
25- default : return 'applied' ;
26- }
27- }
28-
29- function plainEntryColor ( entry : ApplyResultEntry ) : ( s : string ) => string {
30- if ( entry . status === 'failed' ) return chalk . red ;
31- if ( entry . status === 'skipped' ) return chalk . gray ;
32- switch ( entry . operation ) {
33- case ResourceOperation . CREATE : return chalk . green ;
34- case ResourceOperation . DESTROY : return chalk . red ;
35- case ResourceOperation . MODIFY :
36- case ResourceOperation . RECREATE : return chalk . yellow ;
37- default : return ( s ) => s ;
38- }
39- }
40-
4118export class PlainReporter implements Reporter {
4219 private readonly rl = readline . createInterface ( process . stdin , process . stdout ) ;
4320 silent = false ;
@@ -190,13 +167,11 @@ Use this init flow to get started quickly with Codify.
190167 ) ;
191168 }
192169
193- async displayPluginError ( errors : PluginError [ ] ) : Promise < void > {
194- for ( const error of errors ) {
195- if ( error . errorData . errorType === 'apply_validation' ) {
196- ctx . log ( chalk . red ( formatApplyValidationError ( error ) ) ) ;
197- } else {
198- ctx . log ( chalk . red ( error . message ) ) ;
199- }
170+ async displayPluginError ( error : PluginError ) : Promise < void > {
171+ if ( error . errorData . errorType === 'apply_validation' ) {
172+ ctx . log ( chalk . red ( formatApplyValidationError ( error ) ) ) ;
173+ } else {
174+ ctx . log ( chalk . red ( error . message ) ) ;
200175 }
201176 }
202177
@@ -210,13 +185,16 @@ Use this init flow to get started quickly with Codify.
210185 if ( result . entries . length > 0 ) {
211186 ctx . log ( '' ) ;
212187 for ( const entry of result . entries ) {
213- const label = plainEntryLabel ( entry ) ;
214- const colorFn = plainEntryColor ( entry ) ;
215- ctx . log ( ` ${ entry . id . padEnd ( 30 ) } ${ colorFn ( label ) } ` ) ;
188+ ctx . log ( ` ${ entry . id . padEnd ( 30 ) } ${ applyEntryChalkColor ( entry ) ( applyEntryLabel ( entry ) ) } ` ) ;
216189 }
217190 }
218191
219- if ( ! result . isPartialFailure ( ) ) {
192+ if ( result . isPartialFailure ( ) ) {
193+ ctx . log ( '' ) ;
194+ for ( const error of result . errors ) {
195+ await this . displayPluginError ( error ) ;
196+ }
197+ } else {
220198 ctx . log ( '' ) ;
221199 ctx . log ( 'Open a new terminal or source \'.zshrc\' for the new changes to be reflected' ) ;
222200 }
0 commit comments