Skip to content

feat: add scan --sort=<column> for non-interactive sorting - #87

Merged
gsjonio merged 1 commit into
developfrom
feature/scan-sort
Jul 20, 2026
Merged

feat: add scan --sort=<column> for non-interactive sorting#87
gsjonio merged 1 commit into
developfrom
feature/scan-sort

Conversation

@gsjonio

@gsjonio gsjonio commented Jul 20, 2026

Copy link
Copy Markdown
Owner

What and why

monitor/dashboard can sort the device table interactively with s; a one-shot scan always came out in IP order. This adds --sort=ip|rtt|name|class.

  • Reuses the live views' comparator (lessByKey), so --sort=rtt and the interactive s order identically. SortKey is now exported with a ParseSortColumn for the CLI.
  • An unknown column fails fast, before scanning (mirrors --class): scan --sort=bogus errors in ~35ms.
  • Sorting moved from RenderDevices to the caller. The renderer now prints what it is given, so one path serves both the table and --json — which previously came out unordered. Default is still IP, and the shared comparator keeps online devices first.

Verified live: default order unchanged (.1, .20, .27, .88, .138, .178), --sort=rtt reorders, bad column fails fast.

Closes #73

Risks

None security-wise. Behavioral note: scan --json output is now ordered (it wasn't before) and offline devices sort after online ones — in practice a scan only returns online devices, so the visible table order is unchanged.

Checklist

  • Build, vet/lint, and tests pass
  • New non-trivial logic has a test (TestParseSortColumn, TestSortDevicesScanByRTT, TestSortDevicesOnlineFirstAndByIP)
  • Conventional Commits, no Claude co-author trailer
  • README.md and README.pt-BR.md updated in this PR
  • Issue has a milestone (v1.21.0)

monitor/dashboard could sort the device table with `s`, but a one-shot scan
always came out in IP order. Add --sort=ip|rtt|name|class, reusing the live
views' comparator so both order identically. An unknown column fails fast,
before scanning, mirroring --class.

Sorting moves from RenderDevices to the caller: the renderer now prints what it
is given, so the same path serves the table and --json (which previously came
out unordered). The default is still IP, and the shared comparator keeps online
devices first.

Closes #73
@gsjonio
gsjonio merged commit b0e2c7b into develop Jul 20, 2026
9 checks passed
@gsjonio
gsjonio deleted the feature/scan-sort branch July 20, 2026 12:43
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.

Add scan --sort=<column> for non-interactive sorting

1 participant