mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-12-23 09:34:23 +00:00
Add support for extra args for command parser
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package backends
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"llamactl/pkg/validation"
|
||||
)
|
||||
@@ -35,6 +36,42 @@ type MlxServerOptions struct {
|
||||
ExtraArgs map[string]string `json:"extra_args,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements custom JSON unmarshaling to collect unknown fields into ExtraArgs
|
||||
func (o *MlxServerOptions) UnmarshalJSON(data []byte) error {
|
||||
// First unmarshal into a map to capture all fields
|
||||
var raw map[string]any
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a temporary struct for standard unmarshaling
|
||||
type tempOptions MlxServerOptions
|
||||
temp := tempOptions{}
|
||||
|
||||
// Standard unmarshal first
|
||||
if err := json.Unmarshal(data, &temp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy to our struct
|
||||
*o = MlxServerOptions(temp)
|
||||
|
||||
// Get all known canonical field names from struct tags
|
||||
knownFields := getKnownFieldNames(o)
|
||||
|
||||
// Collect unknown fields into ExtraArgs
|
||||
if o.ExtraArgs == nil {
|
||||
o.ExtraArgs = make(map[string]string)
|
||||
}
|
||||
for key, value := range raw {
|
||||
if !knownFields[key] {
|
||||
o.ExtraArgs[key] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *MlxServerOptions) GetPort() int {
|
||||
return o.Port
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user