MCPcopy Index your code
hub / github.com/abiosoft/colima / editConfigFile

Function editConfigFile

cmd/start.go:630–664  ·  view source on GitHub ↗

editConfigFile launches an editor to edit the config file.

()

Source from the content-addressed store, hash-verified

628
629// editConfigFile launches an editor to edit the config file.
630func editConfigFile() (config.Config, error) {
631 var c config.Config
632
633 // preserve the current file in case the user terminates
634 currentFile, err := os.ReadFile(config.CurrentProfile().File())
635 if err != nil {
636 return c, fmt.Errorf("error reading config file: %w", err)
637 }
638
639 // prepend the config file with termination instruction
640 abort, err := embedded.ReadString("defaults/abort.yaml")
641 if err != nil {
642 log.Warnln(fmt.Errorf("unable to read embedded file: %w", err))
643 }
644
645 tmpFile, err := waitForUserEdit(startCmdArgs.Flags.Editor, []byte(abort+"\n"+string(currentFile)))
646 if err != nil {
647 return c, fmt.Errorf("error editing config file: %w", err)
648 }
649
650 // if file is empty, abort
651 if tmpFile == "" {
652 return c, fmt.Errorf("empty file, startup aborted")
653 }
654
655 defer func() {
656 _ = os.Remove(tmpFile)
657 }()
658 if startCmdArgs.Flags.SaveConfig {
659 if err := configmanager.SaveFromFile(tmpFile); err != nil {
660 return c, err
661 }
662 }
663 return configmanager.LoadFrom(tmpFile)
664}
665
666func start(app app.App, conf config.Config) error {
667 if err := app.Start(conf); err != nil {

Callers 1

start.goFile · 0.85

Calls 6

CurrentProfileFunction · 0.92
ReadStringFunction · 0.92
SaveFromFileFunction · 0.92
LoadFromFunction · 0.92
waitForUserEditFunction · 0.85
FileMethod · 0.65

Tested by

no test coverage detected