@@ -6,14 +6,22 @@ import { readConfigFile, writeConfigFile } from '../../config/loader';
66import type { Config } from '../../config/schema' ;
77import type { GlobalFlags } from '../../types/flags' ;
88
9- const VALID_KEYS = [ 'region' , 'base_url' , 'output' , 'timeout' , 'api_key' ] ;
9+ const VALID_KEYS = [ 'region' , 'base_url' , 'output' , 'timeout' , 'api_key' , 'default_text_model' , 'default_speech_model' , 'default_video_model' , 'default_music_model' ] ;
10+
11+ // Allow hyphen-style keys (e.g. default-text-model → default_text_model)
12+ const KEY_ALIASES : Record < string , string > = {
13+ 'default-text-model' : 'default_text_model' ,
14+ 'default-speech-model' : 'default_speech_model' ,
15+ 'default-video-model' : 'default_video_model' ,
16+ 'default-music-model' : 'default_music_model' ,
17+ } ;
1018
1119export default defineCommand ( {
1220 name : 'config set' ,
1321 description : 'Set a config value' ,
1422 usage : 'mmx config set --key <key> --value <value>' ,
1523 options : [
16- { flag : '--key <key>' , description : 'Config key (region, base_url, output, timeout, api_key)' } ,
24+ { flag : '--key <key>' , description : 'Config key (region, base_url, output, timeout, api_key, default_text_model, default_speech_model, default_video_model, default_music_model )' } ,
1725 { flag : '--value <value>' , description : 'Value to set' } ,
1826 ] ,
1927 examples : [
@@ -33,29 +41,32 @@ export default defineCommand({
3341 ) ;
3442 }
3543
36- if ( ! VALID_KEYS . includes ( key ) ) {
44+ // Resolve hyphen aliases to underscore keys
45+ const resolvedKey : string = KEY_ALIASES [ key ] || key ;
46+
47+ if ( ! VALID_KEYS . includes ( resolvedKey ) ) {
3748 throw new CLIError (
3849 `Invalid config key "${ key } ". Valid keys: ${ VALID_KEYS . join ( ', ' ) } ` ,
3950 ExitCode . USAGE ,
4051 ) ;
4152 }
4253
4354 // Validate specific values
44- if ( key === 'region' && ! [ 'global' , 'cn' ] . includes ( value ) ) {
55+ if ( resolvedKey === 'region' && ! [ 'global' , 'cn' ] . includes ( value ) ) {
4556 throw new CLIError (
4657 `Invalid region "${ value } ". Valid values: global, cn` ,
4758 ExitCode . USAGE ,
4859 ) ;
4960 }
5061
51- if ( key === 'output' && ! [ 'text' , 'json' ] . includes ( value ) ) {
62+ if ( resolvedKey === 'output' && ! [ 'text' , 'json' ] . includes ( value ) ) {
5263 throw new CLIError (
5364 `Invalid output format "${ value } ". Valid values: text, json` ,
5465 ExitCode . USAGE ,
5566 ) ;
5667 }
5768
58- if ( key === 'timeout' ) {
69+ if ( resolvedKey === 'timeout' ) {
5970 const num = Number ( value ) ;
6071 if ( isNaN ( num ) || num <= 0 ) {
6172 throw new CLIError (
@@ -68,16 +79,16 @@ export default defineCommand({
6879 const format = detectOutputFormat ( config . output ) ;
6980
7081 if ( config . dryRun ) {
71- console . log ( formatOutput ( { would_set : { [ key ] : value } } , format ) ) ;
82+ console . log ( formatOutput ( { would_set : { [ resolvedKey ] : value } } , format ) ) ;
7283 return ;
7384 }
7485
7586 const existing = readConfigFile ( ) as Record < string , unknown > ;
76- existing [ key ] = key === 'timeout' ? Number ( value ) : value ;
87+ existing [ resolvedKey ] = resolvedKey === 'timeout' ? Number ( value ) : value ;
7788 await writeConfigFile ( existing ) ;
7889
7990 if ( ! config . quiet ) {
80- console . log ( formatOutput ( { [ key ] : existing [ key ] } , format ) ) ;
91+ console . log ( formatOutput ( { [ resolvedKey ] : existing [ resolvedKey ] } , format ) ) ;
8192 }
8293 } ,
8394} ) ;
0 commit comments