Refactor command argument building and parsing

This commit is contained in:
2025-09-19 19:59:46 +02:00
parent ec5485bd0e
commit 34a949d22e
7 changed files with 223 additions and 407 deletions

View File

@@ -106,10 +106,8 @@ func (o *MlxServerOptions) UnmarshalJSON(data []byte) error {
return nil
}
// BuildCommandArgs converts to command line arguments using the common builder
// BuildCommandArgs converts to command line arguments
func (o *MlxServerOptions) BuildCommandArgs() []string {
config := backends.ArgsBuilderConfig{
SliceHandling: backends.SliceAsMultipleFlags, // MLX doesn't currently have []string fields, but default to multiple flags
}
return backends.BuildCommandArgs(o, config)
multipleFlags := map[string]bool{} // MLX doesn't currently have []string fields
return backends.BuildCommandArgs(o, multipleFlags)
}

View File

@@ -11,27 +11,14 @@ import (
// 3. Args only: "--model model/path --host 0.0.0.0"
// 4. Multiline commands with backslashes
func ParseMlxCommand(command string) (*MlxServerOptions, error) {
config := backends.CommandParserConfig{
ExecutableNames: []string{"mlx_lm.server"},
MultiValuedFlags: map[string]struct{}{}, // MLX has no multi-valued flags
}
executableNames := []string{"mlx_lm.server"}
var subcommandNames []string // MLX has no subcommands
multiValuedFlags := map[string]bool{} // MLX has no multi-valued flags
var mlxOptions MlxServerOptions
if err := backends.ParseCommand(command, config, &mlxOptions); err != nil {
if err := backends.ParseCommand(command, executableNames, subcommandNames, multiValuedFlags, &mlxOptions); err != nil {
return nil, err
}
return &mlxOptions, nil
}
// isValidLogLevel validates MLX log levels
func isValidLogLevel(level string) bool {
validLevels := []string{"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
for _, valid := range validLevels {
if level == valid {
return true
}
}
return false
}