File: argumentParser.go

package info (click to toggle)
golang-github-integrii-flaggy 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 292 kB
  • sloc: makefile: 3
file content (27 lines) | stat: -rw-r--r-- 837 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package flaggy

// setValueForParsers sets the value for a specified key in the
// specified parsers (which normally include a Parser and Subcommand).
// The return values represent the key being set, and any errors
// returned when setting the key, such as failures to convert the string
// into the appropriate flag value.  We stop assigning values as soon
// as we find a any parser that accepts it.
func setValueForParsers(key string, value string, parsers ...ArgumentParser) (bool, error) {

	for _, p := range parsers {
		valueWasSet, err := p.SetValueForKey(key, value)
		if err != nil {
			return valueWasSet, err
		}
		if valueWasSet {
			return true, nil
		}
	}

	return false, nil
}

// ArgumentParser represents a parser or subcommand
type ArgumentParser interface {
	SetValueForKey(key string, value string) (bool, error)
}