Features: 1) Add tty check for all interactive prompts to support non-interactive environments; 2) Provide fallback behavior for non-tty sessions.
Fixes: 1) Ensure prompts do not stall in non-interactive sessions. Extra: 1) Minor adjustments to prompt messages for better clarity; 2) Refactor prompt logic for improved robustness.
This commit is contained in:
parent
a96aab33cb
commit
d6e308a10f
1 changed files with 26 additions and 6 deletions
|
|
@ -8,8 +8,16 @@ get_random_hex() {
|
|||
}
|
||||
|
||||
prompt_default() {
|
||||
if [ -t 0 ]; then
|
||||
printf "Enter %s [%s]: " "$1" "$2"
|
||||
read -r response
|
||||
if read -r response </dev/tty; then
|
||||
:
|
||||
else
|
||||
response=""
|
||||
fi
|
||||
else
|
||||
response=""
|
||||
fi
|
||||
if [ -z "${response//[[:space:]]/}" ]; then
|
||||
echo "$2"
|
||||
else
|
||||
|
|
@ -18,8 +26,16 @@ prompt_default() {
|
|||
}
|
||||
|
||||
prompt_autogen() {
|
||||
if [ -t 0 ]; then
|
||||
printf "Enter %s (leave blank to auto-generate): " "$1"
|
||||
read -r response
|
||||
if read -r response </dev/tty; then
|
||||
:
|
||||
else
|
||||
response=""
|
||||
fi
|
||||
else
|
||||
response=""
|
||||
fi
|
||||
if [ -z "${response//[[:space:]]/}" ]; then
|
||||
get_random_hex "$2"
|
||||
else
|
||||
|
|
@ -29,8 +45,12 @@ prompt_autogen() {
|
|||
|
||||
if [ -f .env ]; then
|
||||
echo ".env already exists and will be overwritten." >&2
|
||||
printf "Press Enter to continue or Ctrl+C to abort"
|
||||
read -r
|
||||
if [ -t 0 ]; then
|
||||
printf "Press Enter to continue or Ctrl+C to abort: "
|
||||
read -r _ </dev/tty || true
|
||||
else
|
||||
echo "Non-interactive session detected; proceeding without prompt." >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
EVIBES_PROJECT_NAME=$(prompt_default EVIBES_PROJECT_NAME eVibes)
|
||||
|
|
|
|||
Loading…
Reference in a new issue