diff --git a/dist/theme/bin/theme b/dist/theme/bin/theme index c3cbf30..12f977c 100755 --- a/dist/theme/bin/theme +++ b/dist/theme/bin/theme @@ -322,17 +322,6 @@ theme_warn() { theme_run() { local arg="${1:-}" - if [[ "$arg" == "--detect" ]]; then - theme_detect - printf '%s\n' "$THEME_APPEARANCE" - return 0 - fi - - if [[ "$arg" == "--list" ]]; then - theme_list - return 0 - fi - theme_source_config if ! theme_discover_provider; then @@ -353,9 +342,7 @@ theme_run() { ;; esac - if ! theme_detect "$override"; then - return 1 - fi + theme_detect "$override" "$THEME_PROVIDER" "$THEME_APPEARANCE" "$THEME_SOURCE" diff --git a/scripts/theme/main_spec.sh b/scripts/theme/main_spec.sh index 4df1a5c..f135058 100644 --- a/scripts/theme/main_spec.sh +++ b/scripts/theme/main_spec.sh @@ -98,6 +98,21 @@ Describe 'theme' The output should be present End + It 'falls back to THEME env var when set to light' + # Remove detector so it falls through to THEME env + rm -f "$XDG_CONFIG_HOME/theme/detectors.d/noop.sh" + export THEME=light + When run script "$BIN" -q --detect + The status should be success + The output should equal "light" + End + + It 'rejects invalid override with --detect' + When run script "$BIN" --detect invalid + The status should be failure + The stderr should include "invalid appearance" + End + It 'falls back to light when THEME env var is invalid' export THEME=invalid_value # Clear any system-level detection by running in isolated env @@ -399,6 +414,20 @@ EOF The output should equal "PROVIDER_RAN" The stderr should include "no detectors configured" End + + It 'handles non-existent handlers.d directory gracefully' + cat > "$XDG_CONFIG_HOME/theme/provider.sh" << 'EOF' +theme_provider_test() { + echo "PROVIDER_RAN" +} +EOF + # Remove handlers.d directory entirely + rm -rf "$XDG_CONFIG_HOME/theme/handlers.d" + export THEME=dark + When run script "$BIN" -q + The status should be success + The output should equal "PROVIDER_RAN" + End End #═══════════════════════════════════════════════════════════════ diff --git a/scripts/theme/run.sh b/scripts/theme/run.sh index 61835b5..a57aea1 100644 --- a/scripts/theme/run.sh +++ b/scripts/theme/run.sh @@ -14,23 +14,11 @@ theme_warn() { } # Main orchestration function -# Usage: theme_run [--detect|--list|dark|light|auto] +# Usage: theme_run [dark|light|auto] +# Note: --detect and --list are handled by main.sh before calling this theme_run() { local arg="${1:-}" - # Handle --detect: only detect and print, no provider/handlers - if [[ "$arg" == "--detect" ]]; then - theme_detect - printf '%s\n' "$THEME_APPEARANCE" - return 0 - fi - - # Handle --list: list provider and handlers - if [[ "$arg" == "--list" ]]; then - theme_list - return 0 - fi - # Source user configuration (provider.sh, handlers.d/*.sh) theme_source_config @@ -55,9 +43,8 @@ theme_run() { ;; esac - if ! theme_detect "$override"; then - return 1 - fi + # Note: override is validated above, so theme_detect can't fail here + theme_detect "$override" # Call provider with appearance and source "$THEME_PROVIDER" "$THEME_APPEARANCE" "$THEME_SOURCE"