randomizer

package
v0.0.0-...-4425001 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package randomizer implements the randomizer's core logic in a manner suitable for use by multiple frontends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App represents a randomizer app that can accept commands.

func NewApp

func NewApp(name string, store Store) App

NewApp returns an App.

func (App) Main

func (a App) Main(ctx context.Context, args []string) (Result, error)

Main is the entrypoint to the randomizer tool.

Note that all errors returned from this function will be of this package's Error type. This provides the HelpText method for user-friendly output formatting.

type Error

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

Error represents an error encountered by the randomizer. It includes friendly help messages that can be displayed directly to users when errors occur, along with an underlying developer-friendly error that may be useful for debugging.

func (Error) Cause

func (e Error) Cause() error

Cause returns the underlying developer-friendly error that represents this usage error.

func (Error) Error

func (e Error) Error() string

func (Error) HelpText

func (e Error) HelpText() string

HelpText returns user-friendly help text associated with this error. While the underlying error is more suitable for developer use, the help text may be displayed directly to a user.

type Result

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

Result represents a successful randomizer operation.

func (Result) Message

func (r Result) Message() string

Message returns the user-friendly output associated with this result.

func (Result) Type

func (r Result) Type() ResultType

Type returns the type of this result.

type ResultType

type ResultType int

ResultType represents the type of successful result returned by the randomizer.

const (
	// Selection indicates that the randomizer made a random selection from input
	// options.
	Selection ResultType = iota
	// ShowedHelp indicates that the randomizer displayed its help output.
	ShowedHelp
	// ListedGroups indicates that a group list was successfully obtained.
	ListedGroups
	// ShowedGroup indicates that the options of a single group were successfully obtained.
	ShowedGroup
	// SavedGroup indicates that a group was successfully saved.
	SavedGroup
	// DeletedGroup indicates that a group was successfully deleted.
	DeletedGroup
)

type Store

type Store interface {
	// List returns the names of all available groups. If no groups have been
	// saved, it returns an empty list with a nil error.
	List(ctx context.Context) (groups []string, err error)

	// Get returns the list of options in the named group. If the group does not
	// exist, it returns an empty list with a nil error.
	Get(ctx context.Context, group string) (options []string, err error)

	// Put saves the provided options as a named group, overwriting any previous
	// group with that name.
	Put(ctx context.Context, group string, options []string) error

	// Delete ensures that the named group no longer exists, returning true or
	// false to indicate whether the group existed prior to this deletion
	// attempt.
	Delete(ctx context.Context, group string) (bool, error)
}

Store represents an object that provides persistence for "groups" of options.

Directories

Path Synopsis
Package rndtest provides helpers for tests that invoke a randomizer.
Package rndtest provides helpers for tests that invoke a randomizer.

Jump to

Keyboard shortcuts

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