mirror of
https://github.com/onyx-and-iris/lottery-cli.git
synced 2026-08-17 00:34:25 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad882d0fc0 | |||
| fb13566543 | |||
| cdee9113de | |||
| 06f47b1f70 |
22
README.md
Normal file
22
README.md
Normal file
@@ -0,0 +1,22 @@
|
||||

|
||||

|
||||

|
||||
|
||||
# lottery
|
||||
|
||||
Play National Lottery games from your terminal.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 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
65
Taskfile.yaml
Normal 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}}'
|
||||
@@ -9,8 +9,9 @@ import (
|
||||
|
||||
"charm.land/huh/v2"
|
||||
"github.com/charmbracelet/fang"
|
||||
"github.com/onyx-and-iris/lottery-cli"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/onyx-and-iris/lottery-cli"
|
||||
)
|
||||
|
||||
var version string
|
||||
@@ -40,7 +41,7 @@ var cmd = &cobra.Command{
|
||||
Options(
|
||||
huh.NewOption("Lotto", "lotto"),
|
||||
huh.NewOption("EuroMillions", "euromillions"),
|
||||
huh.NewOption("SetForLife", "setforlife"),
|
||||
huh.NewOption("Set For Life", "setforlife"),
|
||||
huh.NewOption("Thunderball", "thunderball"),
|
||||
huh.NewOption("Powerball", "powerball"),
|
||||
).
|
||||
@@ -69,7 +70,11 @@ var cmd = &cobra.Command{
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
|
||||
"github.com/onyx-and-iris/lottery-cli"
|
||||
)
|
||||
|
||||
@@ -16,6 +17,7 @@ func formatNumberList(numbers []int) string {
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
// nolint:misspell
|
||||
func renderDraw(l lottery.Lottery) string {
|
||||
titleStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12"))
|
||||
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
|
||||
@@ -28,23 +30,62 @@ func renderDraw(l lottery.Lottery) string {
|
||||
switch game := l.(type) {
|
||||
case *lottery.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:
|
||||
title = "EuroMillions"
|
||||
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])))
|
||||
lines = append(lines, labelStyle.Render("Lucky Stars:")+" "+specialStyle.Render(formatNumberList(game.LuckyStars[:])))
|
||||
lines = append(
|
||||
lines,
|
||||
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
|
||||
)
|
||||
lines = append(
|
||||
lines,
|
||||
labelStyle.Render(
|
||||
"Lucky Stars:",
|
||||
)+" "+specialStyle.Render(
|
||||
formatNumberList(game.LuckyStars[:]),
|
||||
),
|
||||
)
|
||||
case *lottery.SetForLife:
|
||||
title = "Set For Life"
|
||||
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])))
|
||||
lines = append(lines, labelStyle.Render("Life Ball:")+" "+specialStyle.Render(strconv.Itoa(game.LifeBall)))
|
||||
lines = append(
|
||||
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:
|
||||
title = "Thunderball"
|
||||
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])))
|
||||
lines = append(lines, labelStyle.Render("Thunderball:")+" "+specialStyle.Render(strconv.Itoa(game.Thunderball)))
|
||||
lines = append(
|
||||
lines,
|
||||
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
|
||||
)
|
||||
lines = append(
|
||||
lines,
|
||||
labelStyle.Render(
|
||||
"Thunderball:",
|
||||
)+" "+specialStyle.Render(
|
||||
strconv.Itoa(game.Thunderball),
|
||||
),
|
||||
)
|
||||
case *lottery.Powerball:
|
||||
title = "Powerball"
|
||||
lines = append(lines, labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])))
|
||||
lines = append(lines, labelStyle.Render("Powerball:")+" "+specialStyle.Render(strconv.Itoa(game.Powerball)))
|
||||
lines = append(
|
||||
lines,
|
||||
labelStyle.Render("Main:")+" "+numbersStyle.Render(formatNumberList(game.Numbers[:])),
|
||||
)
|
||||
lines = append(
|
||||
lines,
|
||||
labelStyle.Render("Powerball:")+" "+specialStyle.Render(strconv.Itoa(game.Powerball)),
|
||||
)
|
||||
default:
|
||||
title = "Lottery"
|
||||
lines = append(lines, "Unknown lottery type")
|
||||
|
||||
BIN
img/draw.png
Executable file
BIN
img/draw.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
img/selectionprompt.png
Executable file
BIN
img/selectionprompt.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 5.8 KiB |
Reference in New Issue
Block a user