@@ -18,50 +18,41 @@ export default class Apply extends Command {
1818 ]
1919
2020 static flags = {
21- // flag with no value (-f, --force)
22- force : Flags . boolean ( { char : 'f' } ) ,
23- // flag with a value (-n, --name=VALUE)
24- name : Flags . string ( { char : 'n' , description : 'name to print' } ) ,
2521 // flag with a value (-p, --path=VALUE)
2622 path : Flags . string ( { char : 'p' , description : 'path to project' } ) ,
2723 }
2824
2925 public async run ( ) : Promise < void > {
30- const { args , flags } = await this . parse ( Apply )
26+ const { flags } = await this . parse ( Apply )
3127 const reporter = new DefaultReporter ( )
3228
33- const name = flags . name ?? 'world'
34- this . log ( `hello ${ name } from /Users/kevinwang/Projects/codify/codify-core/src/commands/apply.ts` )
35- if ( args . file && flags . force ) {
36- this . log ( `you input --force and --file: ${ args . file } ` )
37- }
38-
39- if ( flags . path ) {
40- this . log ( `Applying Codify from: ${ flags . path } ` ) ;
41- }
29+ try {
30+ if ( flags . path ) {
31+ this . log ( `Applying Codify from: ${ flags . path } ` ) ;
32+ }
4233
43- const resolvedPath = path . resolve ( flags . path ?? '.' ) ;
34+ const resolvedPath = path . resolve ( flags . path ?? '.' ) ;
4435
45- const planResult = await PlanOrchestrator . run ( resolvedPath , false ) ;
36+ const planResult = await PlanOrchestrator . run ( resolvedPath , false ) ;
37+ reporter . displayPlan ( planResult . plan ) ;
4638
47- // Short circuit and exit if every change is NOOP
48- if ( planResult . plan . every ( ( p ) => p . operation === ResourceOperation . NOOP ) ) {
49- console . log ( 'No changes necessary. Exiting' ) ;
50- await planResult . pluginCollection . destroy ( ) ;
51- return ;
52- }
39+ // Short circuit and exit if every change is NOOP
40+ if ( planResult . plan . every ( ( p ) => p . operation === ResourceOperation . NOOP ) ) {
41+ console . log ( 'No changes necessary. Exiting' ) ;
42+ await planResult . pluginCollection . destroy ( ) ;
43+ return this . exit ( 0 ) ;
44+ }
5345
54- reporter . displayPlan ( planResult . plan ) ;
46+ const confirm = await reporter . promptApplyConfirmation ( )
47+ if ( ! confirm ) {
48+ return this . exit ( 0 ) ;
49+ }
5550
56- const confirm = await reporter . promptApplyConfirmation ( )
57-
58- if ( ! confirm ) {
59- return this . exit ( 0 ) ;
51+ await ApplyOrchestrator . run ( planResult ) ;
52+ } catch ( error : unknown ) {
53+ console . error ( error ) ;
6054 }
6155
62- await ApplyOrchestrator . run ( planResult ) ;
63-
64- // this.exit(0);
65-
56+ this . exit ( 0 ) ;
6657 }
6758}
0 commit comments