4 Commits

Author SHA1 Message Date
ad882d0fc0 lint fixes
make "Set For Life" easier to read.
2026-07-23 23:57:16 +01:00
fb13566543 upd README. 2026-07-23 23:49:48 +01:00
cdee9113de add README + img/ 2026-07-23 23:41:19 +01:00
06f47b1f70 add taskfile 2026-07-23 23:40:58 +01:00
6 changed files with 145 additions and 12 deletions

22
README.md Normal file
View File

@@ -0,0 +1,22 @@
![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)
![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)
![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0)
# lottery
Play National Lottery games from your terminal.
![Selection Prompt](./img/selectionprompt.png)
![Draw](./img/draw.png)
## Install
```console
go install github.com/onyx-and-iris/lottery-cli/cmd/lottery@latest
```
## Special Thanks
- [spf13](https://github.com/spf13) for the [cobra](https://github.com/spf13/cobra) package.
- [Charm](https://github.com/charmbracelet) developers for the [fang](https://github.com/charmbracelet/fang), [lipgloss](https://github.com/charmbracelet/lipgloss) and [huh](https://github.com/charmbracelet/huh) packages.

65
Taskfile.yaml Normal file
View File

@@ -0,0 +1,65 @@
version: '3'
vars:
PROGRAM: lottery
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
BIN_DIR: bin
VERSION:
sh: 'git describe --tags $(git rev-list --tags --max-count=1)'
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
tasks:
default:
desc: Build the lottery project
cmds:
- task: build
build:
desc: Build the lottery project
deps: [vet]
cmds:
- task: build-windows
- task: build-linux
- task: build-macos
vet:
desc: Vet the code
deps: [fmt]
cmds:
- go vet ./...
fmt:
desc: Fmt the code
cmds:
- go fmt ./...
build-windows:
desc: Build the lottery project for Windows
cmds:
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
internal: true
build-linux:
desc: Build the lottery project for Linux
cmds:
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
internal: true
build-macos:
desc: Build the lottery project for macOS
cmds:
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
internal: true
test:
desc: Run tests
cmds:
- go test ./...
clean:
desc: Clean the build artifacts
cmds:
- '{{.SHELL}} rm -r {{.BIN_DIR}}'

View File

@@ -9,8 +9,9 @@ import (
"charm.land/huh/v2" "charm.land/huh/v2"
"github.com/charmbracelet/fang" "github.com/charmbracelet/fang"
"github.com/onyx-and-iris/lottery-cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/onyx-and-iris/lottery-cli"
) )
var version string var version string
@@ -40,7 +41,7 @@ var cmd = &cobra.Command{
Options( Options(
huh.NewOption("Lotto", "lotto"), huh.NewOption("Lotto", "lotto"),
huh.NewOption("EuroMillions", "euromillions"), huh.NewOption("EuroMillions", "euromillions"),
huh.NewOption("SetForLife", "setforlife"), huh.NewOption("Set For Life", "setforlife"),
huh.NewOption("Thunderball", "thunderball"), huh.NewOption("Thunderball", "thunderball"),
huh.NewOption("Powerball", "powerball"), huh.NewOption("Powerball", "powerball"),
). ).
@@ -69,7 +70,11 @@ var cmd = &cobra.Command{
} }
func main() { func main() {
if err := fang.Execute(context.Background(), cmd, fang.WithVersion(versionFromBuild())); err != nil { if err := fang.Execute(
context.Background(),
cmd,
fang.WithVersion(versionFromBuild()),
); err != nil {
os.Exit(1) os.Exit(1)
} }
} }

View File

@@ -5,6 +5,7 @@ import (
"strings" "strings"
"charm.land/lipgloss/v2" "charm.land/lipgloss/v2"
"github.com/onyx-and-iris/lottery-cli" "github.com/onyx-and-iris/lottery-cli"
) )
@@ -16,6 +17,7 @@ func formatNumberList(numbers []int) string {
return strings.Join(parts, " ") return strings.Join(parts, " ")
} }
// nolint:misspell
func renderDraw(l lottery.Lottery) string { func renderDraw(l lottery.Lottery) string {
titleStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12")) titleStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12"))
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("8")) labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
@@ -28,23 +30,62 @@ func renderDraw(l lottery.Lottery) string {
switch game := l.(type) { switch game := l.(type) {
case *lottery.Lotto: case *lottery.Lotto:
title = "Lotto" title = "Lotto"
lines = append(lines, labelStyle.Render("Numbers:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:]))) lines = append(
lines,
labelStyle.Render(
"Numbers:",
)+" "+numbersStyle.Render(
formatNumberList(game.Numbers[:]),
),
)
case *lottery.EuroMillions: case *lottery.EuroMillions:
title = "EuroMillions" title = "EuroMillions"
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:]))) lines = append(
lines = append(lines, labelStyle.Render("Lucky Stars:")+" "+specialStyle.Render(formatNumberList(game.LuckyStars[:]))) lines,
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
)
lines = append(
lines,
labelStyle.Render(
"Lucky Stars:",
)+" "+specialStyle.Render(
formatNumberList(game.LuckyStars[:]),
),
)
case *lottery.SetForLife: case *lottery.SetForLife:
title = "Set For Life" title = "Set For Life"
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:]))) lines = append(
lines = append(lines, labelStyle.Render("Life Ball:")+" "+specialStyle.Render(strconv.Itoa(game.LifeBall))) lines,
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
)
lines = append(
lines,
labelStyle.Render("Life Ball:")+" "+specialStyle.Render(strconv.Itoa(game.LifeBall)),
)
case *lottery.Thunderball: case *lottery.Thunderball:
title = "Thunderball" title = "Thunderball"
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:]))) lines = append(
lines = append(lines, labelStyle.Render("Thunderball:")+" "+specialStyle.Render(strconv.Itoa(game.Thunderball))) lines,
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
)
lines = append(
lines,
labelStyle.Render(
"Thunderball:",
)+" "+specialStyle.Render(
strconv.Itoa(game.Thunderball),
),
)
case *lottery.Powerball: case *lottery.Powerball:
title = "Powerball" title = "Powerball"
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:]))) lines = append(
lines = append(lines, labelStyle.Render("Powerball:")+" "+specialStyle.Render(strconv.Itoa(game.Powerball))) lines,
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
)
lines = append(
lines,
labelStyle.Render("Powerball:")+" "+specialStyle.Render(strconv.Itoa(game.Powerball)),
)
default: default:
title = "Lottery" title = "Lottery"
lines = append(lines, "Unknown lottery type") lines = append(lines, "Unknown lottery type")

BIN
img/draw.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
img/selectionprompt.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB