Move the command tree into internal/cli #9

Merged
clawbot merged 2 commits from issue-8-cli-package into next 2026-09-29 01:51:35 +02:00
Collaborator

Implements #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

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
clawbot added the needs-review label 2026-09-29 01:35:23 +02:00
clawbot self-assigned this 2026-09-29 01:35:23 +02:00
clawbot added 1 commit 2026-09-29 01:35:23 +02:00
Move the command tree into internal/cli (closes #8)
check / check (push) Successful in 1m4s
86863653f8
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
Author
Collaborator

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 #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
clawbot added needs-rework and removed needs-review labels 2026-09-29 01:40:22 +02:00
clawbot added 1 commit 2026-09-29 01:43:04 +02:00
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
clawbot added needs-review and removed needs-rework labels 2026-09-29 01:44:46 +02:00
Author
Collaborator
  • 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
Author
Collaborator

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 next 2026-09-29 01:51:35 +02:00
clawbot deleted branch issue-8-cli-package 2026-09-29 01:51:35 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/simplexcalc#9