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

gum choose: Option to not ask when there is no choice #396

Closed
vt-alt opened this issue Jul 10, 2023 · 6 comments · Fixed by #398
Closed

gum choose: Option to not ask when there is no choice #396

vt-alt opened this issue Jul 10, 2023 · 6 comments · Fixed by #398
Labels
enhancement New feature or request

Comments

@vt-alt
Copy link

vt-alt commented Jul 10, 2023

Is your feature request related to a problem? Please describe.
When using dynamic choice list in gum choose, sometimes it's no need to ask user for choice if there's just one option. So in that case it would be useful to have option to skip asking user and just return that single value.

Describe the solution you'd like
Like gum choose --no-ask-if-no-choice one would just return one immediately.

Describe alternatives you've considered
Well alternative is to script gum call, but such option would be easier for users.

Additional context
It's also important that this should not be enabled by default, because user may expect interactive step and may press enter in advance and if step is skipped wrong choice could be selected,

@bashbunni
Copy link
Member

Hey @vt-alt do you mind providing me with a bit more context here? I'm hoping to clarify the use case for this feature and why it is better than whatever current workaround there is for this? If you could provide some examples with code/scripts that would be really helpful to see how this feature changes the UX.

@kennyp I saw your PR, so if you would like to chime in on this as well that would be great :)

@vt-alt
Copy link
Author

vt-alt commented Jul 26, 2023

I have interface that queries various info about RPM package(s), and by the selectors there could be several packages (like different repositories (old or new) or different architectures) or just one package. It would be just handy when there is single package to not request users to select it.

Workaround is to count lines before gum call and to skip it.

For a more detailed example, from a single RPM source - one or several binary packages could be built (for example tools and maybe libs and docs) when user wants to see content of built RPM when there is several binary packages interface present choice but when there is just one package choice is not needed.

@kennyp
Copy link
Contributor

kennyp commented Jul 26, 2023

My thoughts are the same as @vt-alt. I have a few places where I'm getting a list of candidates by polling an API, and if there's only one candidate, it's nice to select it and move to confirm the following action.

In bash before, I was doing something like:

apps=($(fetch_from API_URL))

if [ "${#apps[@]}" = "1" ]; then
	chosen="${apps[0]}"
else
	chosen=$(echo ${apps[@]} | tr ' ' '\n' | gum choose)
fi

And with this feature it's just:

chosen=$(fetch_from API_URL | gum choose --select-if-one)

@kennyp
Copy link
Contributor

kennyp commented Oct 16, 2023

Any thoughts @bashbunni?

@bashbunni bashbunni added the enhancement New feature or request label Oct 31, 2023
@vt-alt
Copy link
Author

vt-alt commented Nov 28, 2023

Btw, fzf have such option, it's:

       -1, --select-1
              If  there  is only one match for the initial query (--query),
              do not start interactive finder and automatically select  the
              only match

@maaslalani
Copy link
Contributor

Sorry about the delay on this one! Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants