Skip to content

Split the commands package into one package per structural part - #18

Merged
siliconwitch merged 3 commits into
mainfrom
dev
Aug 20, 2026
Merged

Split the commands package into one package per structural part#18
siliconwitch merged 3 commits into
mainfrom
dev

Conversation

@siliconwitch

Copy link
Copy Markdown
Member

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.

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.
@siliconwitch
siliconwitch merged commit 7c03410 into main Aug 20, 2026
1 check passed
@siliconwitch
siliconwitch deleted the dev branch August 20, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant