package flagvalue

import "go.abhg.dev/doc2go/internal/flagvalue"

Package flagvalue provides flag.Value implementations.

Index

Types

type FileSwitch

type FileSwitch string

FileSwitch is a flag that accepts both "-x" and "-x=value", If a value is specified, it opens a file with that name. Otherwise, it uses a provided fallback writer.

func (*FileSwitch) Bool

func (fs *FileSwitch) Bool() bool

Bool reports whether this flag was set with any value.

func (*FileSwitch) Create

func (fs *FileSwitch) Create(fallback io.Writer) (w io.Writer, done func() error, err error)

Create creates the file specified for this flag, and returns an io.Writer to it and a function to close it.

This has three possible behaviors:

func (*FileSwitch) Get

func (fs *FileSwitch) Get() any

Get returns the path stored in the writer or '-' if no value was specified.

func (*FileSwitch) IsBoolFlag

func (*FileSwitch) IsBoolFlag() bool

IsBoolFlag marks this as a flag that doesn't require a value.

func (*FileSwitch) Set

func (fs *FileSwitch) Set(v string) error

Set receives the value for this flag.

func (*FileSwitch) String

func (fs *FileSwitch) String() string

String returns the path stored in the writer or '-' if no value was specified.

type Getter

type Getter[T any] interface {
	*T
	flag.Getter
}

Getter is a constraint satisfied by pointers to types which implement flag.Getter.

type List

type List[T any, PT Getter[T]] []T

List is a generic flag.Getter that accepts zero or more instances of the same flag and combines them into a list.

func ListOf

func ListOf[T any, PT Getter[T]](vs *[]T) *List[T, PT]

ListOf wraps a slice of flag.Getter objects to accept zero or more instances of that flag.

flag.Var(flagvalue.ListOf(&items), "item", ...)

func (*List[T, PT]) Get

func (lv *List[T, PT]) Get() any

Get returns the values recorded so far as a slice of the underlying type.

func (*List[T, PT]) Set

func (lv *List[T, PT]) Set(s string) error

Set receives a single flag argument into this list.

func (*List[T, PT]) String

func (lv *List[T, PT]) String() string

String returns a semicolon separated list of the values in this list.