refactor IniParser.writeFile into writeIniToFile
diff --git a/ini.go b/ini.go
index fe5f3ba..f92faff 100644
--- a/ini.go
+++ b/ini.go
@@ -3,7 +3,6 @@
import (
"fmt"
"io"
- "os"
)
// IniError contains location information on where an error occured.
@@ -128,17 +127,7 @@
// for more information. The returned error occurs when the specified file
// could not be opened for writing.
func (i *IniParser) WriteFile(filename string, options IniOptions) error {
- file, err := os.Create(filename)
-
- if err != nil {
- return err
- }
-
- defer file.Close()
-
- i.Write(file, options)
-
- return nil
+ return writeIniToFile(i, filename, options)
}
// Write writes the current values of all the flags to an ini format.
diff --git a/ini_private.go b/ini_private.go
index c6ab87d..64f8fb8 100644
--- a/ini_private.go
+++ b/ini_private.go
@@ -163,6 +163,20 @@
writeCommandIni(parser.parser.Command, "", writer, options)
}
+func writeIniToFile(parser *IniParser, filename string, options IniOptions) error {
+ file, err := os.Create(filename)
+
+ if err != nil {
+ return err
+ }
+
+ defer file.Close()
+
+ writeIni(parser, file, options)
+
+ return nil
+}
+
func readIniFromFile(filename string) (ini, error) {
file, err := os.Open(filename)