mirror of
https://github.com/mikefarah/yq.git
synced 2026-08-24 08:22:13 +08:00
feat: add --ini-preserve-quotes flag for INI round-trip quote preservation (#2728)
Add INIPreferences.PreserveSurroundedQuote option that wires through to go-ini/ini's LoadOptions.PreserveSurroundedQuote. When enabled, existing surrounding quotes on INI values are preserved during decode/encode round-trips. Fixes #2456 Co-authored-by: toller892 <toller892@gmail.com>
This commit is contained in:
@@ -12,11 +12,13 @@ import (
|
||||
type iniDecoder struct {
|
||||
reader io.Reader
|
||||
finished bool // Flag to signal completion of processing
|
||||
prefs INIPreferences
|
||||
}
|
||||
|
||||
func NewINIDecoder() Decoder {
|
||||
func NewINIDecoder(prefs INIPreferences) Decoder {
|
||||
return &iniDecoder{
|
||||
finished: false, // Initialise the flag as false
|
||||
prefs: prefs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +41,10 @@ func (dec *iniDecoder) Decode() (*CandidateNode, error) {
|
||||
}
|
||||
|
||||
// Parse the INI content
|
||||
cfg, err := ini.Load(content)
|
||||
loadOpts := ini.LoadOptions{
|
||||
PreserveSurroundedQuote: dec.prefs.PreserveSurroundedQuote,
|
||||
}
|
||||
cfg, err := ini.LoadSources(loadOpts, content)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse INI content: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user