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

@@ -12,22 +12,20 @@ import (
// 4. Args only: "--model MODEL_NAME --other-args"
// 5. Multiline commands with backslashes
func ParseVllmCommand(command string) (*VllmServerOptions, error) {
config := backends.CommandParserConfig{
ExecutableNames: []string{"vllm"},
SubcommandNames: []string{"serve"},
MultiValuedFlags: map[string]struct{}{
"middleware": {},
"api_key": {},
"allowed_origins": {},
"allowed_methods": {},
"allowed_headers": {},
"lora_modules": {},
"prompt_adapters": {},
},
executableNames := []string{"vllm"}
subcommandNames := []string{"serve"}
multiValuedFlags := map[string]bool{
"middleware": true,
"api_key": true,
"allowed_origins": true,
"allowed_methods": true,
"allowed_headers": true,
"lora_modules": true,
"prompt_adapters": true,
}
var vllmOptions VllmServerOptions
if err := backends.ParseCommand(command, config, &vllmOptions); err != nil {
if err := backends.ParseCommand(command, executableNames, subcommandNames, multiValuedFlags, &vllmOptions); err != nil {
return nil, err
}

View File

@@ -130,18 +130,15 @@ type VllmServerOptions struct {
OverrideKVCacheALIGNSize int `json:"override_kv_cache_align_size,omitempty"`
}
// BuildCommandArgs converts VllmServerOptions to command line arguments using the common builder
// BuildCommandArgs converts VllmServerOptions to command line arguments
// Note: This does NOT include the "serve" subcommand, that's handled at the instance level
func (o *VllmServerOptions) BuildCommandArgs() []string {
config := backends.ArgsBuilderConfig{
SliceHandling: backends.SliceAsMixed,
MultipleFlags: map[string]struct{}{
"api-key": {},
"allowed-origins": {},
"allowed-methods": {},
"allowed-headers": {},
"middleware": {},
},
multipleFlags := map[string]bool{
"api-key": true,
"allowed-origins": true,
"allowed-methods": true,
"allowed-headers": true,
"middleware": true,
}
return backends.BuildCommandArgs(o, config)
return backends.BuildCommandArgs(o, multipleFlags)
}