Write default header only if `DEFAULT` section exists (#31)

This commit is contained in:
Kartik Gupta 2022-09-06 18:04:05 +02:00 committed by GitHub
parent 30a7de621a
commit f070c24399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -150,9 +150,11 @@ var configureCmd = &cobra.Command{
} }
var buffer bytes.Buffer var buffer bytes.Buffer
//The ini library does not write [DEFAULT] header, so we always if ini_cfg.Section("DEFAULT").Body() != "" {
//add the [DEFAULT] header explicitly. The section might be empty. //This configuration makes the ini library write the DEFAULT header explicitly.
buffer.WriteString("[DEFAULT]\n") //DEFAULT section might be empty
ini.DefaultHeader = true
}
_, err = ini_cfg.WriteTo(&buffer) _, err = ini_cfg.WriteTo(&buffer)
if err != nil { if err != nil {
return fmt.Errorf("write config to buffer: %w", err) return fmt.Errorf("write config to buffer: %w", err)