From dfc040064a8d40ba2617eb78bba1d306ac26c42f Mon Sep 17 00:00:00 2001 From: Dalton Williams Date: Tue, 13 Aug 2024 21:45:20 -0500 Subject: [PATCH] Documentation updates, marking internal TODOs, and version update. Approaching 1.0 :) --- cmd/aocli/README.md | 46 +++++++++++++++++++++++++++++++++-- cmd/aocli/aocli.go | 52 +++++++++++++++++++++------------------- cmd/aocli/helptext.go | 4 ++++ cmd/aocli/module_docs.go | 2 ++ cmd/aocli/updater.go | 2 +- 5 files changed, 79 insertions(+), 27 deletions(-) diff --git a/cmd/aocli/README.md b/cmd/aocli/README.md index f7cfaa9..fcf65f7 100644 --- a/cmd/aocli/README.md +++ b/cmd/aocli/README.md @@ -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 [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 [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` diff --git a/cmd/aocli/aocli.go b/cmd/aocli/aocli.go index 74d7923..f33f7da 100644 --- a/cmd/aocli/aocli.go +++ b/cmd/aocli/aocli.go @@ -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": @@ -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]) @@ -309,6 +315,8 @@ func loadUser(args []string, user *resources.User) { } } +// TODO: Document + // `submit [answer] -y -d
` command func submit(args []string, user *resources.User) { year, day, err := utils.GetYearAndDayFromCWD() @@ -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!")) @@ -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 @@ -365,6 +375,7 @@ func reload(args []string, user *resources.User) { puzzle.ReloadPuzzleData() } +// TODO: Implement func run(args []string) { } @@ -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 @@ -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()) +// } diff --git a/cmd/aocli/helptext.go b/cmd/aocli/helptext.go index e8b922a..d8a3d68 100644 --- a/cmd/aocli/helptext.go +++ b/cmd/aocli/helptext.go @@ -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")) diff --git a/cmd/aocli/module_docs.go b/cmd/aocli/module_docs.go index 3f3ea86..b353ca0 100644 --- a/cmd/aocli/module_docs.go +++ b/cmd/aocli/module_docs.go @@ -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. diff --git a/cmd/aocli/updater.go b/cmd/aocli/updater.go index 6ce2794..73808bb 100644 --- a/cmd/aocli/updater.go +++ b/cmd/aocli/updater.go @@ -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 {