| 1 | // Copyright 2013 Google Inc. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/ |
| 6 | |
| 7 | import ( |
| 8 | "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 9 | "strconvscip-go gomod github.com/golang/go/src go1.13 strconv/" |
| 10 | ) |
| 11 | |
| 12 | type unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned# uint64 |
| 13 | |
| 14 | type UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit# struct { |
| 15 | Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base. int // Base for conversion as per strconv.ParseInt |
| 16 | Bitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Bits. int // Number of bits as per strconv.ParseInt |
| 17 | Minscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Min. uint64 // Minimum allowed value if both Min and Max are not 0 |
| 18 | Maxscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Max. uint64 // Maximum allowed value if both Min and Max are not 0 |
| 19 | } |
| 20 | |
| 21 | var unsignedLimitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsignedLimits. = make(map[*unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#]*UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#) |
| 22 | |
| 23 | func (n *unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#) Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#Set().(value string, opt Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#) error { |
| 24 | l := unsignedLimitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsignedLimits.[n] |
| 25 | if l == nil { |
| 26 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("no limits defined for %s", opt.Namescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Name.()) |
| 27 | } |
| 28 | v, err := strconvscip-go gomod github.com/golang/go/src go1.13 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.13 strconv/ParseUint().(value, l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base., l.Bitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Bits.) |
| 29 | if err != nil { |
| 30 | if e, ok := err.(*strconvscip-go gomod github.com/golang/go/src go1.13 strconv/.NumErrorscip-go gomod github.com/golang/go/src go1.13 strconv/NumError#); ok { |
| 31 | switch e.Errscip-go gomod github.com/golang/go/src go1.13 strconv/NumError#Err. { |
| 32 | case strconvscip-go gomod github.com/golang/go/src go1.13 strconv/.ErrRangescip-go gomod github.com/golang/go/src go1.13 strconv/ErrRange.: |
| 33 | err = fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("value out of range: %s", value) |
| 34 | case strconvscip-go gomod github.com/golang/go/src go1.13 strconv/.ErrSyntaxscip-go gomod github.com/golang/go/src go1.13 strconv/ErrSyntax.: |
| 35 | err = fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("not a valid number: %s", value) |
| 36 | } |
| 37 | } |
| 38 | return err |
| 39 | } |
| 40 | if l.Minscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Min. != 0 || l.Maxscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Max. != 0 { |
| 41 | if v < l.Minscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Min. { |
| 42 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("value out of range (<%v): %s", l.Minscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Min., value) |
| 43 | } |
| 44 | if v > l.Maxscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Max. { |
| 45 | return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("value out of range (>%v): %s", l.Maxscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Max., value) |
| 46 | } |
| 47 | } |
| 48 | *n = unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#(v) |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | func (n *unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#) Stringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#String().() string { |
| 53 | l := unsignedLimitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsignedLimits.[n] |
| 54 | if l != nil && l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base. != 0 { |
| 55 | return strconvscip-go gomod github.com/golang/go/src go1.13 strconv/.FormatUintscip-go gomod github.com/golang/go/src go1.13 strconv/FormatUint().(uint64(*n), l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base.) |
| 56 | } |
| 57 | return strconvscip-go gomod github.com/golang/go/src go1.13 strconv/.FormatUintscip-go gomod github.com/golang/go/src go1.13 strconv/FormatUint().(uint64(*n), 10) |
| 58 | } |
| 59 | |
| 60 | // Unsigned creates an option that is stored in a uint64 and is |
| 61 | // constrained by the limits pointed to by l. The Max and Min values are only |
| 62 | // used if at least one of the values are not 0. If Base is 0, the base is |
| 63 | // implied by the string's prefix: base 16 for "0x", base 8 for "0", and base |
| 64 | // 10 otherwise. |
| 65 | func Unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Unsigned().(name rune, value uint64, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) *uint64 { |
| 66 | return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Unsigned().(name, value, l, helpvalue...) |
| 67 | } |
| 68 | |
| 69 | func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) Unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Unsigned().(name rune, value uint64, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) *uint64 { |
| 70 | return s.UnsignedLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedLong().("", name, value, l, helpvalue...) |
| 71 | } |
| 72 | |
| 73 | func UnsignedLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLong().(name string, short rune, value uint64, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) *uint64 { |
| 74 | return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..UnsignedLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedLong().(name, short, value, l, helpvalue...) |
| 75 | } |
| 76 | |
| 77 | func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) UnsignedLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedLong().(name string, short rune, value uint64, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) *uint64 { |
| 78 | s.UnsignedVarLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedVarLong().(&value, name, short, l, helpvalue...) |
| 79 | return &value |
| 80 | } |
| 81 | |
| 82 | func UnsignedVarscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedVar().(p *uint64, name rune, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option# { |
| 83 | return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..UnsignedVarscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedVar().(p, name, l, helpvalue...) |
| 84 | } |
| 85 | |
| 86 | func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) UnsignedVarscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedVar().(p *uint64, name rune, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option# { |
| 87 | return s.UnsignedVarLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedVarLong().(p, "", name, l, helpvalue...) |
| 88 | } |
| 89 | |
| 90 | func UnsignedVarLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedVarLong().(p *uint64, name string, short rune, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option# { |
| 91 | return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..UnsignedVarLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedVarLong().(p, name, short, l, helpvalue...) |
| 92 | } |
| 93 | |
| 94 | func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) UnsignedVarLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#UnsignedVarLong().(p *uint64, name string, short rune, l *UnsignedLimitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#, helpvalue ...string) Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option# { |
| 95 | opt := s.VarLongscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#VarLong().((*unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#)(p), name, short, helpvalue...) |
| 96 | if l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base. > 36 || l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base. == 1 || l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base. < 0 { |
| 97 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(stderrscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/stderr., "invalid base for %s: %d\n", opt.Namescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Name.(), l.Basescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Base.) |
| 98 | exitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/exit.(1) |
| 99 | } |
| 100 | if l.Bitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Bits. < 0 || l.Bitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Bits. > 64 { |
| 101 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(stderrscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/stderr., "invalid bit size for %s: %d\n", opt.Namescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Name.(), l.Bitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Bits.) |
| 102 | exitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/exit.(1) |
| 103 | } |
| 104 | if l.Minscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Min. > l.Maxscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/UnsignedLimit#Max. { |
| 105 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(stderrscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/stderr., "min greater than max for %s\n", opt.Namescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Name.()) |
| 106 | exitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/exit.(1) |
| 107 | } |
| 108 | lim := *l |
| 109 | unsignedLimitsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsignedLimits.[(*unsignedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/unsigned#)(p)] = &lim |
| 110 | return opt |
| 111 | } |