Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( Byte uint64 Kilobyte = uint64(1 << (10 * (iota - 1))) Megabyte Gigabyte Terabyte Petabyte Exabyte )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
Flag satisfies the flag.Value and pflag.Value interfaces
func NewFlag ¶
NewFlag is used to initialise a new iecbyte.Flag with a default value
Example ¶
package main
import (
"flag"
"fmt"
"github.com/andrewheberle/iecbyte"
)
func main() {
size := iecbyte.NewFlag(1024 * 1024)
flag.Var(&size, "size", "Size in IEC bytes")
//
// In this example flag.Parse() is commented out as this forms part of the tests
// of this module, so parsing the command line flags is disabled.
//
// In a real program you would need to call flag.Parse()
//
// flag.Parse()
fmt.Printf("Size is %s\n", size)
}
Output: Size is 1Mi
func (Flag) Get ¶
Get returns the value of the Flag as an int64
Example ¶
package main
import (
"fmt"
"github.com/andrewheberle/iecbyte"
)
func main() {
size := iecbyte.NewFlag(1024 * 1024)
fmt.Println(size)
fmt.Println(size.Get())
}
Output: 1Mi 1048576
func (Flag) Type ¶
Type returns a user facing type for this flag and is required to satisfy the pflag.Value interface
Example ¶
package main
import (
"os"
"github.com/andrewheberle/iecbyte"
"github.com/spf13/pflag"
)
func main() {
// This example doesn't explicitly show the calling of Type(),
// however the pflag package calls Type() as part of it's display
// of command line flag defaults that is being manually called below.
size := iecbyte.NewFlag(1024 * 1024)
fs := pflag.NewFlagSet("example", pflag.ExitOnError)
fs.SetOutput(os.Stdout)
fs.Var(&size, "size", "Size in IEC bytes")
fs.Parse([]string{})
fs.PrintDefaults()
}
Output: --size bytes (IEC) Size in IEC bytes (default 1Mi)
Click to show internal directories.
Click to hide internal directories.