Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const (
type IniParser struct {
ParseAsDefaults bool // override default flags

// NotifyValidateAfterParsing indidcates whether we should Validate any ZCommander fulfilling
// commands after parsing has completed.
// If true, the caller is responsible for calling the separate Validate method.
NoValidateAfterParsing bool

parser *Parser
}

Expand Down Expand Up @@ -159,6 +164,19 @@ func (i *IniParser) Write(writer io.Writer, options IniOptions) {
writeIni(i, writer, options)
}

// ValidateZCommanders validates all commands in the parser that
// implement the ZCommander interface. If any validation fails, the
// program will log.Fatal with the error.
func (i *IniParser) ValidateZCommanders() {
i.parser.eachCommand(func(c *Command) {
if zcmd, ok := c.data.(ZCommander); ok {
if err := zcmd.Validate([]string{}); err != nil {
log.Fatal(err)
}
}
}, true)
}

func readFullLine(reader *bufio.Reader) (string, error) {
var line []byte

Expand Down Expand Up @@ -628,13 +646,10 @@ func (i *IniParser) parse(ini *ini) ([]string, []interface{}, error) {
})
// Validate the options after all default settings set

p.eachCommand(func(c *Command) {
if cmd, ok := c.data.(ZCommander); ok {
if err := cmd.Validate([]string{}); err != nil { //validate
log.Fatal(err)
}
}
}, true)
if !i.NoValidateAfterParsing {
i.ValidateZCommanders()
}

// TODO: checkRequired?

for opt, quoted := range quotesLookup {
Expand Down