Skip to content

Commit 62291f8

Browse files
committed
read from /dev/tty if we need to
1 parent d52de2b commit 62291f8

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

bootstrap.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ show_usage() {
1515
download_framework() {
1616
echo "Downloading the framework..."
1717
if ! curl -sSL "$BASE_URL/$ZIP_NAME" -o "$TMP_DIR/$ZIP_NAME"; then
18-
echo "Error: Failed to download the framework."
18+
echo "Error: Failed to download the framework." 1>&2
1919
rm -rf "$TMP_DIR"
2020
exit 1
2121
fi
2222
echo "Extracting the framework..."
2323
if ! unzip -q "$TMP_DIR/$ZIP_NAME" -d "$TMP_DIR"; then
24-
echo "Error: Failed to extract the framework."
24+
echo "Error: Failed to extract the framework." 1>&2
2525
rm -rf "$TMP_DIR"
2626
exit 1
2727
fi
@@ -51,8 +51,17 @@ main() {
5151

5252
# Check if a project name is provided as an argument
5353
if [ -z "$1" ]; then
54+
# we need to connect to /dev/tty in order to read stdin
55+
if [ ! -t 0 ]; then
56+
if [ ! -t 1 ]; then
57+
echo "Error: Unable to run interactively!" 1>&2
58+
exit 1
59+
fi
60+
read -p "Enter a project name: " PROJECT_NAME </dev/tty
61+
else
62+
read -p "Enter a project name: " PROJECT_NAME
63+
fi
5464
# Prompt the user for the project name interactively
55-
read -p "Enter a project name: " PROJECT_NAME
5665
if [ -z "$PROJECT_NAME" ]; then
5766
show_usage
5867
rm -rf "$TMP_DIR"
@@ -64,14 +73,14 @@ main() {
6473

6574
# Check if the project name is valid
6675
if ! is_valid_project_name "$PROJECT_NAME"; then
67-
echo "Error: Invalid project name. Project name can only contain letters, numbers, dashes, and underscores."
76+
echo "Error: Invalid project name. Project name can only contain letters, numbers, dashes, and underscores." 1>&2
6877
rm -rf "$TMP_DIR"
6978
exit 1
7079
fi
7180

7281
# Check if the project directory already exists
7382
if [ -d "$PROJECT_NAME" ]; then
74-
echo "Error: Project directory '$PROJECT_NAME' already exists."
83+
echo "Error: Project directory '$PROJECT_NAME' already exists." 1>&2
7584
rm -rf "$TMP_DIR"
7685
exit 1
7786
fi

0 commit comments

Comments
 (0)