@@ -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 { withSpinner } from '../utils.js' ;
56
67const config : ConfigLocal = new ConfigLocal ( isTests ( ) ? CONFIG_LOCAL_TEST : undefined ) ;
78const program = new Command ( ) ;
@@ -13,14 +14,23 @@ 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 ) ) ;
23- }
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+ ) ;
2434 } ) ;
2535
2636configCmd
@@ -29,12 +39,22 @@ configCmd
2939 . option ( '-l, --log' , 'Enable logging' )
3040 . description ( 'Set a config setting by key and value' )
3141 . 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 ) ) ;
39- }
42+ return withSpinner (
43+ options ,
44+ config as any ,
45+ `Set config ${ String ( key ) } ` ,
46+ async ( ) => {
47+ 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+ ) ;
4060 } ) ;
0 commit comments