fix(config): export default config

resolves #2961
This commit is contained in:
Jan De Dobbeleer 2022-10-18 13:07:09 +02:00 committed by Jan De Dobbeleer
parent b174c27a5b
commit ef8055eb08

View file

@ -182,24 +182,28 @@ func (cfg *Config) Export(format string) string {
var result bytes.Buffer
if cfg.format == JSON {
data := config.Data()
data["$schema"] = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json"
jsonEncoder := json2.NewEncoder(&result)
jsonEncoder.SetEscapeHTML(false)
jsonEncoder.SetIndent("", " ")
err := jsonEncoder.Encode(data)
err := jsonEncoder.Encode(cfg)
cfg.exitWithError(err)
return escapeGlyphs(result.String())
prefix := "{\n \"$schema\": \"https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\","
data := strings.Replace(result.String(), "{", prefix, 1)
return escapeGlyphs(data)
}
_, err := config.DumpTo(&result, cfg.format)
cfg.exitWithError(err)
if cfg.format == YAML {
switch cfg.format {
case YAML:
prefix := "# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
return prefix + result.String()
case TOML:
prefix := "#:schema https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
return prefix + escapeGlyphs(result.String())
default:
return result.String()
}
prefix := "#:schema https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json\n\n"
return prefix + escapeGlyphs(result.String())
}
func (cfg *Config) BackupAndMigrate(env environment.Environment) {