use strings.Builder
This commit is contained in:
parent
119589fcb3
commit
8acb233668
1 changed files with 6 additions and 10 deletions
|
@ -29,24 +29,20 @@ type Command struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Command) String() string {
|
func (c Command) String() string {
|
||||||
name := c.Name
|
var sb strings.Builder
|
||||||
args := c.Args
|
|
||||||
|
|
||||||
switch c.Name {
|
switch c.Name {
|
||||||
case "model":
|
case "model":
|
||||||
name = "from"
|
fmt.Fprintf(&sb, "FROM %s", c.Args)
|
||||||
args = c.Args
|
|
||||||
case "license", "template", "system", "adapter":
|
case "license", "template", "system", "adapter":
|
||||||
args = quote(args)
|
fmt.Fprintf(&sb, "%s %s", strings.ToUpper(c.Name), quote(c.Args))
|
||||||
case "message":
|
case "message":
|
||||||
role, message, _ := strings.Cut(c.Args, ": ")
|
role, message, _ := strings.Cut(c.Args, ": ")
|
||||||
args = role + " " + quote(message)
|
fmt.Fprintf(&sb, "MESSAGE %s %s", role, quote(message))
|
||||||
default:
|
default:
|
||||||
name = "parameter"
|
fmt.Fprintf(&sb, "PARAMETER %s %s", c.Name, quote(c.Args))
|
||||||
args = c.Name + " " + quote(c.Args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s %s", strings.ToUpper(name), args)
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type state int
|
type state int
|
||||||
|
|
Loading…
Reference in a new issue