@@ -20,6 +20,7 @@ import (
20
20
"github.com/lima-vm/lima/pkg/store/filenames"
21
21
"github.com/lima-vm/lima/pkg/uiutil"
22
22
"github.com/lima-vm/lima/pkg/yqutil"
23
+ "github.com/mattn/go-isatty"
23
24
"github.com/sirupsen/logrus"
24
25
"github.com/spf13/cobra"
25
26
)
@@ -33,11 +34,25 @@ func newEditCommand() *cobra.Command {
33
34
ValidArgsFunction : editBashComplete ,
34
35
GroupID : basicCommand ,
35
36
}
37
+ editCommand .PersistentFlags ().BoolP ("yes" , "y" , isatty .IsTerminal (os .Stdout .Fd ()), "Alias of --tty=false" )
36
38
editflags .RegisterEdit (editCommand )
37
39
return editCommand
38
40
}
39
41
40
42
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
+
41
56
var arg string
42
57
if len (args ) > 0 {
43
58
arg = args [0 ]
@@ -79,23 +94,20 @@ func editAction(cmd *cobra.Command, args []string) error {
79
94
if err != nil {
80
95
return err
81
96
}
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 )
88
99
if err != nil {
89
100
return err
90
101
}
102
+
91
103
var yBytes []byte
92
104
if len (yqExprs ) > 0 {
93
105
yq := yqutil .Join (yqExprs )
94
106
yBytes , err = yqutil .EvaluateExpression (yq , yContent )
95
107
if err != nil {
96
108
return err
97
109
}
98
- } else if tty {
110
+ } else {
99
111
var hdr string
100
112
if inst != nil {
101
113
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 {
137
149
logrus .Infof ("Instance %q configuration edited" , inst .Name )
138
150
}
139
151
140
- if ! tty {
152
+ if ! cmd . Flags (). Changed ( " tty" ) {
141
153
// use "start" to start it
142
154
return nil
143
155
}
0 commit comments