@@ -7,7 +7,10 @@ import (
7
7
"os"
8
8
"path/filepath"
9
9
10
+ "github.com/AlecAivazis/survey/v2"
10
11
"github.com/lima-vm/lima/pkg/limayaml"
12
+ networks "github.com/lima-vm/lima/pkg/networks/reconcile"
13
+ "github.com/lima-vm/lima/pkg/start"
11
14
"github.com/lima-vm/lima/pkg/store"
12
15
"github.com/lima-vm/lima/pkg/store/filenames"
13
16
"github.com/sirupsen/logrus"
@@ -40,12 +43,16 @@ func editAction(cmd *cobra.Command, args []string) error {
40
43
return err
41
44
}
42
45
46
+ if inst .Status == store .StatusRunning {
47
+ return errors .New ("Cannot edit a running instance" )
48
+ }
49
+
43
50
filePath := filepath .Join (inst .Dir , filenames .LimaYAML )
44
51
yContent , err := os .ReadFile (filePath )
45
52
if err != nil {
46
53
return err
47
54
}
48
- hdr := fmt .Sprintf ("# Please edit the folling configuration for Lima instance %q\n " , instName )
55
+ hdr := fmt .Sprintf ("# Please edit the following configuration for Lima instance %q\n " , instName )
49
56
hdr += "# and an empty file will abort the edit.\n "
50
57
hdr += "\n "
51
58
yBytes , err := openEditor (cmd , instName , yContent , hdr )
@@ -75,8 +82,33 @@ func editAction(cmd *cobra.Command, args []string) error {
75
82
if err := os .WriteFile (filePath , yBytes , 0644 ); err != nil {
76
83
return err
77
84
}
78
- logrus .Infof ("Instance %q edited, you need restart instance to apply it" , instName )
79
- return nil
85
+ logrus .Infof ("Instance %q configuration edited" , instName )
86
+
87
+ startNow , err := askWhetherToStart ()
88
+ if err != nil {
89
+ return err
90
+ }
91
+ if ! startNow {
92
+ return nil
93
+ }
94
+ ctx := cmd .Context ()
95
+ err = networks .Reconcile (ctx , inst .Name )
96
+ if err != nil {
97
+ return err
98
+ }
99
+ return start .Start (ctx , inst )
100
+ }
101
+
102
+ func askWhetherToStart () (bool , error ) {
103
+ ans := true
104
+ prompt := & survey.Confirm {
105
+ Message : "Do you want to start the instance now? " ,
106
+ Default : true ,
107
+ }
108
+ if err := survey .AskOne (prompt , & ans ); err != nil {
109
+ return false , err
110
+ }
111
+ return ans , nil
80
112
}
81
113
82
114
func editBashComplete (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
0 commit comments