Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/limactl/editflags/editflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
}
d := defaultExprFunc
defs := []def{
{"cpus", d(".cpus = %s"), false, false},
{
"cpus",
func(_ *flag.Flag) ([]string, error) {
numCpus, err := flags.GetInt("cpus")
if err != nil {
return nil, err
}
if numCpus < 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting to negative numbers is not caught by validation, but will cause a failure to start the VM. This must be caught; limactl edit should never leave lima.yaml in a non-startable state.

Can we just say -1 means the same amount as the host?
Other negative values such as -2 should be invalid.

Originally posted by @AkihiroSuda in #3987

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Can be revisited in another PR)

return nil, errors.New("invalid value for number of cpus, must be >= 0")
}
return []string{fmt.Sprintf(".cpus = %d", numCpus)}, nil
},
false,
false,
},
{
"dns",
func(_ *flag.Flag) ([]string, error) {
Expand Down