Skip to content

Add column-scoped search predicates (Fixes #776)#934

Draft
DannyStoll1 wants to merge 1 commit into
dalance:masterfrom
DannyStoll1:pr/column-predicates
Draft

Add column-scoped search predicates (Fixes #776)#934
DannyStoll1 wants to merge 1 commit into
dalance:masterfrom
DannyStoll1:pr/column-predicates

Conversation

@DannyStoll1

Copy link
Copy Markdown

Summary

Adds column-scoped search predicates, giving a general way to filter by a single field. This resolves #776 ("filter processes of a user") without a special-purpose flag:

procs user==root         # only root's processes
procs command~=dockerd   # command contains "dockerd"

Behavior

A search keyword now parses into either a plain keyword (matched against every searchable column, as before) or a <column><op><value> predicate:

  • == : exact, full-string match
  • ~= : substring match

Details:

  • The column name resolves case-insensitively against the existing column kinds (a substring is enough, e.g. user, command, pid).

  • A predicate matches its target column regardless of that column's numeric_search / nonnumeric_search flags, so pid==1 works even when Pid is not otherwise searchable.

  • Only the value after the operator may contain further = characters; the leftmost operator splits the token.

  • Predicates are ordinary search terms, so they compose with plain keywords and with --and / --or / --nand / --nor:

    procs --and user==root command~=dockerd
  • Unknown column names, and columns absent from the active layout, are reported as errors before any output.

  • Predicate parsing is disabled in --regex mode, where the pattern is taken verbatim.

Implementation

View::filter's matching is extracted into a Search type that compiles the keywords once (regex, or a set of per-column terms) and exposes matches(pid). Plain-keyword matching folds per-term results with the active logic; this is equivalent to the previous numeric/nonnumeric group combine, verified for all four logic modes. View::filter shrinks from ~200 lines to ~70.

Tests

  • Unit tests for predicate parsing (operators, value containing =, unknown/empty column).
  • Integration tests in run_default mirroring the existing search tests, plus error cases.
  • Existing search tests pass unchanged.

Docs updated: README (new subsection + feature bullet), man page, and CHANGELOG.

Introduce column predicates as a general way to filter by a single field,
addressing the "filter processes of a user" request without a special-purpose
flag: `procs user==root` shows only root's processes, `procs command~=dockerd`
matches a substring of the command.

A search keyword now parses into either a plain keyword (matched against every
searchable column, as before) or a `<column><op><value>` predicate:

  ==  exact, full-string match
  ~=  substring match

The column name resolves case-insensitively against the existing column kinds,
and a predicate matches its target column regardless of that column's
numeric_search/nonnumeric_search flags (so `pid==1` works).
Predicates are ordinary terms, so they compose with plain keywords and the
existing `--and`/`--or`/`--nand`/`--nor` logic:

  procs --and user==root command~=dockerd

Internally, `View::filter` is refactored from combining numeric/nonnumeric
keyword groups to a per-term fold. Each term compiles to the set of columns it
searches plus the operator, then the active logic folds per-term results.
This is equivalent to the previous behavior for plain keywords and generalizes
cleanly to predicates.

Unknown column names and columns absent from the active layout are reported as
errors before output. Predicate parsing is disabled in --regex mode.
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.

[Feature Request] Ability to filter processes of a user

1 participant