Add --properties-separator option (#1951)

This commit adds the --properties-separator option, which lets users
specify the separator used between keys and values in the properties
output format. This is done by adjusting the value of
github.com/magiconair/properties#Properties.WriteSeparator at encode
time.

Some refactoring of the properties encoder unit tests was done to make
it easier to write unit tests that include different separator values.

Fixes: #1864

Signed-off-by: Ryan Drew <ryan.drew@isovalent.com>
This commit is contained in:
Ryan Drew
2024-02-20 10:57:44 +11:00
committed by GitHub
parent 9a8151d316
commit 2865022cf8
8 changed files with 208 additions and 76 deletions
+4 -1
View File
@@ -12,11 +12,13 @@ import (
type propertiesEncoder struct {
unwrapScalar bool
prefs PropertiesPreferences
}
func NewPropertiesEncoder(unwrapScalar bool) Encoder {
func NewPropertiesEncoder(unwrapScalar bool, prefs PropertiesPreferences) Encoder {
return &propertiesEncoder{
unwrapScalar: unwrapScalar,
prefs: prefs,
}
}
@@ -69,6 +71,7 @@ func (pe *propertiesEncoder) Encode(writer io.Writer, node *CandidateNode) error
mapKeysToStrings(node)
p := properties.NewProperties()
p.WriteSeparator = pe.prefs.KeyValueSeparator
err := pe.doEncode(p, node, "", nil)
if err != nil {
return err