mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
chore(migrate): backup config on migration
This commit is contained in:
parent
0185299263
commit
6fcae4207e
|
@ -76,6 +76,7 @@ func (cfg *Config) exitWithError(err error) {
|
||||||
func LoadConfig(env environment.Environment) *Config {
|
func LoadConfig(env environment.Environment) *Config {
|
||||||
cfg := loadConfig(env)
|
cfg := loadConfig(env)
|
||||||
if cfg.Version != configVersion {
|
if cfg.Version != configVersion {
|
||||||
|
cfg.Backup()
|
||||||
cfg.Migrate(env)
|
cfg.Migrate(env)
|
||||||
cfg.Write()
|
cfg.Write()
|
||||||
}
|
}
|
||||||
|
@ -171,8 +172,16 @@ func (cfg *Config) Export(format string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Config) Write() {
|
func (cfg *Config) Write() {
|
||||||
|
cfg.write(cfg.origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *Config) Backup() {
|
||||||
|
cfg.write(cfg.origin + ".bak")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *Config) write(destination string) {
|
||||||
content := cfg.Export(cfg.format)
|
content := cfg.Export(cfg.format)
|
||||||
f, err := os.OpenFile(cfg.origin, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
|
f, err := os.OpenFile(destination, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
|
||||||
cfg.exitWithError(err)
|
cfg.exitWithError(err)
|
||||||
_, err = f.WriteString(content)
|
_, err = f.WriteString(content)
|
||||||
cfg.exitWithError(err)
|
cfg.exitWithError(err)
|
||||||
|
|
|
@ -166,11 +166,13 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if *args.Migrate {
|
if *args.Migrate {
|
||||||
cfg.Migrate(env)
|
|
||||||
if *args.Write {
|
if *args.Write {
|
||||||
|
cfg.Backup()
|
||||||
|
cfg.Migrate(env)
|
||||||
cfg.Write()
|
cfg.Write()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
cfg.Migrate(env)
|
||||||
fmt.Print(cfg.Export(*args.ConfigFormat))
|
fmt.Print(cfg.Export(*args.ConfigFormat))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue