bfmt

package module
v0.0.0-...-ebed8dd Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2017 License: BSD-3-Clause Imports: 4 Imported by: 0

README

bfmt

Build Status

This is a package that wraps most functions present in the fmt package with a boolean conditional.

Docs can be found at http://godoc.org/github.com/hgfischer/go-bfmt

Introduction

If you ever needed to write code like this:

package main

import (
	"fmt"
	"flag"
)

var verbose bool

func main() {
	flag.BoolVar(&verbose, "v", false, "Enable verbose output")
	flag.Parse()

	if verbose {
		fmt.Println("I'm chatty...")
	}
}

Then you can now use go-bfmt to do this:

package main

import (
	"flag"
	"github.com/hgfischer/go-bfmt"
)

var verbose = bfmt.Bool(false)

func main() {
	flag.Var(&verbose, "v", "Enable verbose output")
	flag.Parse()

	verbose.Println("I'm chatty...")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BoolWriter io.Writer = os.Stdout

BoolWriter is the default io.Writes interface used by bfmt.Bool to output things

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool is just a bool type, that conditionally mimics the fmt package. If its value is `true` Bool methods do what they are meant to be done, otherwise, they do nothing.

func (Bool) Errorf

func (b Bool) Errorf(format string, a ...interface{}) error

Errorf conditionally and formatted output to a error. See fmt.Errorf. Return nil if false.

func (Bool) Fprint

func (b Bool) Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint conditionally print output to an io.Writer. See fmt.Fprint. Return (0, nil) if false.

func (Bool) Fprintf

func (b Bool) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf conditionally and formatted output to a io.Writer. See fmt.Fprintf. Return (0, nil) if false.

func (Bool) Fprintln

func (b Bool) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln conditionally print output with carriage return to an io.Writer. See fmt.Fprintln. Return (0, nil) if false.

func (*Bool) Get

func (b *Bool) Get() interface{}

Get returns a bool that have the same value as the method receiver

func (*Bool) IsBoolFlag

func (b *Bool) IsBoolFlag() bool

IsBoolFlag returns true

func (Bool) Print

func (b Bool) Print(a ...interface{}) (n int, err error)

Print conditionally print output. See fmt.Print. Return (0, nil) if false.

func (Bool) Printf

func (b Bool) Printf(format string, a ...interface{})

Printf conditionally and formatted output. See fmt.Printf.

func (Bool) Println

func (b Bool) Println(a ...interface{}) (n int, err error)

Println conditionally print output with carriage return. See fmt.Println. Return (0, nil) if false.

func (*Bool) Set

func (b *Bool) Set(s string) error

Set parse a boolean string value and change the method receiver value

func (Bool) Sprint

func (b Bool) Sprint(a ...interface{}) string

Sprint conditionally print output to a string. See fmt.Sprint. Return "" if false.

func (Bool) Sprintf

func (b Bool) Sprintf(format string, a ...interface{}) string

Sprintf conditionally and formatted output to a string. See fmt.Sprintf. Return "" if false.

func (Bool) Sprintln

func (b Bool) Sprintln(a ...interface{}) string

Sprintln conditionally print output with carriage return to a string. See fmt.Sprintln. Return "" if false.

func (*Bool) String

func (b *Bool) String() string

String returns a string representation of the method receiver

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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