Split the commands package into one package per structural part - #18
Merged
Conversation
Every command now takes a Session carrying the base url, version, http client, input, output and browser opener, so nothing reads or writes package-level state. TakeServerFlag returns the base rather than assigning it, and the eight mutable package vars are gone. Command matching, help rendering and the help and version answers move from main.go into internal/commands/dispatch.go, leaving main.go holding the version, the table and the wiring. Two shared helpers replace 21 copies of the server error relay and five copies of the --json argument split. The relay bounds its read, which member list did not. Polling now treats five seconds as the default for an absent interval rather than a floor over a provided one, and slow_down always adds five seconds, per RFC 8628 sections 3.2 and 3.5.
Errors now describe what happened rather than relaying transport failures, status lines and raw provider error identifiers. Help text follows the vocabulary: fleets and devices are released rather than factory reset, the button is the pairing button, and top-up is not payment. Three fixes behind that. Filtering a balance or key list by fleet said there were no fleets at all, deleting a fleet whose credit could not be read dropped the forfeit warning entirely, and one login failure printed a dangling colon. Adds the refusal and branch coverage that was missing, tests for the key and balance fetchers, and a table over dispatch, which nothing exercised.
internal/commands held all twenty-four commands, so nothing stopped one reaching into another and the layer split existed only in the filenames. Each part of the system named in the command table now has its own package: login, fleet, device, member, key and account. The four fetchers and the response types move down into internal/api, which is what removes the sideways calls: device claim needed fleet names, fleet delete needed balances. Argument handling and the command table move to internal/dispatch, callable from anywhere. Tests move with the code they cover, sharing internal/api/apitest. Splitting the packages also splits the test cache, so a change to one part no longer re-runs the login tests. Those wait real seconds for the poll interval, and -short now skips them. Verified identical to the previous commit across eighteen invocations, output and exit code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
internal/commands held all twenty-four commands, so nothing stopped one
reaching into another and the layer split existed only in the filenames. Each
part named in the command table now owns its package: login, fleet, device,
member, key and account. The four fetchers and their response types move down
into internal/api, which is what removes the sideways calls, and argument
handling and the command table move to internal/dispatch.
Every command now takes a Session carrying the base url, version, http client,
input, output and browser opener, so nothing reads or writes package-level
state, and the eight mutable package vars are gone. Two shared helpers replace
21 copies of the server error relay and five copies of the --json split. The
relay bounds its read, which member list did not.
Errors now describe what happened rather than relaying transport failures,
status lines and raw provider error identifiers, and help text follows the
vocabulary. Three fixes behind that: filtering a balance or key list by fleet
said there were no fleets at all, deleting a fleet whose credit could not be
read dropped the forfeit warning, and one login failure printed a dangling
colon. Polling now treats five seconds as the default for an absent interval
rather than a floor over a provided one, and slow_down always adds five
seconds, per RFC 8628 sections 3.2 and 3.5.
Tests move with the code they cover and share internal/api/apitest. The split
also splits the test cache, so a change to one part no longer re-runs the login
tests, and -short skips them.
No version change, and nothing under .github, flake.nix, .goreleaser.yaml or
go.mod is touched.