mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -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"
|
||||
YAML string = "yaml"
|
||||
TOML string = "toml"
|
||||
|
||||
configVersion = 1
|
||||
)
|
||||
|
||||
// Config holds all the theme for rendering the prompt
|
||||
type Config struct {
|
||||
Version int `json:"version"`
|
||||
FinalSpace bool `json:"final_space,omitempty"`
|
||||
OSC99 bool `json:"osc99,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
|
||||
func LoadConfig(env environment.Environment) *Config {
|
||||
cfg := loadConfig(env)
|
||||
if cfg.Version != configVersion {
|
||||
cfg.Migrate(env)
|
||||
cfg.Write()
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
|
|
|
@ -17,21 +17,24 @@ const (
|
|||
|
||||
func (cfg *Config) Migrate(env environment.Environment) {
|
||||
for _, block := range cfg.Blocks {
|
||||
block.migrate(env)
|
||||
for _, segment := range block.Segments {
|
||||
segment.migrate(env, cfg.Version)
|
||||
}
|
||||
}
|
||||
for _, segment := range cfg.Tooltips {
|
||||
segment.migrate(env)
|
||||
segment.migrate(env, cfg.Version)
|
||||
}
|
||||
cfg.updated = true
|
||||
cfg.Version = configVersion
|
||||
}
|
||||
|
||||
func (block *Block) migrate(env environment.Environment) {
|
||||
for _, segment := range block.Segments {
|
||||
segment.migrate(env)
|
||||
func (segment *Segment) migrate(env environment.Environment, version int) {
|
||||
if version < 1 {
|
||||
segment.migrationOne(env)
|
||||
}
|
||||
}
|
||||
|
||||
func (segment *Segment) migrate(env environment.Environment) {
|
||||
func (segment *Segment) migrationOne(env environment.Environment) {
|
||||
if err := segment.mapSegmentWithWriter(env); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
Type: tc.Type,
|
||||
Properties: tc.Props,
|
||||
}
|
||||
segment.migrate(&mock.MockedEnvironment{})
|
||||
segment.migrationOne(&mock.MockedEnvironment{})
|
||||
assert.Equal(t, tc.Expected, segment.Properties[properties.SegmentTemplate], tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue