Skip to content

Conversation

olamilekan000
Copy link
Contributor

@olamilekan000 olamilekan000 commented Oct 12, 2025

change adds --filter option to list command for a user-friendly way to filter instances using yq expressions,
which is equivalent to yq options like --yq 'select(EXPR)'

Fixes

@olamilekan000 olamilekan000 force-pushed the add-filter-opttion-to-list-cmd branch 2 times, most recently from 4601c97 to c7631d4 Compare October 12, 2025 21:57
}
if len(filter) != 0 {
for _, f := range filter {
yq = append(yq, "select("+f+")")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs escaping

Copy link
Contributor Author

@olamilekan000 olamilekan000 Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested numerous escaping approaches as asked, but it breaks the yq expressions. What string escape approach would you recommend? Thanks @AkihiroSuda

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda I don't see why this needs escaping. The filter expression should be inserted literally inside the select().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without escaping the code looks vulnerable to "Bobby Tables".
Unlikely to result in breaking data in our case though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different from any code you specify via --yq? The only difference is that the --filter argument is wrapped inside a select() call.

The user can literally send the same command via --yq "$(printf "select(%s)" "$FILTER")".

Any escaping would simply break the filter expression.

Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs changes (allow --filter with --yq) and simplifications.

Comment on lines +162 to +164
if len(yq) != 0 {
return errors.New("option --filter conflicts with option --yq")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to combine --filter and --yq as long as the output format is json or yaml.

So you could just drop the check here because yq is already incompatible with the other output formats.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't too clear to me but is there anything wrong with the way it currently is?

}
if len(filter) != 0 {
for _, f := range filter {
yq = append(yq, "select("+f+")")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda I don't see why this needs escaping. The filter expression should be inserted literally inside the select().

@olamilekan000 olamilekan000 force-pushed the add-filter-opttion-to-list-cmd branch 2 times, most recently from 1c7ed74 to 404b08c Compare October 14, 2025 22:29
Signed-off-by: olalekan odukoya <odukoyaonline@gmail.com>
@olamilekan000 olamilekan000 force-pushed the add-filter-opttion-to-list-cmd branch from 404b08c to a5ba9ad Compare October 14, 2025 22:33
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.

3 participants