Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 24, 2023
1 parent 58aea7d commit 023935b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 46 deletions.
41 changes: 0 additions & 41 deletions internal/pflagfork/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,6 @@ func (f Flag) IsRepeatable() bool {
return false
}

func (f Flag) Matches(arg string, posix bool) bool {
if !strings.HasPrefix(arg, "-") { // not a flag
return false
}

switch {

case strings.HasPrefix(arg, "--"):
name := strings.TrimPrefix(arg, "--")
name = strings.SplitN(name, string(f.OptargDelimiter()), 2)[0]

switch f.Mode() {
case ShorthandOnly, NameAsShorthand:
return false
default:
return name == f.Name
}

case !posix:
name := strings.TrimPrefix(arg, "-")
name = strings.SplitN(name, string(f.OptargDelimiter()), 2)[0]

if name == "" {
return false
}

switch f.Mode() {
case ShorthandOnly:
return name == f.Shorthand
default:
return name == f.Name || name == f.Shorthand
}

default:
if f.Shorthand != "" {
return strings.HasSuffix(arg, f.Shorthand)
}
return false
}
}

func (f Flag) TakesValue() bool {
switch f.Value.Type() {
case "bool", "boolSlice", "count":
Expand Down
10 changes: 5 additions & 5 deletions internal/pflagfork/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,22 @@ func (fs FlagSet) lookupPosixShorthandArg(arg string) *Flag {
return nil
}

func (fs FlagSet) lookupNonPosixShorthandArg(arg string) (flag *Flag) { // TODO pretty much duplicates longhand lookup
func (fs FlagSet) lookupNonPosixShorthandArg(arg string) (result *Flag) { // TODO pretty much duplicates longhand lookup
if !strings.HasPrefix(arg, "-") {
return nil
}

fs.VisitAll(func(f *Flag) { // TODO needs to be sorted to try longest matching first
if flag != nil {
if result != nil {
return
}

splitted := strings.SplitAfterN(arg, string(f.OptargDelimiter()), 2)
if strings.TrimSuffix(splitted[0], string(f.OptargDelimiter())) == "-"+f.Shorthand {
flag = f
flag.Prefix = splitted[0]
result = f
result.Prefix = splitted[0]
if len(splitted) > 1 {
flag.Args = splitted[1:]
result.Args = splitted[1:]
}
strings.HasPrefix(arg, fmt.Sprintf("-%v%c", f.Shorthand, f.OptargDelimiter()))

Check failure on line 153 in internal/pflagfork/flagset.go

View workflow job for this annotation

GitHub Actions / lint

SA4017: HasPrefix doesn't have side effects and its return value is ignored (staticcheck)
}
Expand Down

0 comments on commit 023935b

Please sign in to comment.