mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
feat(config): auto migrate to 1
This commit is contained in:
parent
a5162b0f19
commit
0185299263
|
@ -23,10 +23,13 @@ const (
|
||||||
JSON string = "json"
|
JSON string = "json"
|
||||||
YAML string = "yaml"
|
YAML string = "yaml"
|
||||||
TOML string = "toml"
|
TOML string = "toml"
|
||||||
|
|
||||||
|
configVersion = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config holds all the theme for rendering the prompt
|
// Config holds all the theme for rendering the prompt
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Version int `json:"version"`
|
||||||
FinalSpace bool `json:"final_space,omitempty"`
|
FinalSpace bool `json:"final_space,omitempty"`
|
||||||
OSC99 bool `json:"osc99,omitempty"`
|
OSC99 bool `json:"osc99,omitempty"`
|
||||||
ConsoleTitle bool `json:"console_title,omitempty"`
|
ConsoleTitle bool `json:"console_title,omitempty"`
|
||||||
|
@ -72,6 +75,10 @@ func (cfg *Config) exitWithError(err error) {
|
||||||
// LoadConfig returns the default configuration including possible user overrides
|
// LoadConfig returns the default configuration including possible user overrides
|
||||||
func LoadConfig(env environment.Environment) *Config {
|
func LoadConfig(env environment.Environment) *Config {
|
||||||
cfg := loadConfig(env)
|
cfg := loadConfig(env)
|
||||||
|
if cfg.Version != configVersion {
|
||||||
|
cfg.Migrate(env)
|
||||||
|
cfg.Write()
|
||||||
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,21 +17,24 @@ const (
|
||||||
|
|
||||||
func (cfg *Config) Migrate(env environment.Environment) {
|
func (cfg *Config) Migrate(env environment.Environment) {
|
||||||
for _, block := range cfg.Blocks {
|
for _, block := range cfg.Blocks {
|
||||||
block.migrate(env)
|
for _, segment := range block.Segments {
|
||||||
|
segment.migrate(env, cfg.Version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, segment := range cfg.Tooltips {
|
for _, segment := range cfg.Tooltips {
|
||||||
segment.migrate(env)
|
segment.migrate(env, cfg.Version)
|
||||||
}
|
}
|
||||||
cfg.updated = true
|
cfg.updated = true
|
||||||
|
cfg.Version = configVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (block *Block) migrate(env environment.Environment) {
|
func (segment *Segment) migrate(env environment.Environment, version int) {
|
||||||
for _, segment := range block.Segments {
|
if version < 1 {
|
||||||
segment.migrate(env)
|
segment.migrationOne(env)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (segment *Segment) migrate(env environment.Environment) {
|
func (segment *Segment) migrationOne(env environment.Environment) {
|
||||||
if err := segment.mapSegmentWithWriter(env); err != nil {
|
if err := segment.mapSegmentWithWriter(env); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,7 +295,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
||||||
Type: tc.Type,
|
Type: tc.Type,
|
||||||
Properties: tc.Props,
|
Properties: tc.Props,
|
||||||
}
|
}
|
||||||
segment.migrate(&mock.MockedEnvironment{})
|
segment.migrationOne(&mock.MockedEnvironment{})
|
||||||
assert.Equal(t, tc.Expected, segment.Properties[properties.SegmentTemplate], tc.Case)
|
assert.Equal(t, tc.Expected, segment.Properties[properties.SegmentTemplate], tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue