Skip to content

feat: add --order-by and --order parameters to parse and search commands#102

Merged
digizeph merged 1 commit intomainfrom
issue-98-order-by-parameter
Jan 29, 2026
Merged

feat: add --order-by and --order parameters to parse and search commands#102
digizeph merged 1 commit intomainfrom
issue-98-order-by-parameter

Conversation

@digizeph
Copy link
Member

Summary

This PR adds sorting capability to the parse and search commands, allowing users to output results in a specified order (e.g., chronological or reverse chronological).

Closes #98

Changes

  • Added --order-by option to specify the field to sort by
  • Added --order option to specify sort direction (asc/desc, default: asc)
  • When ordering is requested, output is buffered and sorted before display
  • Updated CHANGELOG.md with unreleased changes

Available Order-By Fields

  • timestamp - Order by timestamp (default)
  • prefix - Order by network prefix
  • peer_ip - Order by peer IP address
  • peer_asn - Order by peer AS number
  • as_path - Order by AS path (string comparison)
  • next_hop - Order by next hop IP address

Examples

# Parse with chronological ordering (ascending)
monocle parse file.mrt --order-by timestamp --order asc

# Parse with reverse chronological ordering (descending)
monocle parse file.mrt --order-by timestamp --order desc

# Search with ordering
monocle search -t 2024-01-01 -d 1h -p 1.1.1.0/24 --order-by timestamp --order desc

# Order by peer ASN
monocle parse file.mrt --order-by peer_asn --order asc

Notes

  • Field names use underscores (e.g., peer_ip, as_path) to match the output field names
  • When --order-by is specified, all output is buffered before display (similar to table format behavior)
  • Without --order-by, streaming output behavior is preserved for better performance with large datasets

- Add OrderByField enum with sortable fields: timestamp, prefix, peer_ip,
  peer_asn, as_path, next_hop
- Add OrderDirection enum with asc/desc options
- Add sort_elems() function for sorting buffered BGP elements
- Update parse command to buffer and sort output when ordering is requested
- Update search command to buffer and sort output when ordering is requested
- Update CHANGELOG.md with unreleased changes for #98 and #101

When --order-by is specified, output is buffered before display to enable
sorting. This allows users to view results in chronological or reverse
chronological order.

Closes #98
@digizeph digizeph merged commit 4f1afb9 into main Jan 29, 2026
1 check passed
@digizeph digizeph deleted the issue-98-order-by-parameter branch January 31, 2026 01:23
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.

Support outputting search results in chronological order

1 participant