refactor: split cli_show_interfaces.go per render mode (#4654)#4681
Merged
Conversation
pkg/cli/cli_show_interfaces.go had grown to 1396 LOC, and the RETH / physical-member display logic repeated across the summary, terse, detail, and extensive render modes. That duplication is exactly where the #4328 family of fixes kept drifting between modes. Splitting the file per render mode and pulling the shared RETH/kernel-query helpers into one file removes the drift surface: the four modes now resolve reth link state, member attrs, and lease data through a single place. This is a pure code-motion change. Every top-level declaration was moved verbatim; no logic, output text, or netlink/sysfs query order changed. New layout (same package, so unexported helpers stay reachable): cli_show_interfaces.go showInterfaces dispatch + summary, showInterfacesRethMemberSummary, showTunnelInterfaces cli_show_interfaces_terse.go showInterfacesTerse cli_show_interfaces_detail.go showInterfacesDetail + showInterfacesRethDetail (reused by the extensive view) cli_show_interfaces_extensive.go showInterfacesExtensive[Filtered] cli_show_interfaces_stats.go showInterfacesStatistics, showVlans cli_show_interfaces_shared.go dhcpLease, rethMemberLinkState, rethMemberAttrs, baseIfName Validation: - go/parser decl-diff of origin/master's single file against the union of the six new files: identical=14, bodydiff=0, missing=0, extra=0 — all 14 top-level declarations byte-for-byte identical. - go build ./... clean; go vet ./pkg/cli/... reports only the pre-existing cli.go:503 unreachable-code note (untouched file). - go test ./pkg/cli/... green, including the #4328 (RETH) and #3654 (host-inbound) output tests that assert the exact rendered text across the summary/detail/extensive/member paths — the visible-output byte-identity gate. - gofmt clean on all six files. Closes #4654 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors show interfaces presentation code by splitting the former monolithic pkg/cli/cli_show_interfaces.go into per-render-mode files plus a small shared helper file for RETH/kernel-query helpers, aiming to eliminate renderer drift while keeping behavior and output unchanged.
Changes:
- Split
show interfacesinto dedicated files for summary/dispatch, terse, detail (incl. shared RETH detail renderer), extensive, and statistics/VLANs. - Centralize shared helpers (
dhcpLease, RETH member link-state / attrs,baseIfName) intocli_show_interfaces_shared.go. - Document the new layout in
pkg/cli/README.mdand record the refactor in_Log.md.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/README.md | Documents the new per-renderer file layout for show interfaces and the shared helper surface. |
| pkg/cli/cli_show_interfaces.go | Retains dispatch + summary renderer and member-summary path; delegates terse/detail/extensive/stats to split files. |
| pkg/cli/cli_show_interfaces_terse.go | Holds the show interfaces terse tabular renderer. |
| pkg/cli/cli_show_interfaces_detail.go | Holds show interfaces ... detail renderer and the shared showInterfacesRethDetail block reused by extensive. |
| pkg/cli/cli_show_interfaces_extensive.go | Holds show interfaces extensive and ... extensive <if> renderer. |
| pkg/cli/cli_show_interfaces_stats.go | Holds show interfaces statistics and show vlans presenters. |
| pkg/cli/cli_show_interfaces_shared.go | Shared DHCP + RETH/kernel-query helpers to prevent drift across renderers. |
| _Log.md | Logs the refactor action and touched files per repo conventions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splits the 1396-LOC
pkg/cli/cli_show_interfaces.goper render mode plus ashared RETH/kernel-query helper file. The RETH / physical-member display
logic repeated across the summary/terse/detail/extensive modes and drifted
(the #4328 family of fixes) — collecting the shared helpers in one place
removes the drift surface. Pure code motion, behavior-identical: no logic,
output text, or netlink/sysfs query order changed.
New layout (same package — unexported helpers stay reachable)
cli_show_interfaces.goshowInterfaces(dispatch + summary),showInterfacesRethMemberSummary,showTunnelInterfacescli_show_interfaces_terse.goshowInterfacesTersecli_show_interfaces_detail.goshowInterfacesDetail,showInterfacesRethDetail(reused by extensive)cli_show_interfaces_extensive.goshowInterfacesExtensive/…Filteredcli_show_interfaces_stats.goshowInterfacesStatistics,showVlanscli_show_interfaces_shared.godhcpLease,rethMemberLinkState,rethMemberAttrs,baseIfNameValidation
go/parserextraction of origin/master'ssingle file vs the union of the six new files reports
identical=14, bodydiff=0, missing=0, extra=0— all 14 top-level declarationsbyte-for-byte identical.
go build ./...clean;go vet ./pkg/cli/...reports only thepre-existing
cli.go:503unreachable-code note (untouched file).go test ./pkg/cli/...green, including the cli/grpc: show interfaces reth0 / detail / extensive fail for bondless reth — only 'terse' is reth-aware #4328 (RETH) and cli,grpc,remote-cli: text zone/interface views hide per-interface host-inbound overrides + no-stanza default-deny posture + split system-services/protocols #3654(host-inbound) output tests that assert the exact rendered text across the
summary/detail/extensive/member paths — the visible-output byte-identity gate.
gofmtclean on all six files.pkg/cli/README.mdgains a "show interfacesrender files (refactor: pkg/cli/cli_show_interfaces.go (1396 LOC) — split per-renderer + shared RETH/kernel helpers #4654)"section documenting the split.
Closes #4654
🤖 Generated with Claude Code
https://claude.ai/code/session_015oARShYtiJJ2H4UB4nXGqi