aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/pflag/uint_slice.go
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2020-06-17 15:07:58 -0400
committerGitHub <noreply@github.com>2020-06-17 22:07:58 +0300
commit9e6a79bea9d7911c81b86a6d3715d340fc19032a (patch)
tree3c5982227a3ed7481786185f5fdf5a8c1107f279 /vendor/github.com/spf13/pflag/uint_slice.go
parent1645d4a5d8def3cc5451e068aa0a321e028a889b (diff)
downloadgitea-9e6a79bea9d7911c81b86a6d3715d340fc19032a.tar.gz
gitea-9e6a79bea9d7911c81b86a6d3715d340fc19032a.zip
upgrade to use testfixtures v3 (#11904)
* upgrade to use testfixtures v3 * simplify logic * make vendor * update per @lunny * Update templates/repo/empty.tmpl * Update templates/repo/empty.tmpl Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'vendor/github.com/spf13/pflag/uint_slice.go')
-rw-r--r--vendor/github.com/spf13/pflag/uint_slice.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/github.com/spf13/pflag/uint_slice.go b/vendor/github.com/spf13/pflag/uint_slice.go
index edd94c600a..5fa924835e 100644
--- a/vendor/github.com/spf13/pflag/uint_slice.go
+++ b/vendor/github.com/spf13/pflag/uint_slice.go
@@ -50,6 +50,48 @@ func (s *uintSliceValue) String() string {
return "[" + strings.Join(out, ",") + "]"
}
+func (s *uintSliceValue) fromString(val string) (uint, error) {
+ t, err := strconv.ParseUint(val, 10, 0)
+ if err != nil {
+ return 0, err
+ }
+ return uint(t), nil
+}
+
+func (s *uintSliceValue) toString(val uint) string {
+ return fmt.Sprintf("%d", val)
+}
+
+func (s *uintSliceValue) Append(val string) error {
+ i, err := s.fromString(val)
+ if err != nil {
+ return err
+ }
+ *s.value = append(*s.value, i)
+ return nil
+}
+
+func (s *uintSliceValue) Replace(val []string) error {
+ out := make([]uint, len(val))
+ for i, d := range val {
+ var err error
+ out[i], err = s.fromString(d)
+ if err != nil {
+ return err
+ }
+ }
+ *s.value = out
+ return nil
+}
+
+func (s *uintSliceValue) GetSlice() []string {
+ out := make([]string, len(*s.value))
+ for i, d := range *s.value {
+ out[i] = s.toString(d)
+ }
+ return out
+}
+
func uintSliceConv(val string) (interface{}, error) {
val = strings.Trim(val, "[]")
// Empty string would cause a slice with one (empty) entry