MCPcopy
hub / github.com/dnote/dnote / migrateToV4

Function migrateToV4

pkg/cli/migrate/legacy.go:643–673  ·  view source on GitHub ↗
(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

641}
642
643func 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
676func migrateToV5(ctx context.DnoteCtx) error {

Callers 2

performMigrationFunction · 0.85
TestMigrateToV4Function · 0.85

Calls 1

getEditorCommandFunction · 0.70

Tested by 1

TestMigrateToV4Function · 0.68