Skip to content

Improve output formatting for databases commands#1565

Open
kdhillon-stripe wants to merge 1 commit into
masterfrom
kdhillon/stripedb-output-polish
Open

Improve output formatting for databases commands#1565
kdhillon-stripe wants to merge 1 commit into
masterfrom
kdhillon/stripedb-output-polish

Conversation

@kdhillon-stripe
Copy link
Copy Markdown
Contributor

@kdhillon-stripe kdhillon-stripe commented Apr 28, 2026

Summary

Updates the pretty-print output for all stripe databases commands to be more scannable and consistent.

  • List: cleaner table with colored status indicators (● Active, ○ Backfilling), Unicode separators, muted secondary columns
  • Create: progress steps after provisioning, bold cyan connection detail labels, password warning, dashboard link, privacy/terms notice
  • Retrieve: split into two sections (instance metadata + connection details), View in Dashboard with clickable URL on supporting terminals
  • Delete / Users commands: consistent leading/trailing blank lines, green success messages, full IDs shown (no truncation)

Changes

  • New tableColumn + printTable abstraction replaces printAlignedTable — each column owns its data extraction and styling, no more parallel arrays
  • visualWidth() strips ANSI sequences before measuring column padding so colored cells align correctly
  • databaseUnicodeSupported() gates Unicode glyphs on Windows (falls back to ASCII on cmd.exe, passes through on Windows Terminal)
  • databaseWarningGlyph() and databaseRelativeTimeAgo() helpers eliminate duplication
  • OSC-8 hyperlinks on dashboard and privacy URLs (clickable in iTerm2, VS Code terminal, Windows Terminal; plain text fallback elsewhere)

Test plan

  • go test ./pkg/cmd/resource/ -run TestDatabase passes
  • built the CLI and tested commands individually

Visual overhaul of all `stripe databases` commands to match design spec:

Table (list):
- Remove Host column; show ID and colored status indicators (● Active, ○ Backfilling)
- Unicode ─ separators with ASCII fallback on Windows
- Bold white headers, muted ID column
- Name column commented out pending API display_name field

Retrieve:
- Split into two blocks: instance metadata (Status, API Version, Mode, Created)
  then Connection details (Host, Port, Database)
- "View in Dashboard:" in muted text with indented clickable URL
- Full database ID always shown (no truncation)

Create:
- Progress steps (✓ Provisioned, ✓ Generated credentials, ○ Syncing data...)
  with 30ms staggered display and correct color tokens
- Password warning uses em dash: "Save this password now — it will not be shown again."
- Dashboard URL uses /test/ prefix for test-mode databases
- Current status line: status colored by value, retrieve command in cyan
- Legal disclaimer with "Privacy Policy" and "Preview Terms" in bold,
  surrounding text faint; privacy/terms URLs as clickable OSC-8 links

General:
- Every command output starts and ends with a blank line
- Delete confirmation prompt includes ⚠ glyph and leading blank line
- Phrase changed to "delete database"
- Users retrieve: full IDs shown (no truncation)
- Users delete: clean "Deleted {id}" without parenthetical name
- textBoldCyan labels throughout connection detail blocks
- tableColumn abstraction replaces printAlignedTable for cleaner column definitions
- databaseUnicodeSupported() gates Unicode glyphs on Windows

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
@kdhillon-stripe kdhillon-stripe force-pushed the kdhillon/stripedb-output-polish branch from 7dea20d to 9b4c11a Compare April 28, 2026 20:56
Comment on lines +1064 to +1065
func printTable(out io.Writer, columns []tableColumn, rowCount int, emptyMessage string) {
if rowCount == 0 {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably move this out to its own file but don't want to change how the code is currently structured as this is the only consumer

@kdhillon-stripe kdhillon-stripe marked this pull request as ready for review April 28, 2026 20:57
@kdhillon-stripe kdhillon-stripe requested a review from a team as a code owner April 28, 2026 20:57
Copy link
Copy Markdown

@mattmueller-stripe mattmueller-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requesting changes specifically to remove the warning. everything else is nice-to-have.

Strong suggestion to update some of our command examples to include how to get the url/password:

Prior art:

Example: "stripe serve /path/to/directory",

Can be added here and a few of the other commands:

opCmd.Cmd.RunE = func(cmd *cobra.Command, args []string) error {

Can definitely be a follow-up though.

func runDatabaseCreate(cmd *cobra.Command, opCmd *OperationCmd, args []string) error {
var sp *spinner.Spinner
if !jsonOutputEnabled(cmd) {
sp = ansi.StartNewSpinner("Creating StripeDB instance...", cmd.ErrOrStderr())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

fmt.Fprintf(out, "Created StripeDB instance %s\n", database.ID)

// Leading blank line to match design spec
fmt.Fprintln(out)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/ooc: do other cli commands have tests?

I feel like we should probably be doing something like:

type CLI struct {
   Stdout io.Writer // defaults to os.Stdout, but can be overriden for testing
}

func (c *CLI) runDatabaseCreate(...) {
  fmt.Fprintln(c.Stdout, "blah blah")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, nevermind, looks like cobra has this built-in with cmd.OutOrStdout()

databaseJSONFlagName = "json"
databaseRequestVersion = "unsafe-development"
databaseDeleteConfirmationPhrase = "remove StripeDB"
databaseDeleteConfirmationPhrase = "delete database"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

database name instead?

if user.Password != "" {
fmt.Fprintln(out)
fmt.Fprintf(out, " %s %s. %s stripe databases retrieve %s\n",
fmt.Fprintln(out, textYellow(out, databaseWarningGlyph()+" Save this password now — it will not be shown again."))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

termsURL := "https://stripe.com/stripe-database-preview-terms"
fmt.Fprintf(out, " %s\n", ansi.Linkify(privacyURL, privacyURL, out))
fmt.Fprintf(out, " %s\n", ansi.Linkify(termsURL, termsURL, out))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Fprintln(out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants