translators

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValNotInAllowedListErr = errors.New("Value was not found in the allowed list")
)

Functions

This section is empty.

Types

type BuiltinBool

type BuiltinBool struct{}

Represents a cmd line argument that will be translated to a bool type.

func (BuiltinBool) Reset

func (_ BuiltinBool) Reset()

func (BuiltinBool) Translate

func (_ BuiltinBool) Translate(arg string) (bool, error)

type BuiltinComplex128

type BuiltinComplex128 struct{}

Represents a cmd line argument that will be translated to a complex128 type.

func (BuiltinComplex128) Reset

func (_ BuiltinComplex128) Reset()

func (BuiltinComplex128) Translate

func (_ BuiltinComplex128) Translate(arg string) (complex128, error)

type BuiltinComplex64

type BuiltinComplex64 struct{}

Represents a cmd line argument that will be translated to a complex64 type.

func (BuiltinComplex64) Reset

func (_ BuiltinComplex64) Reset()

func (BuiltinComplex64) Translate

func (_ BuiltinComplex64) Translate(arg string) (complex64, error)

type BuiltinFloat32

type BuiltinFloat32 struct{}

Represents a cmd line argument that will be translated to a float32 type.

func (BuiltinFloat32) Reset

func (_ BuiltinFloat32) Reset()

func (BuiltinFloat32) Translate

func (_ BuiltinFloat32) Translate(arg string) (float32, error)

type BuiltinFloat64

type BuiltinFloat64 struct{}

Represents a cmd line argument that will be translated to a floa64 type.

func (BuiltinFloat64) Reset

func (_ BuiltinFloat64) Reset()

func (BuiltinFloat64) Translate

func (_ BuiltinFloat64) Translate(arg string) (float64, error)

type BuiltinInt

type BuiltinInt struct {
	Base int
}

Represents a cmd line argument that will be translated to a int type.

func (BuiltinInt) Reset

func (i BuiltinInt) Reset()

func (BuiltinInt) Translate

func (i BuiltinInt) Translate(arg string) (int, error)

type BuiltinInt16

type BuiltinInt16 struct {
	Base int
}

Represents a cmd line argument that will be translated to a int16 type.

func (BuiltinInt16) Reset

func (i BuiltinInt16) Reset()

func (BuiltinInt16) Translate

func (i BuiltinInt16) Translate(arg string) (int16, error)

type BuiltinInt32

type BuiltinInt32 struct {
	Base int
}

Represents a cmd line argument that will be translated to a int32 type.

func (BuiltinInt32) Reset

func (i BuiltinInt32) Reset()

func (BuiltinInt32) Translate

func (i BuiltinInt32) Translate(arg string) (int32, error)

type BuiltinInt64

type BuiltinInt64 struct {
	Base int
}

Represents a cmd line argument that will be translated to a int64 type.

func (BuiltinInt64) Reset

func (i BuiltinInt64) Reset()

func (BuiltinInt64) Translate

func (i BuiltinInt64) Translate(arg string) (int64, error)

type BuiltinInt8

type BuiltinInt8 struct {
	Base int
}

Represents a cmd line argument that will be translated to a int8 type.

func (BuiltinInt8) Reset

func (i BuiltinInt8) Reset()

func (BuiltinInt8) Translate

func (i BuiltinInt8) Translate(arg string) (int8, error)

type BuiltinString

type BuiltinString struct{}

Represents a cmd line argument that will be translated to a string type.

func (BuiltinString) Reset

func (_ BuiltinString) Reset()

func (BuiltinString) Translate

func (_ BuiltinString) Translate(arg string) (string, error)

type BuiltinUint

type BuiltinUint struct {
	Base int
}

Represents a cmd line argument that will be translated to a uint type.

func (BuiltinUint) Reset

func (u BuiltinUint) Reset()

func (BuiltinUint) Translate

func (u BuiltinUint) Translate(arg string) (uint, error)

type BuiltinUint16

type BuiltinUint16 struct {
	Base int
}

Represents a cmd line argument that will be translated to a uint16 type.

func (BuiltinUint16) Reset

func (u BuiltinUint16) Reset()

func (BuiltinUint16) Translate

func (u BuiltinUint16) Translate(arg string) (uint16, error)

type BuiltinUint32

type BuiltinUint32 struct {
	Base int
}

Represents a cmd line argument that will be translated to a uint32 type.

func (BuiltinUint32) Reset

func (u BuiltinUint32) Reset()

func (BuiltinUint32) Translate

func (u BuiltinUint32) Translate(arg string) (uint32, error)

type BuiltinUint64

type BuiltinUint64 struct {
	Base int
}

Represents a cmd line argument that will be translated to a uint64 type.

func (BuiltinUint64) Reset

func (u BuiltinUint64) Reset()

func (BuiltinUint64) Translate

func (u BuiltinUint64) Translate(arg string) (uint64, error)

type BuiltinUint8

type BuiltinUint8 struct {
	Base int
}

Represents a cmd line argument that will be translated to a uint8 type.

func (BuiltinUint8) Reset

func (u BuiltinUint8) Reset()

func (BuiltinUint8) Translate

func (u BuiltinUint8) Translate(arg string) (uint8, error)

type Dir

type Dir struct{}

A translator that checks that the supplied directory exists.

func (Dir) Reset

func (_ Dir) Reset()

func (Dir) Translate

func (_ Dir) Translate(arg string) (string, error)

