Skip to content

Commit

Permalink
Merge changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Aug 15, 2022
1 parent 6ff3e8e commit 0decf96
Show file tree
Hide file tree
Showing 5 changed files with 691 additions and 12 deletions.
13 changes: 9 additions & 4 deletions flag-spec.yaml
Expand Up @@ -45,7 +45,12 @@ flag_types:
- { name: Layout, type: string }
- { name: Timezone, type: "*time.Location" }

# TODO: enable UintSlice
# UintSlice: {}
# TODO: enable Uint64Slice once #1334 lands
# Uint64Slice: {}
UintSlice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
Uint64Slice:
value_pointer: true
skip_interfaces:
- fmt.Stringer

23 changes: 23 additions & 0 deletions flag.go
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"regexp"
"runtime"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -317,6 +318,28 @@ func stringifyFlag(f Flag) string {
fmt.Sprintf("%s\t%s", prefixedNames(df.Names(), placeholder), usageWithDefault))
}

func stringifyUintSliceFlag(f *UintSliceFlag) string {
var defaultVals []string
if f.Value != nil && len(f.Value.Value()) > 0 {
for _, i := range f.Value.Value() {
defaultVals = append(defaultVals, strconv.FormatUint(uint64(i), 10))
}
}

return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
}

func stringifyUint64SliceFlag(f *Uint64SliceFlag) string {
var defaultVals []string
if f.Value != nil && len(f.Value.Value()) > 0 {
for _, i := range f.Value.Value() {
defaultVals = append(defaultVals, strconv.FormatUint(i, 10))
}
}

return stringifySliceFlag(f.Usage, f.Names(), defaultVals)
}

func stringifySliceFlag(usage string, names, defaultVals []string) string {
placeholder, usage := unquoteUsage(usage)
if placeholder == "" {
Expand Down

0 comments on commit 0decf96

Please sign in to comment.