Skip to content

Commit

Permalink
Merge pull request #42 from ethpandaops/refactor/ask-start-on-install
Browse files Browse the repository at this point in the history
refactor(install): prompt to start post install
  • Loading branch information
mattevans authored Jan 15, 2025
2 parents 3a48ca0 + 549423a commit a02572a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
86 changes: 86 additions & 0 deletions install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,90 @@ EOF
grep -q "<string>io.ethpandaops.contributoor</string>" "$TEST_DIR/io.ethpandaops.contributoor.plist"
grep -q "<string>$CONTRIBUTOOR_BIN/sentry</string>" "$TEST_DIR/io.ethpandaops.contributoor.plist"
grep -q "<string>$USER</string>" "$TEST_DIR/io.ethpandaops.contributoor.plist"
}

@test "service start prompt handles yes response" {
# Create test script
cat > "$TEST_DIR/prompt_test.sh" << 'EOF'
#!/bin/bash
source ./install.sh
contributoor() { return 0; }
export -f contributoor
CONTRIBUTOOR_BIN="$TEST_DIR/bin"
printf "\nWould you like to start contributoor now? [y/N]: "
read -r START_SERVICE
case "$(echo "$START_SERVICE" | tr "[:upper:]" "[:lower:]")" in
y|yes)
contributoor --config-path "$TEST_DIR" restart
;;
*)
printf "You can start contributoor later by running: contributoor start"
;;
esac
EOF
chmod +x "$TEST_DIR/prompt_test.sh"

# Run test with yes input
printf 'y\n' | "$TEST_DIR/prompt_test.sh"
local result=$?

[ "$result" -eq 0 ]
}

@test "service start prompt handles no response" {
# Create test script
cat > "$TEST_DIR/prompt_test.sh" << 'EOF'
#!/bin/bash
source ./install.sh
contributoor() { return 0; }
export -f contributoor
CONTRIBUTOOR_BIN="$TEST_DIR/bin"
printf "\nWould you like to start contributoor now? [y/N]: "
read -r START_SERVICE
case "$(echo "$START_SERVICE" | tr "[:upper:]" "[:lower:]")" in
y|yes)
contributoor --config-path "$TEST_DIR" restart
;;
*)
printf "You can start contributoor later by running: contributoor start"
;;
esac
EOF
chmod +x "$TEST_DIR/prompt_test.sh"

# Run test with no input
output=$(printf 'n\n' | "$TEST_DIR/prompt_test.sh")
local result=$?

[ "$result" -eq 0 ]
echo "$output" | grep -q "You can start contributoor later"
}

@test "service start prompt handles empty response" {
# Create test script
cat > "$TEST_DIR/prompt_test.sh" << 'EOF'
#!/bin/bash
source ./install.sh
contributoor() { return 0; }
export -f contributoor
CONTRIBUTOOR_BIN="$TEST_DIR/bin"
printf "\nWould you like to start contributoor now? [y/N]: "
read -r START_SERVICE
case "$(echo "$START_SERVICE" | tr "[:upper:]" "[:lower:]")" in
y|yes)
contributoor --config-path "$TEST_DIR" restart
;;
*)
printf "You can start contributoor later by running: contributoor start"
;;
esac
EOF
chmod +x "$TEST_DIR/prompt_test.sh"

# Run test with empty input
output=$(printf '\n' | "$TEST_DIR/prompt_test.sh")
local result=$?

[ "$result" -eq 0 ]
echo "$output" | grep -q "You can start contributoor later"
}
16 changes: 14 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if ! tput clear >/dev/null 2>&1; then
fi

# Installation defaults
TOTAL_STEPS="8"
TOTAL_STEPS="9"
CONTRIBUTOOR_PATH=${CONTRIBUTOOR_PATH:-"$HOME/.contributoor"}
CONTRIBUTOOR_BIN="$CONTRIBUTOOR_PATH/bin"
CONTRIBUTOOR_VERSION="latest"
Expand Down Expand Up @@ -757,9 +757,21 @@ main() {
progress 8 "Run install wizard"
"$CONTRIBUTOOR_BIN/contributoor" --config-path "$CONTRIBUTOOR_PATH" install --version "$CONTRIBUTOOR_VERSION" --run-method "$INSTALL_MODE"

# Ask user if they want to start the service
printf "\nWould you like to start contributoor now? [y/N]: "
read -r START_SERVICE
case "$(echo "$START_SERVICE" | tr '[:upper:]' '[:lower:]')" in
y|yes)
"$CONTRIBUTOOR_BIN/contributoor" --config-path "$CONTRIBUTOOR_PATH" restart
;;
*)
printf "${COLOR_YELLOW}You can start contributoor later by running:${COLOR_RESET} contributoor start"
;;
esac

# Show PATH refresh message if needed.
if [ "$ADDED_TO_PATH" = true ]; then
printf "${COLOR_YELLOW}NOTE: To use contributoor commands, either start a new terminal or run: source ~/.$(basename "$SHELL")rc${COLOR_RESET}\n"
printf "\n\n${COLOR_YELLOW}NOTE: To use contributoor commands, either start a new terminal or run:${COLOR_RESET} source ~/.$(basename "$SHELL")rc\n"
fi
}

Expand Down

0 comments on commit a02572a

Please sign in to comment.