Skip to content

Commit 3be5bf4

Browse files
committed
added --yes flag to edit
Signed-off-by: Kairvee Vaswani <[email protected]>
1 parent d82d125 commit 3be5bf4

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Diff for: cmd/limactl/edit.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lima-vm/lima/pkg/store/filenames"
2121
"github.com/lima-vm/lima/pkg/uiutil"
2222
"github.com/lima-vm/lima/pkg/yqutil"
23+
"github.com/mattn/go-isatty"
2324
"github.com/sirupsen/logrus"
2425
"github.com/spf13/cobra"
2526
)
@@ -33,11 +34,25 @@ func newEditCommand() *cobra.Command {
3334
ValidArgsFunction: editBashComplete,
3435
GroupID: basicCommand,
3536
}
37+
editCommand.PersistentFlags().BoolP("yes", "y", isatty.IsTerminal(os.Stdout.Fd()), "Alias of --tty=false")
3638
editflags.RegisterEdit(editCommand)
3739
return editCommand
3840
}
3941

4042
func editAction(cmd *cobra.Command, args []string) error {
43+
if cmd.Flags().Changed("yes") && cmd.Flags().Changed("tty") {
44+
return errors.New("cannot use both --tty and --yes flags at the same time")
45+
}
46+
47+
if cmd.Flags().Changed("yes") {
48+
yesValue, _ := cmd.Flags().GetBool("yes")
49+
if yesValue {
50+
if err := cmd.Flags().Set("tty", "false"); err != nil {
51+
return err
52+
}
53+
}
54+
}
55+
4156
var arg string
4257
if len(args) > 0 {
4358
arg = args[0]
@@ -79,23 +94,20 @@ func editAction(cmd *cobra.Command, args []string) error {
7994
if err != nil {
8095
return err
8196
}
82-
flags := cmd.Flags()
83-
tty, err := flags.GetBool("tty")
84-
if err != nil {
85-
return err
86-
}
87-
yqExprs, err := editflags.YQExpressions(flags, false)
97+
98+
yqExprs, err := editflags.YQExpressions(cmd.Flags(), false)
8899
if err != nil {
89100
return err
90101
}
102+
91103
var yBytes []byte
92104
if len(yqExprs) > 0 {
93105
yq := yqutil.Join(yqExprs)
94106
yBytes, err = yqutil.EvaluateExpression(yq, yContent)
95107
if err != nil {
96108
return err
97109
}
98-
} else if tty {
110+
} else {
99111
var hdr string
100112
if inst != nil {
101113
hdr = fmt.Sprintf("# Please edit the following configuration for Lima instance %q\n", inst.Name)
@@ -137,7 +149,7 @@ func editAction(cmd *cobra.Command, args []string) error {
137149
logrus.Infof("Instance %q configuration edited", inst.Name)
138150
}
139151

140-
if !tty {
152+
if !cmd.Flags().Changed("tty") {
141153
// use "start" to start it
142154
return nil
143155
}

0 commit comments

Comments
 (0)