| 641 | } |
| 642 | |
| 643 | func migrateToV4(ctx context.DnoteCtx) error { |
| 644 | configPath := fmt.Sprintf("%s/dnoterc", ctx.Paths.LegacyDnote) |
| 645 | |
| 646 | b, err := os.ReadFile(configPath) |
| 647 | if err != nil { |
| 648 | return errors.Wrap(err, "Failed to read the config file") |
| 649 | } |
| 650 | |
| 651 | var preConfig migrateToV4PreConfig |
| 652 | err = yaml.Unmarshal(b, &preConfig) |
| 653 | if err != nil { |
| 654 | return errors.Wrap(err, "Failed to unmarshal existing config into JSON") |
| 655 | } |
| 656 | |
| 657 | postConfig := migrateToV4PostConfig{ |
| 658 | APIKey: preConfig.APIKey, |
| 659 | Editor: getEditorCommand(), |
| 660 | } |
| 661 | |
| 662 | data, err := yaml.Marshal(postConfig) |
| 663 | if err != nil { |
| 664 | return errors.Wrap(err, "Failed to marshal config into JSON") |
| 665 | } |
| 666 | |
| 667 | err = os.WriteFile(configPath, data, 0644) |
| 668 | if err != nil { |
| 669 | return errors.Wrap(err, "Failed to write the config into a file") |
| 670 | } |
| 671 | |
| 672 | return nil |
| 673 | } |
| 674 | |
| 675 | // migrateToV5 migrates actions |
| 676 | func migrateToV5(ctx context.DnoteCtx) error { |