Skip to content

Commit 9b480bf

Browse files
committed
editflags: update the expression for mount flag
Signed-off-by: ashwat287 <[email protected]>
1 parent 1bf475c commit 9b480bf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cmd/limactl/editflags/editflags.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"math/bits"
1010
"runtime"
11+
"slices"
1112
"strconv"
1213
"strings"
1314

@@ -179,7 +180,7 @@ func buildMountListExpression(ss []string) (string, error) {
179180
if err != nil {
180181
return "", err
181182
}
182-
expr += fmt.Sprintf(`{"location": %q, "writable": %v}`, loc, writable)
183+
expr += fmt.Sprintf(`{"location": %q, "mountPoint": %q, "writable": %v}`, loc, loc, writable)
183184
if i < len(ss)-1 {
184185
expr += ","
185186
}
@@ -225,14 +226,16 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
225226
"mount",
226227
func(_ *flag.Flag) (string, error) {
227228
ss, err := flags.GetStringSlice("mount")
229+
slices.Reverse(ss)
228230
if err != nil {
229231
return "", err
230232
}
231233
mountListExpr, err := buildMountListExpression(ss)
232234
if err != nil {
233235
return "", err
234236
}
235-
expr := `.mounts += ` + mountListExpr + ` | .mounts |= unique_by(.location)`
237+
// mount options take precedence over template settings
238+
expr := fmt.Sprintf(".mounts = %s + .mounts", mountListExpr)
236239
mountOnly, err := flags.GetStringSlice("mount-only")
237240
if err != nil {
238241
return "", err

cmd/limactl/editflags/editflags_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ func TestYQExpressions(t *testing.T) {
181181
name: "mount",
182182
args: []string{"--mount", "/foo", "--mount", "./bar:w"},
183183
newInstance: false,
184-
expected: []string{`.mounts += [{"location": "` + expand("/foo") + `", "writable": false},{"location": "` + expand("./bar") + `", "writable": true}] | .mounts |= unique_by(.location)`},
184+
expected: []string{`.mounts = [{"location": "` + expand("./bar") + `", "mountPoint": "` + expand("./bar") + `", "writable": true},{"location": "` + expand("/foo") + `", "mountPoint": "` + expand("/foo") + `", "writable": false}] + .mounts`},
185185
},
186186
{
187187
name: "mount-only",
188188
args: []string{"--mount-only", "/foo", "--mount-only", "/bar:w"},
189189
newInstance: false,
190-
expected: []string{`.mounts = [{"location": "` + expand("/foo") + `", "writable": false},{"location": "` + expand("/bar") + `", "writable": true}]`},
190+
expected: []string{`.mounts = [{"location": "` + expand("/foo") + `", "mountPoint": "` + expand("/foo") + `", "writable": false},{"location": "` + expand("/bar") + `", "mountPoint": "` + expand("/bar") + `", "writable": true}]`}
191191
},
192192
{
193193
name: "mixture of mount and mount-only",

0 commit comments

Comments
 (0)