@@ -2,6 +2,7 @@ import { Command } from 'commander';
22import { CliOptions } from '../types/options.js' ;
33import { ConfigInterface , ConfigLocal , isTests } from '@open-audio-stack/core' ;
44import { CONFIG_LOCAL_TEST } from '../data/Config.js' ;
5+ import { output , OutputType } from '../utils.js' ;
56
67const config : ConfigLocal = new ConfigLocal ( isTests ( ) ? CONFIG_LOCAL_TEST : undefined ) ;
78const program = new Command ( ) ;
@@ -13,13 +14,16 @@ configCmd
1314 . option ( '-l, --log' , 'Enable logging' )
1415 . description ( 'Get a config setting by key' )
1516 . action ( ( key : keyof ConfigInterface , options : CliOptions ) => {
16- if ( options . log ) config . logEnable ( ) ;
17- if ( options . json ) {
18- const obj : any = { } ;
19- obj [ key ] = config . get ( key ) ;
20- console . log ( { key } ) ;
21- } else {
22- console . log ( config . get ( key ) ) ;
17+ {
18+ const message = `Get config ${ String ( key ) } ` ;
19+ output ( OutputType . START , message , options , config ) ;
20+ try {
21+ const payload = options && options . json ? { key, value : config . get ( key ) } : String ( config . get ( key ) ) ;
22+ output ( OutputType . SUCCESS , payload , options , config ) ;
23+ } catch ( err : any ) {
24+ output ( OutputType . ERROR , err , options , config ) ;
25+ process . exit ( 1 ) ;
26+ }
2327 }
2428 } ) ;
2529
@@ -29,12 +33,16 @@ configCmd
2933 . option ( '-l, --log' , 'Enable logging' )
3034 . description ( 'Set a config setting by key and value' )
3135 . action ( ( key : keyof ConfigInterface , val : any , options : CliOptions ) => {
32- // if (options.log) config.logEnable();
33- if ( options . json ) {
34- const obj : any = { } ;
35- obj [ key ] = config . set ( key , val ) ;
36- console . log ( obj ) ;
37- } else {
38- console . log ( config . set ( key , val ) ) ;
36+ {
37+ const message = `Set config ${ String ( key ) } ` ;
38+ output ( OutputType . START , message , options , config ) ;
39+ try {
40+ const res = config . set ( key , val ) ;
41+ const payload = options && options . json ? { key, value : res } : String ( res ) ;
42+ output ( OutputType . SUCCESS , payload , options , config ) ;
43+ } catch ( err : any ) {
44+ output ( OutputType . ERROR , err , options , config ) ;
45+ process . exit ( 1 ) ;
46+ }
3947 }
4048 } ) ;
0 commit comments