-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
72 lines (61 loc) · 1.67 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* -----------------------------------------------------------------------------
* Copyright (c) Nimble Bun Works. All rights reserved.
* This software is licensed under the MIT license.
* See the LICENSE file for further information.
* -------------------------------------------------------------------------- */
package main
import (
"log"
"os"
"pkg.nimblebun.works/wordle-cli/common"
"pkg.nimblebun.works/wordle-cli/game"
"pkg.nimblebun.works/wordle-cli/words"
tea "github.com/charmbracelet/bubbletea"
"github.com/urfave/cli/v2"
)
func startGame(word string, gameType common.GameType, id int) error {
model := game.NewGame(word, gameType, id)
program := tea.NewProgram(model, tea.WithAltScreen())
return program.Start()
}
func startOfficial(c *cli.Context) error {
word, id := words.GetOfficialWordOfTheDay()
return startGame(word, common.GameTypeOfficial, id)
}
func startDaily(c *cli.Context) error {
word, id := words.GetWordOfTheDay()
return startGame(word, common.GameTypeDaily, id)
}
func startRandom(c *cli.Context) error {
word, id := words.GetRandomWordle()
return startGame(word, common.GameTypeRandom, id)
}
func main() {
app := &cli.App{
Name: "wordle-cli",
Usage: "play wordle in your terminal",
Action: startOfficial,
Version: "1.0.9",
Commands: []*cli.Command{
{
Name: "official",
Usage: "play official wordle of the day",
Action: startOfficial,
},
{
Name: "daily",
Usage: "play the CLI's wordle of the day",
Action: startDaily,
},
{
Name: "random",
Usage: "play a random wordle",
Action: startRandom,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}