Skip to content

Commit

Permalink
Documentation updates, marking internal TODOs, and version update. Ap…
Browse files Browse the repository at this point in the history
…proaching 1.0 :)
  • Loading branch information
DaltonSW committed Aug 14, 2024
1 parent 26e8417 commit dfc0400
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 27 deletions.
46 changes: 44 additions & 2 deletions cmd/aocli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,56 @@ It is implemented with rate limiting and local caching to ensure we're not hitti

## Available Commands

Syntax Example: `aocli command_name <RequiredParam> [OptionalParam] -optionOne valueOne -x`

### `get`

Allows you to get the user input for a given year and day. Either passed in as parameters, or attempted to be derived from the current directory.
Allows you to get the user input for a given year and day. Can be passed in as parameters. If not passed in, will attempt to be derived from the current directory.

Syntax: `aocli get [year] [day]`

[![aocli get demo](https://asciinema.org/a/lduYJUOBrHWqwe9UieBHX9hU4.svg)](https://asciinema.org/a/lduYJUOBrHWqwe9UieBHX9hU4?autoplay=1)

### `view`

Allows you to view the puzzle page for a given year and day. Either passed in as parameters, or attempted to be derived from the current directory.
Allows you to view the puzzle page for a given year and day. Can be passed in as parameters. If not passed in, will attempt to be derived from the current directory.

Syntax: `aocli view [year] [day]`

[![aocli view demo](https://asciinema.org/a/bq5KqnHaY8ozybzxTGIAWFM8Z.svg)](https://asciinema.org/a/bq5KqnHaY8ozybzxTGIAWFM8Z?autoplay=1)

### `leaderboard`

Allows you to view the leaderboard for a given year, or given year + day. Passed in as parameters.

Syntax: `aocli leaderboard <year> [day]`

[![aocli leaderboard demo](https://asciinema.org/a/misVkiiAbGsJb0xq1iq3WXhfk.svg)](https://asciinema.org/a/misVkiiAbGsJb0xq1iq3WXhfk?autoplay=1)

### `submit`

This exists! Need to document it!

### `check-update`

Will check the internal version against the latest GitHub repo release to see if there's a new version available.

`aocli check-update`

### `update`

Will attempt to download and install the newest version of `aocli` in-place, if there is one newer.

`aocli update`

### `reload`

Will reload the contents of the puzzle page for a given year and day. Can be passed in as parameters. If not passed in, will attempt to be derived from the current directory.

Syntax: `aocli reload [year] [day]`

### `clear-user`

Will clear the stored information for the user in the session token file, or AOC_SESSION_TOKEN environment variable.

`aocli clear-user`
52 changes: 28 additions & 24 deletions cmd/aocli/aocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,16 @@ func main() {
submit(args, user)
case "leaderboard":
leaderboard(args)
case "load-user":
loadUser(args, user)
// case "load-user":
// loadUser(args, user)
case "reload":
reload(args, user)
// case "run":
// run(args)
case "view":
view(args, user)
case "test":
test(user)
case "testTwo":
testTwo()
// case "test":
// test(user)
case "clear-user":
clearUser(user)
case "update":
Expand Down Expand Up @@ -227,11 +225,19 @@ func get(args []string, user *resources.User) {
return
}

// TODO: Handle days as well

// `leaderboard [year] [day]` command
// `leaderboard year [day]` command
// Desc: Gets leaderboard information for a specific year or day
// Params:
//
// year - 2 or 4 digit year (16 or 2016)
// [day] - 1 or 2 digit day (1, 01, 21)
func leaderboard(args []string) {
year, _ := utils.ParseYear(args[2])
// TODO: Validation and help message
year, err := utils.ParseYear(args[2])
if err != nil {
log.Fatal("Error parsing year!", "err", err)
}

var lb resources.ViewableLB
if len(args) == 4 {
day, _ := utils.ParseDay(args[3])
Expand Down Expand Up @@ -309,6 +315,8 @@ func loadUser(args []string, user *resources.User) {
}
}

// TODO: Document

// `submit [answer] -y <yyyy> -d <dd>` command
func submit(args []string, user *resources.User) {
year, day, err := utils.GetYearAndDayFromCWD()
Expand All @@ -322,6 +330,7 @@ func submit(args []string, user *resources.User) {

answerResp, message := puzzle.SubmitAnswer(answer)

// TODO: Move these styles to the 'styles' package
if answerResp == resources.CorrectAnswer {
correctStyle := lipgloss.NewStyle().Background(lipgloss.Color("34"))
fmt.Println(correctStyle.Render("Correct answer!"))
Expand All @@ -338,6 +347,7 @@ func submit(args []string, user *resources.User) {
}
}

// TODO: Document
func reload(args []string, user *resources.User) {
var year int
var day int
Expand Down Expand Up @@ -365,6 +375,7 @@ func reload(args []string, user *resources.User) {
puzzle.ReloadPuzzleData()
}

// TODO: Implement
func run(args []string) {

}
Expand All @@ -379,24 +390,22 @@ func view(args []string, user *resources.User) {
if len(args) < 4 {
year, day, err = utils.GetYearAndDayFromCWD()
if err != nil {
log.Fatal("Unable to parse year/day from current directory.")
log.Fatal("Unable to parse year/day from current directory.", "err", err)
}
} else {
year, err = utils.ParseYear(args[2])
if err != nil {
log.Fatal("Unable to parse year from current directory.")
log.Fatal("Unable to parse year from current directory.", "err", err)
}

day, err = utils.ParseDay(args[3])
if err != nil {
log.Fatal("Unable to parse day from current directory.")
log.Fatal("Unable to parse day from current directory.", "err", err)
}
}

puzzle := resources.LoadOrCreatePuzzle(year, day, user.GetToken())
// userInput, _ := puzzle.GetUserInput()
puzzle.Display()
// tui.NewPuzzleViewport(puzzle.GetPrettyPageData(), puzzle.Title, puzzle.URL, userInput)
}

// `health` command
Expand All @@ -412,12 +421,7 @@ func health() {

// Command: `test`
// Desc: Does whatever I need to test at the time :)
func test(user *resources.User) {
lb := resources.NewDayLB(2016, 1)
resources.NewLeaderboardViewport(lb.GetContent(), lb.GetTitle())
}

func testTwo() {
lb := resources.NewYearLB(2016)
resources.NewLeaderboardViewport(lb.GetContent(), lb.GetTitle())
}
// func test(user *resources.User) {
// lb := resources.NewDayLB(2016, 1)
// resources.NewLeaderboardViewport(lb.GetContent(), lb.GetTitle())
// }
4 changes: 4 additions & 0 deletions cmd/aocli/helptext.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"github.com/charmbracelet/lipgloss"
)

// TODO: Move styles to 'styles' package

// TODO: Make sure documentation here is accurate as of v1.0

var NameStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#FF0000"))
var UseStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#00FFFF"))
var DescStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#FFFF00"))
Expand Down
2 changes: 2 additions & 0 deletions cmd/aocli/module_docs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: Update all of this too

// Copyright 2024 Dalton Williams
// Use of this source code is governed by GPL v2 license,
// which can be found in the repository's LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion cmd/aocli/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// Internally tracked version to compare against GitHub releases
const currentVersion = "v0.9.2"
const currentVersion = "v0.9.3"
const repoURL = "https://api.github.com/repos/DaltonSW/aocGo/releases/latest"

type githubRelease struct {
Expand Down

0 comments on commit dfc0400

Please sign in to comment.