Skip to content

Commit

Permalink
Comment out null values in generated YAML config
Browse files Browse the repository at this point in the history
  • Loading branch information
milogreg committed Dec 5, 2024
1 parent 0df8e9a commit 3b24a0c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions go/libraries/doltcore/servercfg/yaml_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,17 @@ func (cfg YAMLConfig) String() string {
return formattedYAMLMarshal(cfg)
}

// Same as String, but includes nil values for empty fields rather than omitting them.
// Behaves like String, but includes empty fields instead of omitting them.
// If an empty field has a default value, the default will be used.
// If an empty field has no default value, a commented-out placeholder will be used.
func (cfg YAMLConfig) VerboseString() string {
withDefaults := cfg
withDefaults.fillDefaults()

return formattedYAMLMarshal(removeOmitemptyTags(withDefaults))
formatted := formattedYAMLMarshal(removeOmitemptyTags(withDefaults))
formatted = commentNullYAMLValues(formatted)

return formatted
}

// Assumes YAMLConfig has no circular references.
Expand Down Expand Up @@ -381,6 +386,19 @@ func formattedYAMLMarshal(toMarshal any) string {
return result
}

func commentNullYAMLValues(needsComments string) string {
lines := strings.Split(needsComments, "\n")
for i := 0; i < len(lines); i++ {
if strings.HasSuffix(lines[i], "null") {
withoutSpace := strings.TrimSpace(lines[i])
space := lines[i][:len(lines[i])-len(withoutSpace)]
lines[i] = space + "# " + withoutSpace
}
}

return strings.Join(lines, "\n")
}

// Host returns the domain that the server will run on. Accepts an IPv4 or IPv6 address, in addition to localhost.
func (cfg YAMLConfig) Host() string {
if cfg.ListenerConfig.HostStr == nil {
Expand Down

0 comments on commit 3b24a0c

Please sign in to comment.