Skip to content

Fix kubectl table parser to handle multi-word column headers - #23

Merged
clobrano merged 1 commit into
mainfrom
claude/dazzling-mccarthy-Wc2OQ
May 29, 2026
Merged

Fix kubectl table parser to handle multi-word column headers#23
clobrano merged 1 commit into
mainfrom
claude/dazzling-mccarthy-Wc2OQ

Conversation

@clobrano

Copy link
Copy Markdown
Owner

Summary

Fixed the kubectl table output parser to correctly handle column headers with spaces in their names (e.g., "RELEASE STATUS"). Previously, the parser treated any space as a column boundary, which broke parsing of multi-word headers commonly found in kubectl CRD output.

Key Changes

  • Updated column boundary detection logic in parseColumnBoundaries() to distinguish between single spaces (part of a header word) and 2+ consecutive spaces (column separators)
  • Added space run tracking to count consecutive spaces and only treat gaps of 2+ spaces as column boundaries
  • Added comprehensive test case TestParseTableOutputMultiWordHeader() that validates:
    • Correct parsing of headers with spaces ("RELEASE STATUS")
    • Proper row data alignment with multi-word column headers
    • Correct column lookup and value retrieval via GetColumnIndex()

Implementation Details

The fix modifies the state machine in parseColumnBoundaries() to:

  1. Track the length of consecutive space runs (spaceRun variable)
  2. Only append a new column boundary when encountering a non-space character after either the start of the header or a gap of 2+ spaces
  3. Reset the space counter when a non-space character is encountered

This allows headers like "RELEASE STATUS" to be treated as a single column while maintaining backward compatibility with standard kubectl output that uses multiple spaces as column separators.

https://claude.ai/code/session_01L3xhVzAJ3e7metZ2gfC7hN

Columns separated by a single space (e.g. "RELEASE STATUS") were
incorrectly split into two columns, causing values like "Succeeded"
to bleed across the fabricated boundary. Only 2+ consecutive spaces
now mark a new column boundary.
@clobrano
clobrano merged commit 87b6b9f into main May 29, 2026
2 of 3 checks passed
@clobrano
clobrano deleted the claude/dazzling-mccarthy-Wc2OQ branch May 29, 2026 16:24
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