Skip to content

Share the CLI output utilities between lakectl and lakefs - #10610

Open
shaktimaan00 wants to merge 1 commit into
treeverse:masterfrom
shaktimaan00:extract-shared-output-utils
Open

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

Conversation

@shaktimaan00

Copy link
Copy Markdown

Closes #7904

Change Description

Background

lakectl renders everything it prints through a small template engine: WriteTo with the red / yellow / blue / bold / table / paginate functions, plus the Table, Pagination and ColoredText types. That code lived in cmd/lakectl/cmd, so lakefs could not import it and kept its own printInfo / printNonFatalError / printMsgAndExit helpers that duplicated the same idea with direct go-pretty calls.

New Feature

No new user-facing behaviour. The renderer now lives in pkg/cmdutils/output.go, a package both binaries already use:

  • pkg/cmdutils: WriteTo, Write, ColoredText/Colored, Table, Pagination, and DisableColors/Interactive for the terminal-vs-pipe rendering decision. The code is moved as-is, so lakectl output is unchanged.
  • cmd/lakectl/cmd: keeps its lakectl-specific templates and Die/Warning/PrintTable helpers, with type aliases (Table, Pagination, ColoredText) and thin Write/WriteTo/DisableColors wrappers so its ~60 call sites are untouched.
  • cmd/lakefs/cmd: printInfo, printNonFatalError and printMsgAndExit now render through cmdutils.WriteTo with the same templates lakectl uses, instead of hand-rolled fmt.Fprintln/text.Sprintf calls.

Messages printed by lakefs are byte-for-byte identical to before: I compared the old and new implementations for plain, multi-argument and error-valued arguments.

Testing Details

  • go build ./cmd/... passes.
  • go test ./pkg/cmdutils/... ./cmd/lakectl/cmd/... ./cmd/lakefs/cmd/... passes. TestColors moved with the renderer to pkg/cmdutils/output_test.go, and two tests were added for the non-interactive paths (tables rendered as tab-separated rows, pagination hint suppressed), which were previously untested.
  • go vet is clean; gofmt -l is clean. go tool golangci-lint could not run locally — the pinned linter in go.mod cannot read Go 1.27 export data — so CI will be the first lint run.
  • Parity check of lakefs output: old fmt.Fprintln(os.Stderr, "Error:", ...) vs the new template, and old text.FgHiBlue.Sprintf / text.FgHiRed.Sprintf vs {{.Message|blue}} / {{.Message|red}}, produced identical bytes for all printInfo / printNonFatalError / printMsgAndExit call shapes.

Breaking Change?

No. No API, CLI flag or output format changes. The only new exported surface is pkg/cmdutils, which is internal to this repository.

Additional info

The issue mentioned the basic helpers added in #7854 (cmd/lakefs/cmd/common_helpers.go); those are now the three callers of the shared renderer and no longer import go-pretty directly.

lakectl renders output through a small template engine (WriteTo and the
red/yellow/blue/table/paginate functions) but it lived in cmd/lakectl/cmd,
so lakefs could not use it and kept its own printing helpers.

Move the renderer and the Table, Pagination and ColoredText types to
pkg/cmdutils, which both binaries already depend on. lakectl keeps thin
aliases and wrappers so its call sites are unchanged, and lakefs renders
its info, error and fatal messages through the same engine.

Messages printed by lakefs are byte-for-byte identical to before.
@github-actions github-actions Bot added area/testing Improvements or additions to tests area/lakectl Issues related to lakeFS' command line interface (lakectl) labels Nov 11, 2026

This branch has not been deployed

No deployments
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) area/testing Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share Stdout/Stderr Output Utils Between lakefs and lakectl

1 participant