@@ -14,6 +14,8 @@ import (
14
14
"github.com/lima-vm/lima/pkg/start"
15
15
"github.com/lima-vm/lima/pkg/store"
16
16
"github.com/lima-vm/lima/pkg/store/filenames"
17
+ "github.com/lima-vm/lima/pkg/yqutil"
18
+ "github.com/mattn/go-isatty"
17
19
"github.com/sirupsen/logrus"
18
20
"github.com/spf13/cobra"
19
21
)
@@ -26,6 +28,9 @@ func newEditCommand() *cobra.Command {
26
28
RunE : editAction ,
27
29
ValidArgsFunction : editBashComplete ,
28
30
}
31
+ // TODO: "survey" does not support using cygwin terminal on windows yet
32
+ editCommand .Flags ().Bool ("tty" , isatty .IsTerminal (os .Stdout .Fd ()), "enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal" )
33
+ editCommand .Flags ().String ("set" , "" , "modify the template inplace, using yq syntax" )
29
34
return editCommand
30
35
}
31
36
@@ -53,14 +58,31 @@ func editAction(cmd *cobra.Command, args []string) error {
53
58
if err != nil {
54
59
return err
55
60
}
56
- hdr := fmt .Sprintf ("# Please edit the following configuration for Lima instance %q\n " , instName )
57
- hdr += "# and an empty file will abort the edit.\n "
58
- hdr += "\n "
59
- hdr += editutil .GenerateEditorWarningHeader ()
60
- yBytes , err := editutil .OpenEditor (instName , yContent , hdr )
61
+ tty , err := cmd .Flags ().GetBool ("tty" )
61
62
if err != nil {
62
63
return err
63
64
}
65
+ yq , err := cmd .Flags ().GetString ("set" )
66
+ if err != nil {
67
+ return err
68
+ }
69
+ var yBytes []byte
70
+ if yq != "" {
71
+ logrus .Warn ("`--set` is experimental" )
72
+ yBytes , err = yqutil .EvaluateExpression (yq , yContent )
73
+ if err != nil {
74
+ return err
75
+ }
76
+ } else if tty {
77
+ hdr := fmt .Sprintf ("# Please edit the following configuration for Lima instance %q\n " , instName )
78
+ hdr += "# and an empty file will abort the edit.\n "
79
+ hdr += "\n "
80
+ hdr += editutil .GenerateEditorWarningHeader ()
81
+ yBytes , err = editutil .OpenEditor (instName , yContent , hdr )
82
+ if err != nil {
83
+ return err
84
+ }
85
+ }
64
86
if len (yBytes ) == 0 {
65
87
logrus .Info ("Aborting, as requested by saving the file with empty content" )
66
88
return nil
@@ -86,6 +108,10 @@ func editAction(cmd *cobra.Command, args []string) error {
86
108
}
87
109
logrus .Infof ("Instance %q configuration edited" , instName )
88
110
111
+ if ! tty {
112
+ // use "start" to start it
113
+ return nil
114
+ }
89
115
startNow , err := askWhetherToStart ()
90
116
if err != nil {
91
117
return err
0 commit comments