2 files changed,
25 insertions(+),
2 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-08-27 23:00:09 +0300
Authored at:
2026-08-27 22:21:36 +0300
Change ID:
tzvlwztwwzlqnnuzzrnrwvqlwyzmwkkx
Parent:
d1c6934
jump to
| M | internal/viye/viye.go |
| M | internal/viye/viye_test.go |
M
internal/viye/viye.go
··· 79 79 if len(ctx.Path) == 0 { 80 80 return "", nil 81 81 } 82 + for i := range ctx.Path { 83 + ctx.Path[i] = expandEnv(ctx.Path[i]) 84 + } 82 85 ctx.Cmd, ctx.Args = splitLeaf(ctx.Path) 83 86 ctx.dispatch = v.dispatch 84 87 for _, tool := range v.tools { ··· 87 90 } 88 91 } 89 92 return "", ErrPlumbingNotFound 93 +} 94 + 95 +func expandEnv(s string) string { 96 + if s == "$$" { 97 + return s 98 + } 99 + return os.ExpandEnv(s) 90 100 } 91 101 92 102 // splitLeaf splits a path into command name and args.
M
internal/viye/viye_test.go
··· 57 57 {[]string{"line1", "line2"}, []string{"line1", "line2"}}, 58 58 {[]string{"| not data", "| again not data"}, []string{"| not data", "| again not data"}}, 59 59 } { 60 - got := ParseData(tt.inp) 61 - is.Equal(t, tt.want, got) 60 + is.Equal(t, tt.want, ParseData(tt.inp)) 61 + } 62 +} 63 + 64 +func TestExpandEnv(t *testing.T) { 65 + t.Setenv("VIYE_TEST_ONE", "alpha") 66 + for _, tt := range []struct{ in, want string }{ 67 + {"plain", "plain"}, 68 + {"$VIYE_TEST_ONE", "alpha"}, 69 + {"${VIYE_TEST_ONE}/x", "alpha/x"}, 70 + {"$VIYE_TEST_UNSET", ""}, 71 + {"$$", "$$"}, 72 + } { 73 + is.Equal(t, tt.want, expandEnv(tt.in)) 62 74 } 63 75 } 64 76 ··· 71 83 {[]string{"get", "http://site.com"}, "get", []string{"http://site.com"}}, 72 84 {[]string{"ip"}, "ip", []string{}}, 73 85 {[]string{"$", "go", "run", "."}, "$", []string{"go", "run", "."}}, 86 + {[]string{"$$", "sleep", "5"}, "$$", []string{"sleep", "5"}}, 74 87 } { 75 88 tool := &mockTool{cmd: tt.wantCmd} 76 89 v := &Viye{tools: []Tool{tool}}