editConfigFile launches an editor to edit the config file.
()
| 628 | |
| 629 | // editConfigFile launches an editor to edit the config file. |
| 630 | func 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 | |
| 666 | func start(app app.App, conf config.Config) error { |
| 667 | if err := app.Start(conf); err != nil { |
no test coverage detected