/
mapper.go
48 lines (39 loc) · 1.11 KB
/
mapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package config
import (
"emperror.dev/errors"
"gopkg.in/yaml.v3"
)
const (
VersionFrom = "1.1.0"
VersionTo = "1.1.1"
)
func Migrate(old []byte) []byte {
var config versionWrapper
if err := yaml.Unmarshal(old, &config); err != nil {
panic(err)
}
if config.Version != VersionFrom {
panic(errors.Errorf("Invalid version for migration to v1.1.1: %s", config.Version))
}
config.Version = VersionTo
config.Config.FuzzySearch = true
config.Config.Script["execConfirm"] = false
config.Config.Script["execPrint"] = false
configBytes, err := yaml.Marshal(config)
if err != nil {
panic(err)
}
return configBytes
}
type versionWrapper struct {
Version string `yaml:"version"`
Config configV111 `yaml:"config"`
}
type configV111 struct {
Style map[string]interface{} `yaml:"style"`
Editor string `yaml:"editor"`
DefaultRootCommand string `yaml:"defaultRootCommand"`
FuzzySearch bool `yaml:"fuzzySearch"`
Script map[string]interface{} `yaml:"scripts"`
Manager map[string]interface{} `yaml:"manager"`
}