🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

toolman.org/flags/tristate

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toolman.org/flags/tristate

Go Modules
Version
v0.9.3
Version published
Created
Source

GoDoc Go Report Card Build Status

tristate

import "toolman.org/flags/tristate"

Install

    go get toolman.org/flags/tristate

Overview

Package tristate provides a custom TriState flag for use with the alternate flag package github.com/spf13/pflag. A TriState value may take one of three forms: True, False or None and is most useful when you are, for instance, filtering records based on a current boolean value -- and you need all three possibilities (e.g. True, False and I Don't Care)

There are 8 separate functions provided for defining a TriState flag with some combination of the suffixes: "Var", "P", and "FS" each having the following meaning:

Var: Accepts a TriState pointer instead of returning one.
P:   Also takes a shorthand character for use with a single dash
FS:  Accepts a *FlagSet where the flag should be added

The "Var" and "P" suffixes follow the common pflag convention. The "FS" suffix is added to allow the use of alternate FlagSets.

Index

Package files

tristate.go

Variables

var (
    // CommandLine is the default FlagSet where flags will be added (unless
    // otherwise specified)
    CommandLine = pflag.CommandLine
)
var ErrBadTriStateValue = errors.New("bad tristate value")

ErrBadTriStateValue is returned by Set if if cannot parse its input.

func FlagVar

func FlagVar(ts *TriState, name string, value TriState, usage string)

FlagVar is similar to Flag that also accepts a pointer to TriState variable where the flag value should be stored.

func FlagVarFS

func FlagVarFS(fs *pflag.FlagSet, ts *TriState, name string, value TriState, usage string)

FlagVarFS is similar to FlagVar but accepts a pointer to the FlagSet where this flag should be added.

func FlagVarP

func FlagVarP(ts *TriState, name, shorthand string, value TriState, usage string)

FlagVarP is the combination of FlagVar and FlagP.

func FlagVarPFS

func FlagVarPFS(fs *pflag.FlagSet, ts *TriState, name, shorthand string, value TriState, usage string)

FlagVarPFS is similar to FlagVarP but accepts a pointer to the FlagSet where this flag should be added.

type TriState

type TriState int

TriState is a TriState Value and may have one of three values: None, False or True. Its "zero" value is None.

const (
    None TriState = iota
    False
    True
)

The three possible tristate values

func Flag

func Flag(name string, value TriState, usage string) *TriState

Flag defines a tristate.TriState flag with the specified name, default value and usage string. The return value is the address of a TriState variable the stores the values of the flag.

func FlagFS

func FlagFS(fs *pflag.FlagSet, name string, value TriState, usage string) *TriState

FlagFS is similar to Flag but accepts a pointer to the FlagSet where this flag should be added.

func FlagP

func FlagP(name, shorthand string, value TriState, usage string) *TriState

FlagP is similar to Flag butl also accepts a shorthand letter to be used after a single dash.

func FlagPFS

func FlagPFS(fs *pflag.FlagSet, name, shorthand string, value TriState, usage string) *TriState

FlagPFS is similar to FlagP but accepts a pointer to the FlagSet where this flag should be added.

func (*TriState) Bool

func (ts *TriState) Bool() *bool

Bool returns a pointer to a bool holding the value of ts. If ts is None then Bool returns nil.

func (*TriState) Get

func (ts *TriState) Get() interface{}

Get implements flag.Getter

func (*TriState) Set

func (ts *TriState) Set(s string) error

Set the tristate.Value by parsing s according to the following rules:

Value: Strings
------ ----------------------------------------------------------
True:  1, t, true, y, yes
False: 0, f, false, n, no
None:  -1, u, unknown, e, either, b, both, a, all, none, null, nil

Allstring input is case insensitive. Any string not mentioned above will return ErrBadTriStateValue.

Set contributes to the implementation of pflag.Value

func (TriState) String

func (ts TriState) String() string

String contributes to the implementation of pflag.Value

func (*TriState) Type

func (ts *TriState) Type() string

Type contributes to the implementation of pflag.Value

FAQs

Package last updated on 11 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts