@@ -10,6 +10,7 @@ import (
10
10
"os/exec"
11
11
"path"
12
12
"path/filepath"
13
+ "regexp"
13
14
"strings"
14
15
15
16
"github.com/AlecAivazis/survey/v2"
@@ -19,6 +20,7 @@ import (
19
20
"github.com/lima-vm/lima/pkg/osutil"
20
21
"github.com/lima-vm/lima/pkg/start"
21
22
"github.com/lima-vm/lima/pkg/store"
23
+ "github.com/lima-vm/lima/pkg/store/dirnames"
22
24
"github.com/lima-vm/lima/pkg/store/filenames"
23
25
"github.com/mattn/go-isatty"
24
26
"github.com/norouter/norouter/cmd/norouter/editorcmd"
@@ -147,6 +149,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string) (*store.Instance, e
147
149
}
148
150
hdr += "# - To cancel starting Lima, just save this file as an empty file.\n "
149
151
hdr += "\n "
152
+ hdr += generateEditorWarningHeader ()
150
153
yBytes , err = openEditor (cmd , instName , yBytes , hdr )
151
154
if err != nil {
152
155
return nil , err
@@ -211,6 +214,40 @@ func askWhetherToOpenEditor(name string) (bool, error) {
211
214
}
212
215
}
213
216
217
+ func generateEditorWarningHeader () string {
218
+ var s string
219
+ configDir , err := dirnames .LimaConfigDir ()
220
+ if err != nil {
221
+ s += "# WARNING: failed to load the config dir\n "
222
+ s += "\n "
223
+ return s
224
+ }
225
+
226
+ re := regexp .MustCompile (`(?m)^` )
227
+ repl := []byte ("# " )
228
+
229
+ defaultPath := filepath .Join (configDir , filenames .Default )
230
+ if b , err := os .ReadFile (defaultPath ); err == nil {
231
+ s += "# WARNING: " + defaultPath + "includes the following settings,\n "
232
+ s += "# which is applied before applying this YAML:\n "
233
+ s += "# -----------\n "
234
+ s += string (re .ReplaceAll (b , repl )) + "\n "
235
+ s += "# -----------\n "
236
+ s += "\n "
237
+ }
238
+
239
+ overridePath := filepath .Join (configDir , filenames .Override )
240
+ if b , err := os .ReadFile (overridePath ); err == nil {
241
+ s += "# WARNING: " + overridePath + "includes the following settings,\n "
242
+ s += "# which will take precedence over anything configured in this YAML:\n "
243
+ s += "# -----------\n "
244
+ s += string (re .ReplaceAll (b , repl )) + "\n "
245
+ s += "# -----------\n "
246
+ s += "\n "
247
+ }
248
+ return s
249
+ }
250
+
214
251
// openEditor opens an editor, and returns the content (not path) of the modified yaml.
215
252
//
216
253
// openEditor returns nil when the file was saved as an empty file, optionally with whitespaces.
0 commit comments