iecbyte

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 3 Imported by: 0

README

iecbyte Go Report Card GoDoc

This package provides a Flag type that can be used as a custom flag for flag and github.com/sp13/pflag.

Example

package main

import (
    "flag"

    "github.com/andrewheberle/iecbyte"
)

func main() {
	size := iecbyte.NewFlag(1024 * 1024)

	flag.Var(&size, "size", "Size in IEC bytes")
	flag.Parse()

	fmt.Printf("Size is %s\n", size)
	// Output: Size is 1Mi
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag struct {
	// contains filtered or unexported fields
}

Flag satisfies the pflag.Value interface

func NewFlag

func NewFlag(n int64) Flag

NewFlag is used to initialise a new iecbyte.Flag with a default value

A value of n that is < 0 will be set to 0

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

func (f Flag) Get() int64

func (*Flag) Set

func (f *Flag) Set(value string) error

func (Flag) String

func (f Flag) String() string

func (Flag) Type

func (f Flag) Type() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL