...
1 package flagext
2
3 import (
4 "github.com/docker/go-units"
5 )
6
7
8 type ByteSize int
9
10
11 func (b ByteSize) MarshalFlag() (string, error) {
12 return units.HumanSize(float64(b)), nil
13 }
14
15
16 func (b *ByteSize) UnmarshalFlag(value string) error {
17 sz, err := units.FromHumanSize(value)
18 if err != nil {
19 return err
20 }
21 *b = ByteSize(int(sz))
22 return nil
23 }
24
25
26 func (b ByteSize) String() string {
27 return units.HumanSize(float64(b))
28 }
29
30
31 func (b *ByteSize) Set(value string) error {
32 return b.UnmarshalFlag(value)
33 }
34
35
36 func (b *ByteSize) Type() string {
37 return "byte-size"
38 }
39
View as plain text