* feat(viewer): export a session to a self-contained HTML file (#1167)
The only renderer for a review session was the live viewer HTTP server, so
there was no way to archive a review as a CI artifact.
Adds viewer.ExportSession, which drives the same template and the same
LoadSession the HTTP handler does, but renders into an io.Writer with both
/static/ assets inlined. The assets are passed as template.CSS and
template.JS: html/template refuses to interpolate an untyped string into a
<style> or <script>, and would silently emit ZgotmplZ for the stylesheet and
a JSON string literal for the script. session.html gains three gates on a new
Static field, so the served page is unchanged — the field is zero for every
HTTP render — while the exported page inlines the assets and de-links the two
site-absolute breadcrumb anchors, which are dead over file://. style.css
widens nav.breadcrumb a to cover the .crumb span that replaces one of them.
Exposed as `ocr session export [session-id]`, on `session` rather than as a
`viewer --export` flag because `viewer` is cobra.NoArgs and session_cmd.go
already owns session-id resolution and completion. The id is optional and
defaults to the newest session: a successful `ocr review` never prints its
session id, so requiring one would push every CI archive step through
`--format json`. Output goes through the shared --output/-o writer, with
"html" added to isMachineReadable so the page is not run through
stripAnsiWriter, which would eat the ESC bytes in trace-quoted source. The
page is rendered fully into a buffer before the first write, so a failure
part-way through Execute cannot leave a truncated file behind.
Also adds maximumArgs, mirroring the existing minimumArgs, so the optional
positional reports the command's own usage rather than cobra's raw
"accepts at most 1 arg(s), received 2".
Documented in all five locales of cli-reference.md, including the warning
that the artifact embeds reviewed source.
Signed-off-by: ChethanUK <chethanuk@outlook.com>
* refactor(viewer): share the header brand between served and exported pages
Signed-off-by: ChethanUK <chethanuk@outlook.com>
* feat: Apply batched suggestions from code review
Co-authored-by: Kite <254839944+lizhengfeng101@users.noreply.github.com>
---------
Signed-off-by: ChethanUK <chethanuk@outlook.com>
Co-authored-by: Kite <254839944+lizhengfeng101@users.noreply.github.com>
Cobra's default message for a wrong positional-argument count ("accepts
2 arg(s), received 1") names neither the command nor what it expects, and
the root command sets SilenceUsage, so no usage block follows it. Running
"ocr config set provider" gave the user nothing to act on.
Add exactArgs and minimumArgs, drop-in replacements for cobra.ExactArgs
and cobra.MinimumNArgs that build the message from metadata the command
already declares: the positional signature in Use, plus Example and
ValidArgs where present. The guidance therefore cannot drift from the
command's own help output, and no command carries a hand-written error
string. This mirrors how flagErrorWithSuggestion handles the analogous
flag-error case.
Wire the seven commands that take positional arguments: config set,
config unset, rules check, session show, session comments, delegate rule
and completion. Exit codes are unchanged; only the message text differs.
The supplied count is deliberately not echoed back, since it adds nothing
the user cannot see in the line they just typed.
A tree walk over the command tree fails if a command declaring positional
placeholders still reports the raw count message, so wiring a new command
to cobra.ExactArgs directly is caught by tests.
Fixes#890