From 0ea49ff1adbc0675b779f05bd0cbf13ca9facc24 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Wed, 29 Apr 2020 11:38:02 +0300 Subject: [PATCH] release: 0.2.2 - stop parsing options when pos args started - add sections with newline before --- Makefile | 2 +- args.go | 2 +- tests/expected_ini/test_add_section.sh.ini | 1 + types/ini.go | 8 ++++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d954407..5228369 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME=multini -VERSION=0.2.1 +VERSION=0.2.2 GOCMD=go LDFLAGS:="$(LDFLAGS) -X 'main.Version=$(VERSION)'" GOBUILD=$(GOCMD) build -ldflags=$(LDFLAGS) diff --git a/args.go b/args.go index 61441c2..3f9d8a4 100644 --- a/args.go +++ b/args.go @@ -100,7 +100,7 @@ func init() { } func parseArgs() error { - gnuflag.Parse(true) + gnuflag.Parse(false) // info switch { diff --git a/tests/expected_ini/test_add_section.sh.ini b/tests/expected_ini/test_add_section.sh.ini index a528b1a..83eb42a 100644 --- a/tests/expected_ini/test_add_section.sh.ini +++ b/tests/expected_ini/test_add_section.sh.ini @@ -17,4 +17,5 @@ DefKey3=NoSpaces! [SectionWithIndent] Key=Value [SectionWithoutNewLineBefore] + [NewSection] diff --git a/types/ini.go b/types/ini.go index 10f850b..c8127fe 100644 --- a/types/ini.go +++ b/types/ini.go @@ -89,6 +89,14 @@ func (obj *Ini) GetKeyVal(section, key, value string) error { func (obj *Ini) AddSection(section string) *Section { sect, err := obj.FindSection(section) 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 newSection.Name = section newSection.Prefix = obj.Sections[len(obj.Sections)-1].Indent()