Skip to content

Share stdout/stderr output utils between lakefs and lakectl - #10609

Closed
shaktimaan00 wants to merge 1 commit into
treeverse:masterfrom
shaktimaan00:share-output-utils
Closed

shaktimaan00 wants to merge 1 commit into
treeverse:masterfrom
shaktimaan00:share-output-utils

Conversation

@shaktimaan00

Copy link
Copy Markdown

Closes #7904

Change Description

Background

lakectl has template based helpers for writing to stdout and stderr, but they
live in cmd/lakectl/cmd/common_helpers.go and cannot be imported by the
lakefs server binary. As a result, lakefs grew its own small set of print
helpers (printMsgAndExit, printInfo, printNonFatalError, added for the
flare command). This moves the shared implementation into a package that both
binaries import.

New Feature

New package pkg/cmdutils/output.go (next to the existing cmdutils
progress/validation/coalesce helpers) with the output utilities:

  • ColoredText, Table, Pagination and the template functions behind
    red/yellow/green/blue/bold/underline, date, ljust, json,
    table, paginate, lower, human_bytes and join.
  • WriteTo, Write, Warning, Die, DieFmt, DieErr, PrintTable, plus
    the DeathMessage, DeathMessageWithFields, WarnMessage, InfoMessage and
    ErrorMessage templates.
  • DisableColors/IsTerminal, so the "no colors, no terminal only niceties"
    switch applies to every consumer.
  • InfoFmt and NonFatalErrorFmt, replacing lakefs' printInfo and
    printNonFatalError.

cmd/lakectl/cmd/common_helpers.go keeps thin wrappers with its existing
signatures (WriteTo(tpl, data, w), Colored, Table/Pagination/ColoredText
type aliases, ...) so none of the ~135 lakectl command files had to change.
cmd/lakefs/cmd/common_helpers.go is deleted and gc.go/flare.go call
cmdutils directly.

Testing Details

  • go build ./...
  • go vet ./cmd/lakectl/... ./cmd/lakefs/... ./pkg/cmdutils/...
  • go test ./cmd/lakectl/cmd/... — passes, including TestColors, which
    exercises the moved WriteTo template functions through the wrapper.

Breaking Change?

No API or client change. One user visible difference: errors from the lakefs
binary now print through the shared DeathMessage template, i.e.

<error in red>
Error executing command.

instead of Error: <error>. Info/Error non-fatal messages and the flare
warnings keep their previous meaning, now covering both binaries.

lakectl had template based helpers for writing to stdout and stderr that
could not be imported by the lakefs server binary, so lakefs grew its own
ad-hoc print helpers (added for the flare command).  Move the shared
implementation into pkg/cmdutils/output.go:

* ColoredText, Table and Pagination, plus the template functions behind
  red/yellow/green/blue/bold/underline, json, table, paginate and friends.
* WriteTo, Write, Warning, Die, DieFmt, DieErr and PrintTable, along with
  the death and warning message templates.
* InfoFmt and NonFatalErrorFmt, which replace lakefs' printInfo and
  printNonFatalError.

lakectl keeps thin wrappers with its existing signatures, so none of the
commands had to change, and lakefs consumes the package directly.
@github-actions github-actions Bot added the area/lakectl Issues related to lakeFS' command line interface (lakectl) label Nov 11, 2026
@shaktimaan00

Copy link
Copy Markdown
Author

Closing this in favour of #10610, which I opened a minute later — same issue, same approach, so having both open just splits the review. Sorry for the duplicate.

The two differences, so the choice is clear if you would rather have this one:

Both branches build and their tests pass; nothing in this branch is needed by #10610.

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

Labels

area/lakectl Issues related to lakeFS' command line interface (lakectl)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share Stdout/Stderr Output Utils Between lakefs and lakectl

1 participant