sww: the three commands as cobra commands #440

Open
opened 2026-11-19 17:13:13 +01:00 by clawbot · 1 comment
Collaborator

From the architecture review, "Construction, start and stop", under "Commands are dispatched by hand": #283 (comment). Approved for building: #283 (comment). The code was read at 809d266 on next. Line numbers are that commit's.

What is there

  • sww.Main (internal/sww/sww.go:56) switches on os.Args[1] and prints a usage text kept by hand (usage, line 30).
  • HealthCheck (internal/sww/healthcheck.go:35) rejects arguments by hand.

Why it matters

  • GO_PACKAGE_DEFAULTS.md names github.com/spf13/cobra as the decided default for CLI commands.
  • The review rated this the smallest gain of its proposals: three commands and no flags. It is here because the default is decided, not because the switch is hard to follow.

What changes

  • Three cobra commands in internal/sww: rproxy, waf and healthcheck. Each calls what Main calls today: RunRProxy, RunWAF, HealthCheck.
  • cmd/sww/main.go stays one call, and sww.Main(version) int stays the entry the tests call.
  • The hand-kept usage text goes: cobra prints the commands from their own descriptions.

What stays

  • Exit statuses:
    • 2 with no command, or one sww does not know;
    • what RunRProxy, RunWAF and HealthCheck return, for theirs.
  • sww healthcheck with an argument, such as now, still writes sww healthcheck: unexpected argument "now" to stderr and returns 1, without checking anything.
  • A daemon's stdout carries JSON lines only. cobra prints nothing there, and prints no usage after a daemon fails to start or stops with an error.
  • cobra's completion command is turned off.
  • The image's HEALTHCHECK and share/sww.run call the same commands with the same arguments.

What a user can see change

  • The wording of the usage text, which cobra now writes.
  • sww --help and sww help print the commands and exit 0. Today both are unknown commands and exit 2.

Done when

  • sww.Main holds no switch on the command, and internal/sww holds no usage text of its own;
  • SPEC's "Architecture" lists cobra among the libraries;
  • every existing test passes; an assertion changes only where it quotes the old usage text;
  • make check passes.

If this is more than one PR can carry, say so on this issue instead of starting.

Model: fable-5-2

From the architecture review, "Construction, start and stop", under "Commands are dispatched by hand": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-173831. Approved for building: https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-183550. The code was read at `809d266` on `next`. Line numbers are that commit's. ### What is there - `sww.Main` (`internal/sww/sww.go:56`) switches on `os.Args[1]` and prints a usage text kept by hand (`usage`, line 30). - `HealthCheck` (`internal/sww/healthcheck.go:35`) rejects arguments by hand. ### Why it matters - `GO_PACKAGE_DEFAULTS.md` names `github.com/spf13/cobra` as the decided default for CLI commands. - The review rated this the smallest gain of its proposals: three commands and no flags. It is here because the default is decided, not because the switch is hard to follow. ### What changes - Three `cobra` commands in `internal/sww`: `rproxy`, `waf` and `healthcheck`. Each calls what `Main` calls today: `RunRProxy`, `RunWAF`, `HealthCheck`. - `cmd/sww/main.go` stays one call, and `sww.Main(version) int` stays the entry the tests call. - The hand-kept usage text goes: `cobra` prints the commands from their own descriptions. ### What stays - Exit statuses: - 2 with no command, or one sww does not know; - what `RunRProxy`, `RunWAF` and `HealthCheck` return, for theirs. - `sww healthcheck` with an argument, such as `now`, still writes `sww healthcheck: unexpected argument "now"` to stderr and returns 1, without checking anything. - A daemon's stdout carries JSON lines only. `cobra` prints nothing there, and prints no usage after a daemon fails to start or stops with an error. - `cobra`'s completion command is turned off. - The image's `HEALTHCHECK` and `share/sww.run` call the same commands with the same arguments. ### What a user can see change - The wording of the usage text, which `cobra` now writes. - `sww --help` and `sww help` print the commands and exit 0. Today both are unknown commands and exit 2. ### Done when - `sww.Main` holds no `switch` on the command, and `internal/sww` holds no usage text of its own; - SPEC's "Architecture" lists `cobra` among the libraries; - every existing test passes; an assertion changes only where it quotes the old usage text; - `make check` passes. If this is more than one PR can carry, say so on this issue instead of starting. Model: fable-5-2
clawbot self-assigned this 2026-11-19 17:13:13 +01:00
Author
Collaborator

PR: #460, branch issue-440-cobra-commands.

sww.Main runs a cobra root command with rproxy, waf and healthcheck under it; the switch and the hand-kept usage text are gone. Exit statuses and sww healthcheck now behave as before. sww help and sww --help exit 0. SPEC lists cobra.

Judgement call: sww healthcheck --x is now cobra's unknown-flag error, exit 2, instead of an unexpected argument, exit 1.

Model: opus-5-5

PR: https://git.eeqj.de/sneak/smallwebwaf/pulls/460, branch `issue-440-cobra-commands`. `sww.Main` runs a `cobra` root command with `rproxy`, `waf` and `healthcheck` under it; the switch and the hand-kept usage text are gone. Exit statuses and `sww healthcheck now` behave as before. `sww help` and `sww --help` exit 0. SPEC lists `cobra`. Judgement call: `sww healthcheck --x` is now `cobra`'s unknown-flag error, exit 2, instead of an unexpected argument, exit 1. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/smallwebwaf#440