Files
HackBrowserData/internal/app/report.go
T
Roger 7e6f325508 refactor(app): per-stage inputs and per-dir planning (#689)
* refactor(app): per-command flags and per-stage inputs

One Options bag fed every stage and cmd patched restore's keys into it after validation; each stage now takes what it
reads, dir-level failures are their own type, and cmd prints what a run exported.

* refactor(app): group the plan by dir and profile

Execute now walks the plan's own shape instead of filtering a flat list and looking profiles up by name.

* refactor(app): file code by command and stage

Pure moves: each command's flags and validation sit beside its stage, and execute.go keeps only the runner.

* refactor: read the keychain password in cmd

Prompting and reading stdin are terminal work, so app now receives the password func; cobra already rejects both flags.

* refactor(app): plan each user data dir right before it runs

A run-wide Plan had to drop its extractors and rebuild them with the keychain; per-dir planning keeps one extractor.
2026-11-09 17:25:36 +08:00

33 lines
930 B
Go

package app
import (
"fmt"
"io"
"text/tabwriter"
)
// Report prints a summary that is not part of the output contract and never changes the exit status.
func Report(writer io.Writer, summary Summary) error {
table := tabwriter.NewWriter(writer, 0, 0, 2, ' ', 0)
fmt.Fprintln(table, "Browser\tProfile\tCategory\tResult\tRecords\tDetail")
for _, failure := range summary.DirFailures {
fmt.Fprintf(table, "%s\t-\t-\t%s\t0\t%s\n", failure.UserDataDirID, OutcomeError, failure.Err)
}
for _, result := range summary.Results {
fmt.Fprintf(table, "%s\t%s\t%s\t%s\t%d\t%s\n",
result.UserDataDirID, result.ProfileName, result.Category, result.Outcome, result.Records, detail(result))
}
return table.Flush()
}
func detail(result Result) string {
switch {
case result.Err != nil:
return result.Err.Error()
case result.Failures > 0:
return fmt.Sprintf("%d not recovered", result.Failures)
default:
return ""
}
}