cli: maturity polish — color, error translation, tabwriter consistency
Adds three small but high-leverage presentation tweaks for v0.1: 1. internal/cli/style is a new ~70 LOC package with Pass/Fail/Warn/ Dim/Bold helpers. Each is TTY-gated and obeys NO_COLOR. No external dep. Wired into the doctor PASS/FAIL/WARN status, the "banger:" error prefix on stderr, and the dim 'ready in <elapsed>' line. 2. internal/cli/errors translates rpc.ErrorResponse into user-facing text. operation_failed becomes invisible (the message wins); not_found, already_exists, bad_request, bad_version, unauthorized, unknown_method get short labels; unknown codes pass through. The daemon-attached op_id lands in dim parens — paste into journalctl --grep to find the daemon log line that produced the failure. 3. Tabwriter config converges on (0, 8, 2, ' ', 0) across every list/table command. The vm prune confirmation table picked up the right config; system install + system status switched from bare "key: value\n" lines to tabular form. printVMSpecLine drops its Unicode middle dot for an ASCII '|' so terminals without UTF-8 render cleanly. Tests cover translateRPCError for every code, style helpers no-op on non-TTY and under NO_COLOR. Smoke status greps switch from "key: value" to "key value" to match the new format. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e47b8146dc
commit
71a332a6a1
11 changed files with 358 additions and 28 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"banger/internal/buildinfo"
|
||||
"banger/internal/installmeta"
|
||||
|
|
@ -190,8 +191,16 @@ func (d *deps) runSystemInstall(ctx context.Context, out io.Writer, ownerFlag st
|
|||
if err := d.waitForDaemonReady(ctx, installmeta.DefaultSocketPath); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprintf(out, "installed\nowner: %s\nsocket: %s\nhelper_socket: %s\nservice: %s\nhelper_service: %s\n", meta.OwnerUser, installmeta.DefaultSocketPath, installmeta.DefaultRootHelperSocketPath, installmeta.DefaultService, installmeta.DefaultRootHelperService)
|
||||
return err
|
||||
if _, err := fmt.Fprintln(out, "installed"); err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(out, 0, 8, 2, ' ', 0)
|
||||
fmt.Fprintf(w, "owner\t%s\n", meta.OwnerUser)
|
||||
fmt.Fprintf(w, "socket\t%s\n", installmeta.DefaultSocketPath)
|
||||
fmt.Fprintf(w, "helper_socket\t%s\n", installmeta.DefaultRootHelperSocketPath)
|
||||
fmt.Fprintf(w, "service\t%s\n", installmeta.DefaultService)
|
||||
fmt.Fprintf(w, "helper_service\t%s\n", installmeta.DefaultRootHelperService)
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
func (d *deps) runSystemStatus(ctx context.Context, out io.Writer) error {
|
||||
|
|
@ -212,17 +221,28 @@ func (d *deps) runSystemStatus(ctx context.Context, out io.Writer) error {
|
|||
if helperEnabled == "" {
|
||||
helperEnabled = "unknown"
|
||||
}
|
||||
fmt.Fprintf(out, "service: %s\nenabled: %s\nactive: %s\nhelper_service: %s\nhelper_enabled: %s\nhelper_active: %s\nsocket: %s\nhelper_socket: %s\nlog: journalctl -u %s -u %s\n",
|
||||
installmeta.DefaultService, enabled, active,
|
||||
installmeta.DefaultRootHelperService, helperEnabled, helperActive,
|
||||
layout.SocketPath, installmeta.DefaultRootHelperSocketPath,
|
||||
installmeta.DefaultService, installmeta.DefaultRootHelperService)
|
||||
w := tabwriter.NewWriter(out, 0, 8, 2, ' ', 0)
|
||||
fmt.Fprintf(w, "service\t%s\n", installmeta.DefaultService)
|
||||
fmt.Fprintf(w, "enabled\t%s\n", enabled)
|
||||
fmt.Fprintf(w, "active\t%s\n", active)
|
||||
fmt.Fprintf(w, "helper_service\t%s\n", installmeta.DefaultRootHelperService)
|
||||
fmt.Fprintf(w, "helper_enabled\t%s\n", helperEnabled)
|
||||
fmt.Fprintf(w, "helper_active\t%s\n", helperActive)
|
||||
fmt.Fprintf(w, "socket\t%s\n", layout.SocketPath)
|
||||
fmt.Fprintf(w, "helper_socket\t%s\n", installmeta.DefaultRootHelperSocketPath)
|
||||
fmt.Fprintf(w, "log\tjournalctl -u %s -u %s\n", installmeta.DefaultService, installmeta.DefaultRootHelperService)
|
||||
if ping, err := d.daemonPing(ctx, layout.SocketPath); err == nil {
|
||||
info := buildinfo.Normalize(ping.Version, ping.Commit, ping.BuiltAt)
|
||||
_, err = fmt.Fprintf(out, "pid: %d\n%s", ping.PID, formatBuildInfoBlock(info))
|
||||
return err
|
||||
fmt.Fprintf(w, "pid\t%d\n", ping.PID)
|
||||
fmt.Fprintf(w, "version\t%s\n", info.Version)
|
||||
if info.Commit != "" {
|
||||
fmt.Fprintf(w, "commit\t%s\n", info.Commit)
|
||||
}
|
||||
if info.BuiltAt != "" {
|
||||
fmt.Fprintf(w, "built_at\t%s\n", info.BuiltAt)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
func (d *deps) runSystemUninstall(ctx context.Context, out io.Writer, purge bool) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue