github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/command/flag/megabytes.go (about) 1 package flag 2 3 import ( 4 "strings" 5 6 "github.com/cloudfoundry/bytefmt" 7 flags "github.com/jessevdk/go-flags" 8 ) 9 10 type Megabytes struct { 11 Size uint64 12 } 13 14 func (m *Megabytes) UnmarshalFlag(val string) error { 15 size, err := bytefmt.ToMegabytes(val) 16 17 if err != nil || 18 !strings.ContainsAny(strings.ToLower(val), "mg") || 19 strings.Contains(strings.ToLower(val), ".") { 20 return &flags.Error{ 21 Type: flags.ErrRequired, 22 Message: `Byte quantity must be an integer with a unit of measurement like M, MB, G, or GB`, 23 } 24 } 25 26 m.Size = size 27 return nil 28 }