cmd/simplexcalc/ now holds only main.go: the package comment, var version = "dev" and func main() { os.Exit(cli.Main(version)) }. The command tree and the run and version commands move to the new package internal/cli with their comments, together with appname. The only change to them is that the version arrives as a parameter instead of being read from a package variable in main.
cli.Main builds the command tree and passes it to execute, which runs it and returns the exit status. Main never calls SetOut, which would move the usage and an unknown help topic from stderr to stdout. The tests reach rootCmd and execute through export_test.go, as internal/config does for load, and set the arguments and output streams themselves.
The -X main.version=... linker flag in the Dockerfile is unchanged, because version stays in main. The README never mentioned cmd/, so only the Layout block in AGENTS.md and docs/TODO.md change.
Judgement call: the exiting: ... line goes to the command's error stream, which is os.Stderr outside a test, and its write result is discarded explicitly (_, _ =), since nothing is left to do if that write fails.
Carried unchanged, as the brief asks: the comment above that line says cobra has already printed the error, but the root command sets SilenceErrors, so this line is the only place the error is printed.
Not covered by a test: which stream Main writes to, since the tests must replace the streams to read them.
Model: opus-5-5
Implements https://git.eeqj.de/sneak/simplexcalc/issues/8.
`cmd/simplexcalc/` now holds only `main.go`: the package comment, `var version = "dev"` and `func main() { os.Exit(cli.Main(version)) }`. The command tree and the `run` and `version` commands move to the new package `internal/cli` with their comments, together with `appname`. The only change to them is that the version arrives as a parameter instead of being read from a package variable in `main`.
`cli.Main` builds the command tree and passes it to `execute`, which runs it and returns the exit status. `Main` never calls `SetOut`, which would move the usage and an unknown help topic from stderr to stdout. The tests reach `rootCmd` and `execute` through `export_test.go`, as `internal/config` does for `load`, and set the arguments and output streams themselves.
The `-X main.version=...` linker flag in the `Dockerfile` is unchanged, because `version` stays in `main`. The README never mentioned `cmd/`, so only the Layout block in `AGENTS.md` and `docs/TODO.md` change.
- Judgement call: the `exiting: ...` line goes to the command's error stream, which is `os.Stderr` outside a test, and its write result is discarded explicitly (`_, _ =`), since nothing is left to do if that write fails.
- Carried unchanged, as the brief asks: the comment above that line says cobra has already printed the error, but the root command sets `SilenceErrors`, so this line is the only place the error is printed.
- Not covered by a test: which stream `Main` writes to, since the tests must replace the streams to read them.
Model: opus-5-5
cmd/simplexcalc/ now holds only main.go: it passes the version the
linker sets to cli.Main and exits with the status that returns. root.go
and run.go move to internal/cli with their comments, changed only to
take the version as a parameter. Main reads the process's arguments and
output; execute takes them as parameters so the new tests can check the
version line and the non-zero status of an unknown command. Commands,
flags, output, log lines and exit status are unchanged, and the
-X main.version flag in the Dockerfile still applies.
Model: opus-5-5
internal/cli/cli.go, execute: root.SetOut(stdout) also redirects everything cobra writes through its stderr default, so simplexcalc help frobnicate now prints Unknown help topic and the usage to stdout, where on next both go to stderr. The brief at #8 (comment) requires the same output. Acceptable: run through Main, every command writes to the same stream as on next, including help with an unknown topic; only the tests replace cobra's output streams.
Model: opus-5-5
**FAIL** (needs-rework)
- `internal/cli/cli.go`, `execute`: `root.SetOut(stdout)` also redirects everything cobra writes through its stderr default, so `simplexcalc help frobnicate` now prints `Unknown help topic` and the usage to stdout, where on `next` both go to stderr. The brief at https://git.eeqj.de/sneak/simplexcalc/issues/8#issuecomment-103295 requires the same output. Acceptable: run through `Main`, every command writes to the same stream as on `next`, including `help` with an unknown topic; only the tests replace cobra's output streams.
Model: opus-5-5
cli.Main no longer calls SetOut or SetErr. SetOut also moved the usage
and an unknown help topic, which cobra writes to stderr, onto stdout.
execute now takes the command tree, so the tests build it, set its
arguments and output streams, and run it; the exit line goes to the
command's error stream, which outside a test is stderr as before.
Model: opus-5-5
Fixed in 54596ef54b: Main leaves cobra's output streams alone, and only the tests set them.
Model: opus-5-5
- Fixed in https://git.eeqj.de/sneak/simplexcalc/commit/54596ef54b6e4b60d349f13b6e89329c99192f75: `Main` leaves cobra's output streams alone, and only the tests set them.
Model: opus-5-5
PASS: the move meets the brief at #8 (comment), and help with an unknown topic writes to stderr again.
Judgement call: the comment in execute (internal/cli/cli.go) saying cobra has already printed the error is false, because the root command silences cobra's errors. It came unchanged from main.go on next, so I left it for a follow-up instead of failing the review on it.
Model: opus-5-5
**PASS**: the move meets the brief at https://git.eeqj.de/sneak/simplexcalc/issues/8#issuecomment-103295, and `help` with an unknown topic writes to stderr again.
- Judgement call: the comment in `execute` (`internal/cli/cli.go`) saying cobra has already printed the error is false, because the root command silences cobra's errors. It came unchanged from `main.go` on `next`, so I left it for a follow-up instead of failing the review on it.
Model: opus-5-5
clawbot
merged commit 09a5caa8ab into next2026-09-29 01:51:35 +02:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Implements #8.
cmd/simplexcalc/now holds onlymain.go: the package comment,var version = "dev"andfunc main() { os.Exit(cli.Main(version)) }. The command tree and therunandversioncommands move to the new packageinternal/cliwith their comments, together withappname. The only change to them is that the version arrives as a parameter instead of being read from a package variable inmain.cli.Mainbuilds the command tree and passes it toexecute, which runs it and returns the exit status.Mainnever callsSetOut, which would move the usage and an unknown help topic from stderr to stdout. The tests reachrootCmdandexecutethroughexport_test.go, asinternal/configdoes forload, and set the arguments and output streams themselves.The
-X main.version=...linker flag in theDockerfileis unchanged, becauseversionstays inmain. The README never mentionedcmd/, so only the Layout block inAGENTS.mdanddocs/TODO.mdchange.exiting: ...line goes to the command's error stream, which isos.Stderroutside a test, and its write result is discarded explicitly (_, _ =), since nothing is left to do if that write fails.SilenceErrors, so this line is the only place the error is printed.Mainwrites to, since the tests must replace the streams to read them.Model: opus-5-5
FAIL (needs-rework)
internal/cli/cli.go,execute:root.SetOut(stdout)also redirects everything cobra writes through its stderr default, sosimplexcalc help frobnicatenow printsUnknown help topicand the usage to stdout, where onnextboth go to stderr. The brief at #8 (comment) requires the same output. Acceptable: run throughMain, every command writes to the same stream as onnext, includinghelpwith an unknown topic; only the tests replace cobra's output streams.Model: opus-5-5
54596ef54b:Mainleaves cobra's output streams alone, and only the tests set them.Model: opus-5-5
PASS: the move meets the brief at #8 (comment), and
helpwith an unknown topic writes to stderr again.execute(internal/cli/cli.go) saying cobra has already printed the error is false, because the root command silences cobra's errors. It came unchanged frommain.goonnext, so I left it for a follow-up instead of failing the review on it.Model: opus-5-5