From cc3567f26e3f95ee09415417dfcc64d07ec9a328 Mon Sep 17 00:00:00 2001 From: Stanislav Fesenko Date: Tue, 20 Feb 2024 09:30:22 +0300 Subject: [PATCH] impr: unlimited replacements when expanding command vars (#8) --- internal/engine/docker.go | 2 +- internal/engine/docker_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/engine/docker.go b/internal/engine/docker.go index cde048c..bb7adfd 100644 --- a/internal/engine/docker.go +++ b/internal/engine/docker.go @@ -323,7 +323,7 @@ func expandVars(command []string, name string) []string { expanded := make([]string, len(command)) copy(expanded, command) for i, cmd := range expanded { - expanded[i] = strings.Replace(cmd, ":name", name, 1) + expanded[i] = strings.Replace(cmd, ":name", name, -1) } return expanded } diff --git a/internal/engine/docker_test.go b/internal/engine/docker_test.go index d841045..aaa38c8 100644 --- a/internal/engine/docker_test.go +++ b/internal/engine/docker_test.go @@ -300,8 +300,9 @@ func TestDockerExec(t *testing.T) { func Test_expandVars(t *testing.T) { const name = "codapi_01" commands := map[string]string{ - "python main.py": "python main.py", - "sh create.sh :name": "sh create.sh " + name, + "python main.py": "python main.py", + "sh create.sh :name": "sh create.sh " + name, + "sh copy.sh :name new-:name": "sh copy.sh " + name + " new-" + name, } for cmd, want := range commands { src := strings.Fields(cmd)