roll

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 5 Imported by: 0

README

🎲 Roll

Go Reference Latest Release Lint Test Go Report Card

A simple Go package and CLI for dice rolling.

⚡ Usage

How to use Roll as a CLI or a library

CLI

Installation via Go or Docker

# Go
go install github.com/brittonhayes/roll/cmd/roll
# Docker
docker run --rm -it ghcr.io/brittonhayes/roll:latest 1d6+2

Using the command line tool

# Run the CLI
Usage: roll <dice>

A simple CLI for dice rolling

Arguments:
  <dice>    Dice to roll +/- modifiers e.g. 'roll 1d6', 'roll 2d12+20', or 'roll 1d20-5'

Flags:
  -h, --help            Show context-sensitive help.
  -v, --verbose         Display verbose log output ($VERBOSE)
  -s, --skip-spinner    Skip loading spinner ($SKIP_SPINNER)

# Roll a D6
roll 1d6

# Roll with modifiers
roll 1d6+2

📺 Preview

asciicast

Package

Using the package

func main() {
	// Create a new d6
	d := roll.NewD6()

	// Roll the die
	fmt.Println("Rolling", d)
	result := d.Roll()

	// Print the result
	fmt.Println(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Die

type Die struct {
	Min int `validate:"ltfield=Max"`
	Max int `validate:"gtfield=Min"`
}

Die is the struct for all rollable dice types

func NewD6

func NewD6() *Die

NewD6 creates a new instance of the D6 dice type

func NewDie

func NewDie(min, max int) (*Die, error)

func (*Die) Roll

func (d *Die) Roll() int

Roll performs a roll of a single die

func (Die) String

func (d Die) String() string

String returns the string representation of the die

func (*Die) Validate

func (d *Die) Validate() error

Validate ensures that the Dice are in a valid configuration

type Rollable

type Rollable interface {
	Roll() int
}

Rollable is the offered interface by all dice

Directories

Path Synopsis
cmd
roll command

Jump to

Keyboard shortcuts

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