entity

package
v0.0.69 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskForName added in v0.0.21

func AskForName[TEntity any](existingNames []string, defaultName string, desc *EntityDescriptor[TEntity]) (name string, err error)

func AskUserIsCreatingNew

func AskUserIsCreatingNew[TEntity any](desc *EntityDescriptor[TEntity]) (bool, error)

func ConfirmDeletion

func ConfirmDeletion[TEntity any](entity *TEntity, desc *EntityDescriptor[TEntity]) (confirmed bool, err error)

func CreateUniqueNameValidator

func CreateUniqueNameValidator(existingNames []string) survey.Validator

func GetEntityByDisplayName added in v0.0.34

func GetEntityByDisplayName[TEntity any](entityName string, entities []TEntity, desc *EntityDescriptor[TEntity]) (*TEntity, error)

func GetEntityById

func GetEntityById[TEntity any](entityId string, entities []TEntity, desc *EntityDescriptor[TEntity]) (*TEntity, error)

func GetNames added in v0.0.21

func GetNames[TEntity any](entities []TEntity, desc *EntityDescriptor[TEntity]) []string

func InfoCreation

func InfoCreation[TEntity any](entity *TEntity, desc *EntityDescriptor[TEntity])

func InfoDeletion

func InfoDeletion[TEntity any](entity *TEntity, desc *EntityDescriptor[TEntity])

func PrintList

func PrintList[TEntity any](entities []TEntity, desc *EntityDescriptor[TEntity])

func SelectEntitiesByNamesOrAsk added in v0.0.41

func SelectEntitiesByNamesOrAsk[TEntity any](names []string, entities []TEntity, desc *EntityDescriptor[TEntity]) ([]TEntity, error)

func SelectEntity

func SelectEntity[TEntity any](entities []TEntity, desc *EntityDescriptor[TEntity]) (*TEntity, error)

func SelectEntityByNameOrAsk added in v0.0.41

func SelectEntityByNameOrAsk[TEntity any](name string, entities []TEntity, desc *EntityDescriptor[TEntity]) (*TEntity, error)

func SelectEntityOrCreateOne

func SelectEntityOrCreateOne[TEntity any](
	entities []TEntity,
	createEntity func() (*TEntity, error),
	askForNewFirst bool,
	desc *EntityDescriptor[TEntity],
) (entity *TEntity, wasCreated bool, err error)

Types

type EntityDescriptor

type EntityDescriptor[TEntity any] struct {
	Name           string
	PluralName     string
	GetDisplayName func(e *TEntity) string
	GetID          func(e *TEntity) string
}

EntityDescriptor describes an entity and provides a standardized way to handle generic inputs and messaging related to the entity.

func NewEntityDescriptor

func NewEntityDescriptor[TEntity any](
	name, pluralName string,
	getDisplayName func(*TEntity) string,
	getId func(*TEntity) string,
) *EntityDescriptor[TEntity]

Jump to

Keyboard shortcuts

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