-
Notifications
You must be signed in to change notification settings - Fork 699
editflags: update the expression for mount flag #4042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
693b507
to
b2e94ac
Compare
The change looks fine to me, but I've since noticed that the problem is much more convoluted, with no clear solution. Thankfully it is so obscure that I think nobody will ever run into it. First thing is that ❯ cat tmpl.yaml
base: template://default
mounts:
- location: /foo
mountPoint: /bar
❯ l create -y tmpl.yaml --mount /foo
...
❯ l ls tmpl --yq '.config.mounts[] | [.location, .mountPoint]'
[
"/foo",
"/bar"
]
[
"/Users/jan",
"/Users/jan"
] So even though the commandline specified This might be a bug, but it could also be prevented if So I would be in favour of making this change as well. But the other issue is that ❯ l create -y --name foo --mount /foo --set '.mounts += [{"location": "/bar"}]' --mount /baz
❯ l ls foo --yq '.config.mounts[].location'
/foo
/baz
/Users/jan
/bar And even if we managed to process the settings interleaved in the order they appear on the command line, we would still not have control over the user writing With the correct expression it looks like this: ❯ l create -y --name foo --mount /foo --set '.mounts = [{"location": "/bar"}] + .mounts' --mount /baz
...
❯ l ls foo --yq '.config.mounts[].location'
/bar
/foo
/baz
/Users/jan But now Of course I think this is a problem that does not need to be solved; it is a lot of complexity for something that probably nobody will ever run into. |
Since this is all very confusing, these are the changes I would make: --- cmd/limactl/editflags/editflags.go
+++ 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
} But I've also confirmed that the merging of mounts in |
If #4046 is merged first, then I think adding the |
can we prompt the user whether they would want to override the The prompt would look something like this: |
I don't think we want to prompt the user. If there is a problem with their arguments, we show an error and let them fix the command. But checking settings conflicts is very complex, and I don't think we should do it. We have rules how settings are merged (essentially later definitions can update empty fields in earlier definitions based on a common key, but otherwise are ignored). This mechanism exists for It is currently implemented in both the template embedding code, and also in |
Then, i guess I'll just make these suggested changes. |
cb07b08
to
9b480bf
Compare
Signed-off-by: ashwat287 <[email protected]>
9b480bf
to
6d1c17f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
fixes #3959