Skip to content

Commit 50ef0ab

Browse files
Update core.sh
1 parent 747a058 commit 50ef0ab

1 file changed

Lines changed: 37 additions & 29 deletions

File tree

lib/core.sh

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,38 @@
33
# Core functionality integration layer for CompressKit
44
# Coordinates between UI, logging, configuration, and compression modules
55

6-
# Load all required modules
7-
source "./lib/ui.sh"
8-
source "./lib/logger.sh"
9-
source "./lib/config.sh"
10-
source "./lib/compress.sh"
6+
# The roots of CompressKit—where every node in the system grows.
117

12-
# Initialize the system
8+
# Load all required modules (the branches of the tree)
9+
for module in "./lib/ui.sh" "./lib/logger.sh" "./lib/config.sh" "./lib/compress.sh"; do
10+
if [ -f "$module" ]; then
11+
source "$module"
12+
else
13+
echo "Missing essential module: $module"
14+
exit 1
15+
fi
16+
done
17+
18+
# The "roots" of CompressKit—initializing the sacred system.
1319
init_system() {
14-
log_debug "Initializing CompressKit..."
20+
log_debug "Breathing life into CompressKit..."
1521

16-
# Show startup animation
22+
# Show startup animation (the awakening)
1723
matrix_rain 1
1824

19-
# Initialize configuration
25+
# Initialize configuration (the soil of our tree)
2026
init_config
2127

22-
# Validate system requirements
28+
# Validate system requirements (the Gatekeeper checks the path forward)
2329
check_requirements
2430

25-
# Initialize UI
31+
# Initialize UI (the canopy where users interact)
2632
init_ui
2733

2834
log_info "System initialized successfully"
2935
}
3036

31-
# Check system requirements
37+
# Invoke the mythical guardian to check system requirements
3238
check_requirements() {
3339
local requirements=(
3440
"gs:Ghostscript is required for PDF compression"
@@ -42,61 +48,63 @@ check_requirements() {
4248
local msg="${req#*:}"
4349

4450
if ! command -v "$cmd" >/dev/null 2>&1; then
45-
log_error "$msg"
51+
log_error "$msg (The Gatekeeper denies entry: '$cmd')"
4652
all_met=false
4753
fi
4854
done
4955

5056
$all_met || exit 1
5157
}
5258

53-
# Main workflow handler
59+
# Recursive workflow handler—each branch leads deeper into the tree
5460
handle_workflow() {
5561
local command="$1"
5662
shift
5763

64+
# Base case
65+
if [ -z "$command" ]; then
66+
show_help
67+
return
68+
fi
69+
70+
# Recursive call
5871
case "$command" in
59-
"compress")
60-
handle_compression "$@"
61-
;;
62-
"info")
63-
handle_pdf_info "$@"
64-
;;
65-
"config")
66-
handle_configuration "$@"
72+
"compress"|"info"|"config")
73+
handle_$command "$@"
6774
;;
6875
*)
76+
log_error "Unknown command: $command"
6977
show_help
7078
;;
7179
esac
7280
}
7381

74-
# Compression workflow
82+
# ⚙️ The forge of CompressKit - where PDFs are reforged into lighter artifacts
7583
handle_compression() {
7684
local input_file="$1"
7785
local quality=$(get_config "quality")
7886
local output_dir=$(get_config "output_dir")
7987

80-
# Validate input
88+
# Validate input (checking the artifact's integrity)
8189
if [ ! -f "$input_file" ]; then
82-
log_error "Input file not found: $input_file"
90+
log_error "The artifact was not found: $input_file"
8391
return 1
8492
fi
8593

86-
# Show progress
94+
# Show progress (the blacksmith begins their work)
8795
ui_info "Starting compression workflow..."
8896
compress_pdf "$input_file" "$quality" "$output_dir" &
89-
spinner $! "Compressing PDF..."
97+
spinner $! "Invoking the compression daemon..."
9098

91-
# Verify results
99+
# Verify results (the artifact's rebirth)
92100
if [ $? -eq 0 ]; then
93101
ui_success "Compression completed successfully"
94102
else
95103
ui_error "Compression failed"
96104
fi
97105
}
98106

99-
# Main entry point
107+
# Main entry point (the trunk of the tree—where all branches converge)
100108
main() {
101109
init_system
102110
handle_workflow "$@"

0 commit comments

Comments
 (0)