entity

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 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, 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 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 SelectEntity

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

func SelectEntityOrCreateOne

func SelectEntityOrCreateOne[TEntity any](
	entities []TEntity,
	createEntity func() (*TEntity, error),
	askForNewFirst bool,
	desc *EntityDescriptor[TEntity],
) (*TEntity, 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