Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle between path suggest view and keys from the current entry in REPL #38

Open
helibom opened this issue Sep 18, 2024 · 3 comments
Open

Comments

@helibom
Copy link

helibom commented Sep 18, 2024

I thought I'd would be a nice addition to be able to toggle the view above the command line between showing all the valid paths in the JSON (which it currently does) and showing the existing keys in the object that you have currently queried for in the REPL session.

Basically showing you the result of the last valid query and " | to_entries[] | .key" appended.

I'm fairly new to jq as a language, so I apologize if my naivety makes this request totally infeasible or confusing.

@reegnz
Copy link
Owner

reegnz commented Sep 18, 2024

Given that this is just thin wrapper around jq and fzf, I don't think it's feasible to implement this ask.

fzf has a replace-query action that replaces the query with the current selection.
The problem is that fzf doesn't allow us to pass selection through an additional filter before replacing the query.

To provide an example:
You have this in your current query:

.items[]|select(.metadata.namespace == "test")|.metadata

You want to see all keys in the input list that can be found under .metadata, like this:

.name
.namespace
.labels[].app
.labels["app.kubernentes.io/name"]

The replace would look something like this though when I select the last item:

.items[]|select(.metadata.namespace == "test")|.metadata|.labels["app.kubernetes.io/name"]

Sadly transforming into the last form is not possible with fzf to the best of my knowledge.
If fzf introduces a functionality to define a custom filter to replace-query that I can run the selection through, we can revisit.

It's out of scope to implement such complicated features outside of fzf though, this is a very lightweight convenience project that integrates jq and fzf, if those tools don't ship with the capability I don't intend to put it into this project.

@reegnz
Copy link
Owner

reegnz commented Sep 18, 2024

Actually, it seems like fzf has a transform-query now: junegunn/fzf#2465

so it could be feasible to do it. Will investigate.

@helibom
Copy link
Author

helibom commented Oct 21, 2024

Hi again, I apologize for not replying back.
Much appreciate you taking the time to explain the current limitations.
Am still frequently using your tool. If that transform_query API pans out, that would be very cool. Thanks!

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

No branches or pull requests

2 participants