3 Commits
0.2.1 ... 0.2.3

Author SHA1 Message Date
c76140ffe1 release: 0.2.3
- fixed file write for the '--inplace' option
2020-04-30 08:15:26 +03:00
a89e63f19f fix: file write for the '--inplace' option
removes tails for --inplace in case
the source file is larger than the modified one
2020-04-30 08:09:53 +03:00
0ea49ff1ad release: 0.2.2
- stop parsing options when pos args started
- add sections with newline before
2020-04-29 11:38:02 +03:00
5 changed files with 12 additions and 3 deletions

View File

@ -1,5 +1,5 @@
NAME=multini NAME=multini
VERSION=0.2.1 VERSION=0.2.3
GOCMD=go GOCMD=go
LDFLAGS:="$(LDFLAGS) -X 'main.Version=$(VERSION)'" LDFLAGS:="$(LDFLAGS) -X 'main.Version=$(VERSION)'"
GOBUILD=$(GOCMD) build -ldflags=$(LDFLAGS) GOBUILD=$(GOCMD) build -ldflags=$(LDFLAGS)

View File

@ -100,7 +100,7 @@ func init() {
} }
func parseArgs() error { func parseArgs() error {
gnuflag.Parse(true) gnuflag.Parse(false)
// info // info
switch { switch {

View File

@ -17,4 +17,5 @@ DefKey3=NoSpaces!
[SectionWithIndent] [SectionWithIndent]
Key=Value Key=Value
[SectionWithoutNewLineBefore] [SectionWithoutNewLineBefore]
[NewSection] [NewSection]

View File

@ -89,6 +89,14 @@ func (obj *Ini) GetKeyVal(section, key, value string) error {
func (obj *Ini) AddSection(section string) *Section { func (obj *Ini) AddSection(section string) *Section {
sect, err := obj.FindSection(section) sect, err := obj.FindSection(section)
if err != nil { if err != nil {
sectSize := len(obj.Sections)
if sectSize > 1 {
prevSect := obj.Sections[sectSize-1].(*Section)
lineSize := len(prevSect.Lines)
if lineSize == 0 || lineSize > 0 && prevSect.Lines[lineSize-1].Type() != TEmptyLine {
obj.Sections[sectSize-1].(*Section).Lines = append(obj.Sections[sectSize-1].(*Section).Lines, &EmptyLine{})
}
}
var newSection Section var newSection Section
newSection.Name = section newSection.Name = section
newSection.Prefix = obj.Sections[len(obj.Sections)-1].Indent() newSection.Prefix = obj.Sections[len(obj.Sections)-1].Indent()

View File

@ -114,7 +114,7 @@ func iniWriteInplace(filename string, ini *types.Ini) error {
} }
mode = info.Mode() mode = info.Mode()
} }
targetFile, err := os.OpenFile(realfilename, os.O_WRONLY|os.O_CREATE, mode) targetFile, err := os.OpenFile(realfilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode)
if err == nil { if err == nil {
datawriter := bufio.NewWriter(targetFile) datawriter := bufio.NewWriter(targetFile)
_, err = datawriter.WriteString(ini.Full()) _, err = datawriter.WriteString(ini.Full())