From 6d1c17f1ed0467194ff294aa1f12eb75945488bf Mon Sep 17 00:00:00 2001 From: ashwat287 Date: Tue, 16 Sep 2025 21:41:26 +0000 Subject: [PATCH] editflags: update the expression for mount flag Signed-off-by: ashwat287 --- cmd/limactl/editflags/editflags.go | 7 +++++-- cmd/limactl/editflags/editflags_test.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/limactl/editflags/editflags.go b/cmd/limactl/editflags/editflags.go index 6b8d21d65a8..7047a79cabf 100644 --- a/cmd/limactl/editflags/editflags.go +++ b/cmd/limactl/editflags/editflags.go @@ -8,6 +8,7 @@ import ( "fmt" "math/bits" "runtime" + "slices" "strconv" "strings" @@ -179,7 +180,7 @@ func buildMountListExpression(ss []string) (string, error) { if err != nil { return "", err } - expr += fmt.Sprintf(`{"location": %q, "writable": %v}`, loc, writable) + expr += fmt.Sprintf(`{"location": %q, "mountPoint": %q, "writable": %v}`, loc, loc, writable) if i < len(ss)-1 { expr += "," } @@ -225,6 +226,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) { "mount", func(_ *flag.Flag) (string, error) { ss, err := flags.GetStringSlice("mount") + slices.Reverse(ss) if err != nil { return "", err } @@ -232,7 +234,8 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) { if err != nil { return "", err } - expr := `.mounts += ` + mountListExpr + ` | .mounts |= unique_by(.location)` + // mount options take precedence over template settings + expr := fmt.Sprintf(".mounts = %s + .mounts", mountListExpr) mountOnly, err := flags.GetStringSlice("mount-only") if err != nil { return "", err diff --git a/cmd/limactl/editflags/editflags_test.go b/cmd/limactl/editflags/editflags_test.go index ae9e178e166..c580bb0db5a 100644 --- a/cmd/limactl/editflags/editflags_test.go +++ b/cmd/limactl/editflags/editflags_test.go @@ -181,13 +181,13 @@ func TestYQExpressions(t *testing.T) { name: "mount", args: []string{"--mount", "/foo", "--mount", "./bar:w"}, newInstance: false, - expected: []string{`.mounts += [{"location": "` + expand("/foo") + `", "writable": false},{"location": "` + expand("./bar") + `", "writable": true}] | .mounts |= unique_by(.location)`}, + expected: []string{`.mounts = [{"location": "` + expand("./bar") + `", "mountPoint": "` + expand("./bar") + `", "writable": true},{"location": "` + expand("/foo") + `", "mountPoint": "` + expand("/foo") + `", "writable": false}] + .mounts`}, }, { name: "mount-only", args: []string{"--mount-only", "/foo", "--mount-only", "/bar:w"}, newInstance: false, - expected: []string{`.mounts = [{"location": "` + expand("/foo") + `", "writable": false},{"location": "` + expand("/bar") + `", "writable": true}]`}, + expected: []string{`.mounts = [{"location": "` + expand("/foo") + `", "mountPoint": "` + expand("/foo") + `", "writable": false},{"location": "` + expand("/bar") + `", "mountPoint": "` + expand("/bar") + `", "writable": true}]`}, }, { name: "mixture of mount and mount-only",