@@ -10,7 +10,6 @@ import (
10
10
"os/exec"
11
11
"path"
12
12
"path/filepath"
13
- "regexp"
14
13
"strings"
15
14
16
15
"github.com/AlecAivazis/survey/v2"
@@ -214,6 +213,26 @@ func askWhetherToOpenEditor(name string) (bool, error) {
214
213
}
215
214
}
216
215
216
+ func fileWarning (filename string ) string {
217
+ b , err := os .ReadFile (filename )
218
+ if err != nil || len (b ) == 0 {
219
+ return ""
220
+ }
221
+ s := "# WARNING: " + filename + " includes the following settings,\n "
222
+ s += "# which are applied before applying this YAML:\n "
223
+ s += "# -----------\n "
224
+ for _ , line := range strings .Split (strings .TrimSuffix (string (b ), "\n " ), "\n " ) {
225
+ s += "#"
226
+ if len (line ) > 0 {
227
+ s += " " + line
228
+ }
229
+ s += "\n "
230
+ }
231
+ s += "# -----------\n "
232
+ s += "\n "
233
+ return s
234
+ }
235
+
217
236
func generateEditorWarningHeader () string {
218
237
var s string
219
238
configDir , err := dirnames .LimaConfigDir ()
@@ -223,28 +242,8 @@ func generateEditorWarningHeader() string {
223
242
return s
224
243
}
225
244
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
- }
245
+ s += fileWarning (filepath .Join (configDir , filenames .Default ))
246
+ s += fileWarning (filepath .Join (configDir , filenames .Override ))
248
247
return s
249
248
}
250
249
0 commit comments