CliParser.Init() accepts optional flags. Currently una flag is available: ResetOnEqualSign

This commit is contained in:
2026-03-06 11:45:58 +01:00
parent 9e28ee6545
commit 00b84278d8
3 changed files with 26 additions and 6 deletions
+13 -1
View File
@@ -14,6 +14,7 @@ type cliParser interface {
getCliArgs(startIndex, endIndex int) (args []string)
PrintVersion(specs []string)
PrintUsage()
FlagIsSet(flag int16) bool
}
type cliOptionParser interface {
@@ -41,20 +42,31 @@ type OptReference interface {
SetHidden(hidden bool)
}
const (
ResetOnEqualSign = int16(1 << iota) // for some option types, like arrays, the equal signs reset to empty the accumulator of values
)
type CliParser struct {
description string
version string
options []cliOptionParser
argSpecs []argSpec
cliArgs []string
flags int16
}
func (cli *CliParser) Init(argv []string, version string, description string) {
func (cli *CliParser) Init(argv []string, version string, description string, flags ...int16) {
cli.version = version
cli.description = description
cli.cliArgs = argv
for _, flag := range flags {
cli.flags |= flag
}
}
func (cli *CliParser) FlagIsSet(flag int16) bool {
return (cli.flags & flag) == flag
}
func (cli *CliParser) GetOption(name string) (ref OptReference) {
var opt cliOptionParser
if strings.HasPrefix(name, "-") {