From f070c2439947a5324c6afd870cd11ff3a4d96b41 Mon Sep 17 00:00:00 2001 From: Kartik Gupta <88345179+kartikgupta-db@users.noreply.github.com> Date: Tue, 6 Sep 2022 18:04:05 +0200 Subject: [PATCH] Write default header only if `DEFAULT` section exists (#31) --- cmd/configure/configure.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/configure/configure.go b/cmd/configure/configure.go index 1d14cbe4..7c8aaf8b 100644 --- a/cmd/configure/configure.go +++ b/cmd/configure/configure.go @@ -150,9 +150,11 @@ var configureCmd = &cobra.Command{ } var buffer bytes.Buffer - //The ini library does not write [DEFAULT] header, so we always - //add the [DEFAULT] header explicitly. The section might be empty. - buffer.WriteString("[DEFAULT]\n") + if ini_cfg.Section("DEFAULT").Body() != "" { + //This configuration makes the ini library write the DEFAULT header explicitly. + //DEFAULT section might be empty + ini.DefaultHeader = true + } _, err = ini_cfg.WriteTo(&buffer) if err != nil { return fmt.Errorf("write config to buffer: %w", err)