type Enum added in v0.0.2

type Enum[E enum.Value, EP enum.Pntr[E]] struct{}

A translator that forces a value to be a valid enum value for the given enum type.

func (Enum[E, EP]) Reset added in v0.0.2

func (_ Enum[E, EP]) Reset()

func (Enum[E, EP]) Translate added in v0.0.2

func (_ Enum[E, EP]) Translate(arg string) (E, error)

type File

type File struct{}

A translator that checks that the supplied file exists.

func (File) Reset

func (_ File) Reset()

func (File) Translate

func (_ File) Translate(arg string) (string, error)

type Flag

type Flag struct{}

Used to represent a flag that can only be supplied once, returning a boolean value indicating the flags presence.

func (Flag) Reset

func (_ Flag) Reset()

func (Flag) Translate

func (_ Flag) Translate(arg string) (bool, error)

type FlagCntr

type FlagCntr[T basic.Int | basic.Uint] struct {
	// contains filtered or unexported fields
}

Used to represent a flag that can be supplied many times, with a counter incrementing each time the flag is encountered.

func (*FlagCntr[T]) Reset

func (f *FlagCntr[T]) Reset()

func (*FlagCntr[T]) Translate

func (f *FlagCntr[T]) Translate(arg string) (T, error)

type ListValues

type ListValues[T any, U Translater[T], W widgets.BaseInterface[T]] struct {
	ValueTranslator U
	AllowedVals     containers.HashSet[T, W]
	// contains filtered or unexported fields
}

A translator that collects all supplied values into a slice.

func (*ListValues[T, U, W]) Reset

func (l *ListValues[T, U, W]) Reset()

func (*ListValues[T, U, W]) Translate

func (l *ListValues[T, U, W]) Translate(arg string) ([]T, error)

type Mkdir

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

A translator that makes the supplied directory along with all necessary parent directories.

func NewMkdir

func NewMkdir() *Mkdir

Returns a new Mkdir struct initialized with the default values.

func (*Mkdir) GetPermissions

func (o *Mkdir) GetPermissions() fs.FileMode

The permissions used to create all dirs and sub-dirs. See os.MkdirAll for reference.

func (Mkdir) Reset

func (m Mkdir) Reset()

func (*Mkdir) SetPermissions

func (o *Mkdir) SetPermissions(v fs.FileMode) *Mkdir

The permissions used to create all dirs and sub-dirs. See os.MkdirAll for reference.

func (Mkdir) Translate

func (m Mkdir) Translate(arg string) (string, error)

type Noop

type Noop[T any] struct{}

Used to represent a cmd line argument that will always be the default zero-value initilized T type.

func (Noop[T]) Reset

func (_ Noop[T]) Reset()

func (Noop[T]) Translate

func (_ Noop[T]) Translate(arg string) (T, error)

type OpenFile

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

A translator that makes the supplied file.

func NewOpenFile

func NewOpenFile() *OpenFile

Returns a new OpenFile struct initialized with the default values.

func (*OpenFile) GetFlags

func (o *OpenFile) GetFlags() int

The flags used to determine the file mode. See os.RDONLY and friends.

func (*OpenFile) GetPermissions

func (o *OpenFile) GetPermissions() fs.FileMode

The permissions used to open the file with. See os.OpenFile for reference.

func (OpenFile) Reset

func (_ OpenFile) Reset()

func (*OpenFile) SetFlags

func (o *OpenFile) SetFlags(v int) *OpenFile

The flags used to determine the file mode. See os.RDONLY and friends.

func (*OpenFile) SetPermissions

func (o *OpenFile) SetPermissions(v fs.FileMode) *OpenFile

The permissions used to open the file with. See os.OpenFile for reference.

func (OpenFile) Translate

func (o OpenFile) Translate(arg string) (*os.File, error)

type Range

type Range[T basic.Number, U Translater[T]] struct {
	// Inclusive min
	Min T
	// Exclusive max
	Max           T
	NumTranslator U
}

A translator that imposes a range on the supplied cmd line argument.

func (Range[T, U]) Reset

func (r Range[T, U]) Reset()

func (Range[T, U]) Translate

func (r Range[T, U]) Translate(arg string) (T, error)

type Selector

type Selector[T any, U Translater[T], W widgets.BaseInterface[T]] struct {
	AllowedVals     containers.HashSet[T, W]
	ValueTranslator Translater[T]
}

A translator that imposes a set of specific values on a cmd line argument.

func (Selector[T, U, W]) Reset

func (s Selector[T, U, W]) Reset()

func (Selector[T, U, W]) Translate

func (s Selector[T, U, W]) Translate(arg string) (T, error)

type Stopper

type Stopper[T any] struct{ Err error }

Used to represent a flag that when encountered should stop parsing of the cmd line arguments. The error that the stopper is created with will be returned when Stopper.Translate is called.

func (Stopper[T]) Reset

func (s Stopper[T]) Reset()

func (Stopper[T]) Translate

func (s Stopper[T]) Translate(arg string) (T, error)

type Translater

type Translater[T any] interface {
	Translate(arg string) (T, error)
	// Resets the state of the Translater's underlying value.
	Reset()
}

An interface that defines what actions can be performed when translating a string argument to a typed value. The translator is expected to perform all validation required to ensure a correct value is returned. It is also expected to return an error if a value is found to be invalid.

Jump to

Keyboard shortcuts

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