From ac0801ecedec76492a8a024ad2f4fb84f80f001c Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 24 Apr 2024 14:27:12 -0700 Subject: [PATCH] only replace if it matches command --- cmd/cmd.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 96ea705f..4585533f 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -17,6 +17,7 @@ import ( "os" "os/signal" "path/filepath" + "regexp" "runtime" "strings" "syscall" @@ -110,7 +111,13 @@ func CreateHandler(cmd *cobra.Command, args []string) error { return err } - modelfile = bytes.ReplaceAll(modelfile, []byte(c.Args), []byte("@"+digest)) + name := c.Name + if c.Name == "model" { + name = "from" + } + + re := regexp.MustCompile(fmt.Sprintf(`(?im)^(%s)\s+%s\s*$`, name, c.Args)) + modelfile = re.ReplaceAll(modelfile, []byte("$1 @"+digest)) } }