enum

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtensionEnumYml  _ExtensionEnum = ".yml"
	ExtensionEnumYAML _ExtensionEnum = ".yaml"
	ExtensionEnumJSON _ExtensionEnum = ".json"
	ExtensionEnumGo   _ExtensionEnum = ".go"
)
View Source
const (
	// FlagEnumType is the Go Type that will be used for the enum name.
	FlagEnumType _FlagEnum = "type"
	// FlagEnumOutput is the file relative to where ctenum was called.
	FlagEnumOutput _FlagEnum = "output"
	// FlagEnumPackage is the name of the package to put the enum into.
	FlagEnumPackage _FlagEnum = "package"
	// FlagEnumMakeFile is a boolean that defaults to making a file named
	// <type>_ctenumer.go in the current relative directory.
	FlagEnumMakeFile _FlagEnum = "make-file"
)

Variables

View Source
var ErrTypeRequired = errors.New("a type name for the enum is required")

Functions

func Build

func Build(version string, args []string, out, errW io.Writer) error

func ExtensionEnumStrings

func ExtensionEnumStrings() []string

ExtensionEnumStrings returns a slice of all enum values as strings. This could be useful for validation with something like slices.Contains or quickly seeing all values of an enum. Each string matches the index of ExtensionEnumValues.

func FlagEnumStrings

func FlagEnumStrings() []string

FlagEnumStrings returns a slice of all enum values as strings. This could be useful for validation with something like slices.Contains or quickly seeing all values of an enum. Each string matches the index of FlagEnumValues.

Types

type ConstSpec

type ConstSpec struct {
	Comment string
	Name    string
	Value   string
}

type Enum

type Enum struct {
	Package string
	Output  string
	Type    string
	Values  []ConstSpec
}

type ExtensionEnum

type ExtensionEnum interface {
	fmt.Stringer
	encoding.TextMarshaler
	// contains filtered or unexported methods
}

ExtensionEnum is a true enum, i.e. using this as a parameter in a function declaration requires the use of one of the constants defined in this package.

func ExtensionEnumValues

func ExtensionEnumValues() []ExtensionEnum

ExtensionEnumValues returns a slice of values of the ExtensionEnum enum. Each enum value matches the index of ExtensionEnumStrings.

func ToExtensionEnum

func ToExtensionEnum(s string) (ExtensionEnum, error)

ToExtensionEnum retrieves an enum value from the constants defined in this package. It tries it's best to find s in the enum by using the original-case, uppercase and lowercase.

type ExtensionEnumUnmarshaler

type ExtensionEnumUnmarshaler string

func (ExtensionEnumUnmarshaler) Extract

func (*ExtensionEnumUnmarshaler) UnmarshalText

func (x *ExtensionEnumUnmarshaler) UnmarshalText(text []byte) error

type FlagEnum

type FlagEnum interface {
	fmt.Stringer
	encoding.TextMarshaler
	// contains filtered or unexported methods
}

FlagEnum is a true enum, i.e. using this as a parameter in a function declaration requires the use of one of the constants defined in this package.

func FlagEnumValues

func FlagEnumValues() []FlagEnum

FlagEnumValues returns a slice of values of the FlagEnum enum. Each enum value matches the index of FlagEnumStrings.

func ToFlagEnum

func ToFlagEnum(s string) (FlagEnum, error)

ToFlagEnum retrieves an enum value from the constants defined in this package. It tries it's best to find s in the enum by using the original-case, uppercase and lowercase.

type FlagEnumUnmarshaler

type FlagEnumUnmarshaler string

func (FlagEnumUnmarshaler) Extract

func (x FlagEnumUnmarshaler) Extract() FlagEnum

func (*FlagEnumUnmarshaler) UnmarshalText

func (x *FlagEnumUnmarshaler) UnmarshalText(text []byte) error

type InvalidExtensionEnumError

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

InvalidExtensionEnumError is returned by ToExtensionEnum if the passed in string isn't one of the enum values.

func (InvalidExtensionEnumError) Error

Error exposes the invalid string used and shows all the possible values.

func (InvalidExtensionEnumError) Is

Is tells you if target can be unwrapped to be an InvalidExtensionEnumError.

type InvalidFlagEnumError

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

InvalidFlagEnumError is returned by ToFlagEnum if the passed in string isn't one of the enum values.

func (InvalidFlagEnumError) Error

func (e InvalidFlagEnumError) Error() string

Error exposes the invalid string used and shows all the possible values.

func (InvalidFlagEnumError) Is

func (e InvalidFlagEnumError) Is(err error) bool

Is tells you if target can be unwrapped to be an InvalidFlagEnumError.

Jump to

Keyboard shortcuts

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