...

Source file src/github.com/go-openapi/runtime/flagext/byte_size.go

Documentation: github.com/go-openapi/runtime/flagext

     1  package flagext
     2  
     3  import (
     4  	"github.com/docker/go-units"
     5  )
     6  
     7  // ByteSize used to pass byte sizes to a go-flags CLI
     8  type ByteSize int
     9  
    10  // MarshalFlag implements go-flags Marshaller interface
    11  func (b ByteSize) MarshalFlag() (string, error) {
    12  	return units.HumanSize(float64(b)), nil
    13  }
    14  
    15  // UnmarshalFlag implements go-flags Unmarshaller interface
    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  // String method for a bytesize (pflag value and stringer interface)
    26  func (b ByteSize) String() string {
    27  	return units.HumanSize(float64(b))
    28  }
    29  
    30  // Set the value of this bytesize (pflag value interfaces)
    31  func (b *ByteSize) Set(value string) error {
    32  	return b.UnmarshalFlag(value)
    33  }
    34  
    35  // Type returns the type of the pflag value (pflag value interface)
    36  func (b *ByteSize) Type() string {
    37  	return "byte-size"
    38  }
    39  

View as plain text