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

umpf: answer interactive prompts with default when --default set #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

a3f
Copy link
Member

@a3f a3f commented Nov 27, 2024

When building or tagging an umpf, umpf can ask which branch to use when multiple are available. Piping yes(1) into umpf in this case doesn't work, because the variable populated by read in that case is left empty.

Handle this case to reduce user confusion.

@michaelolbrich
Copy link
Member

I think a --yes/-y option that skips the read entirely and used the default make more sense.

@a3f
Copy link
Member Author

a3f commented Dec 19, 2024

Ok, but doesn't it make sense to have piping yes behave as expected as well?

@michaelolbrich
Copy link
Member

The problem I have with piping yes is, that is overwrites all reads. So umpf will not stop here:

umpf/umpf

Line 473 in 1a9792e

read -e -i n -p "Use ${branch} instead? [y/n]: " choice

And I think that's a really bad idea.

@a3f
Copy link
Member Author

a3f commented Dec 19, 2024

Fair point. I would rename the option then though. How about --default?

@michaelolbrich
Copy link
Member

Sounds good.

@a3f a3f requested a review from michaelolbrich January 25, 2025 09:04
@a3f a3f changed the title umpf: support piping yes into umpf umpf: answer interactive prompts with default when --default set Jan 25, 2025
Copy link
Member

@michaelolbrich michaelolbrich left a comment

Choose a reason for hiding this comment

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

Just a few, mostly cosmetic things left.

else
read -e -i "$def" -p "$prompt: " choice
fi
}
Copy link
Member

Choose a reason for hiding this comment

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

Please use ${...} for all variables. We're not fully consistent overall, but it used in most cases.
And choice schould be a local variable.

Same everywhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

choice is intentionally not local, so it can be used outside the function. I am not good enough at bash to make it work with a local, can you elaborate?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry, I put that comment in the wrong place. It should be local in the calling function.

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding was that choice as written by read_interactive is a global variable, so the callers need to access to choice global variable. I need to try out whether it still works with local in the calling function

Copy link
Member

Choose a reason for hiding this comment

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

A local variable in bash is valid until the end of the function, including all functions that are called within that function.

umpf Outdated Show resolved Hide resolved
umpf Outdated Show resolved Hide resolved
When building or tagging an umpf, umpf can ask which branch to use when
multiple are available. Piping yes(1) into umpf in this case doesn't
work, because the variable populated by read in that case is left empty.

Provide for this use case, a --default option that will take a default
if one is known.

Signed-off-by: Ahmad Fatoum <[email protected]>
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.

2 participants