Skip to content

Commit edeff30

Browse files
committed
feat(state): add installation progress checklist
Display a visual checklist showing the status of each installation phase with emoji indicators (✅ completed, ⏭️ skipped, 🔄 in progress, ❌ failed, ⏳ pending). The checklist is printed to stderr after each state update when ACFS_CHECKLIST_PROGRESS is enabled and jq is available.
1 parent 0841780 commit edeff30

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

scripts/lib/state.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,9 @@ state_update() {
13161316
local save_result=0
13171317
state_save "$new_state" || save_result=$?
13181318
_state_release_lock
1319+
if [[ $save_result -eq 0 ]]; then
1320+
state_print_checklist "phase_start" || true
1321+
fi
13191322
return $save_result
13201323
}
13211324

@@ -1371,6 +1374,9 @@ state_phase_start() {
13711374
local save_result=0
13721375
state_save "$new_state" || save_result=$?
13731376
_state_release_lock
1377+
if [[ $save_result -eq 0 ]]; then
1378+
state_print_checklist "step_update" || true
1379+
fi
13741380
return $save_result
13751381
}
13761382

@@ -1403,6 +1409,9 @@ state_step_update() {
14031409
local save_result=0
14041410
state_save "$new_state" || save_result=$?
14051411
_state_release_lock
1412+
if [[ $save_result -eq 0 ]]; then
1413+
state_print_checklist "phase_complete" || true
1414+
fi
14061415
return $save_result
14071416
}
14081417

@@ -1460,6 +1469,9 @@ state_phase_complete() {
14601469
local save_result=0
14611470
state_save "$new_state" || save_result=$?
14621471
_state_release_lock
1472+
if [[ $save_result -eq 0 ]]; then
1473+
state_print_checklist "phase_fail" || true
1474+
fi
14631475
return $save_result
14641476
}
14651477

@@ -1532,6 +1544,7 @@ state_phase_skip() {
15321544

15331545
state_save "$new_state" 2>/dev/null || true
15341546
_state_release_lock
1547+
state_print_checklist "phase_skip" || true
15351548
return 0
15361549
}
15371550

@@ -2146,6 +2159,71 @@ state_print_summary() {
21462159
done
21472160
}
21482161

2162+
_state_list_contains() {
2163+
local list="$1"
2164+
local target="$2"
2165+
2166+
while IFS= read -r item; do
2167+
if [[ "$item" == "$target" ]]; then
2168+
return 0
2169+
fi
2170+
done <<< "$list"
2171+
2172+
return 1
2173+
}
2174+
2175+
state_print_checklist() {
2176+
local trigger="${1:-update}"
2177+
2178+
if [[ "${ACFS_CHECKLIST_PROGRESS:-true}" != "true" ]]; then
2179+
return 0
2180+
fi
2181+
2182+
if ! command -v jq &>/dev/null; then
2183+
return 0
2184+
fi
2185+
2186+
local state
2187+
if ! state=$(state_load); then
2188+
return 1
2189+
fi
2190+
2191+
local completed_list skipped_list current_phase current_step failed_phase failed_step
2192+
completed_list=$(echo "$state" | jq -r '.completed_phases[]?' 2>/dev/null)
2193+
skipped_list=$(echo "$state" | jq -r '.skipped_phases[]?' 2>/dev/null)
2194+
current_phase=$(echo "$state" | jq -r '.current_phase // empty' 2>/dev/null)
2195+
current_step=$(echo "$state" | jq -r '.current_step // empty' 2>/dev/null)
2196+
failed_phase=$(echo "$state" | jq -r '.failed_phase // empty' 2>/dev/null)
2197+
failed_step=$(echo "$state" | jq -r '.failed_step // empty' 2>/dev/null)
2198+
2199+
echo "" >&2
2200+
echo "Installation checklist (${trigger}):" >&2
2201+
2202+
for phase_id in "${ACFS_PHASE_IDS[@]}"; do
2203+
local name="${ACFS_PHASE_NAMES[$phase_id]:-$phase_id}"
2204+
local status=""
2205+
local extra=""
2206+
2207+
if [[ -n "$failed_phase" && "$phase_id" == "$failed_phase" ]]; then
2208+
status=""
2209+
if [[ -n "$failed_step" && "$failed_step" != "null" ]]; then
2210+
extra="$failed_step"
2211+
fi
2212+
elif _state_list_contains "$completed_list" "$phase_id"; then
2213+
status=""
2214+
elif _state_list_contains "$skipped_list" "$phase_id"; then
2215+
status="⏭️"
2216+
elif [[ -n "$current_phase" && "$phase_id" == "$current_phase" ]]; then
2217+
status="🔄"
2218+
if [[ -n "$current_step" && "$current_step" != "null" ]]; then
2219+
extra="$current_step"
2220+
fi
2221+
fi
2222+
2223+
printf " %s %s%s\n" "$status" "$name" "$extra" >&2
2224+
done
2225+
}
2226+
21492227
# ============================================================
21502228
# Phase Execution Wrapper
21512229
# ============================================================

0 commit comments

Comments
 (0)