@@ -2,7 +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 { withSpinner } from '../utils.js' ;
5+ import { output , OutputType } from '../utils.js' ;
66
77const config : ConfigLocal = new ConfigLocal ( isTests ( ) ? CONFIG_LOCAL_TEST : undefined ) ;
88const program = new Command ( ) ;
@@ -14,23 +14,17 @@ configCmd
1414 . option ( '-l, --log' , 'Enable logging' )
1515 . description ( 'Get a config setting by key' )
1616 . action ( ( key : keyof ConfigInterface , options : CliOptions ) => {
17- return withSpinner (
18- options ,
19- config as any ,
20- `Get config ${ String ( key ) } ` ,
21- async ( ) => {
22- return { key, value : config . get ( key ) } ;
23- } ,
24- ( result : any , useJson : boolean ) => {
25- if ( useJson ) {
26- const obj : any = { } ;
27- obj [ result . key ] = result . value ;
28- console . log ( JSON . stringify ( obj , null , 2 ) ) ;
29- } else {
30- console . log ( result . value ) ;
31- }
32- } ,
33- ) ;
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+ }
27+ }
3428 } ) ;
3529
3630configCmd
@@ -39,22 +33,16 @@ configCmd
3933 . option ( '-l, --log' , 'Enable logging' )
4034 . description ( 'Set a config setting by key and value' )
4135 . action ( ( key : keyof ConfigInterface , val : any , options : CliOptions ) => {
42- return withSpinner (
43- options ,
44- config as any ,
45- `Set config ${ String ( key ) } ` ,
46- async ( ) => {
36+ {
37+ const message = `Set config ${ String ( key ) } ` ;
38+ output ( OutputType . START , message , options , config ) ;
39+ try {
4740 const res = config . set ( key , val ) ;
48- return { key, value : res } ;
49- } ,
50- ( result : any , useJson : boolean ) => {
51- if ( useJson ) {
52- const obj : any = { } ;
53- obj [ result . key ] = result . value ;
54- console . log ( JSON . stringify ( obj , null , 2 ) ) ;
55- } else {
56- console . log ( result . value ) ;
57- }
58- } ,
59- ) ;
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+ }
47+ }
6048 } ) ;
0 commit comments