-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainframe
More file actions
executable file
·295 lines (249 loc) · 7.73 KB
/
mainframe
File metadata and controls
executable file
·295 lines (249 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env bash
# =============================================================================
# MAINFRAME - A GI Joe-Inspired Bash Toolkit for the Agentic CLI Era
# =============================================================================
# "Mainframe can make a computer do anything short of tap dance."
# - GI Joe Filecard, 1986
# =============================================================================
set -euo pipefail
# Version
MAINFRAME_VERSION="1.0.0"
# Determine installation directory
MAINFRAME_ROOT="${MAINFRAME_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
export MAINFRAME_ROOT
# Source libraries
source "$MAINFRAME_ROOT/lib/common.sh"
source "$MAINFRAME_ROOT/lib/config.sh"
source "$MAINFRAME_ROOT/lib/args.sh"
# =============================================================================
# ASCII ART BANNER
# =============================================================================
show_banner() {
cat << 'EOF'
__ ______ _____ ________ ___ __ _________
/ |/ / | / _/ | / / ____/ / _ \ / |/ / ____/
/ /|_/ / /| | / // |/ / /_ / , _/ / /|_/ / __/
/ / / / ___ |_/ // /| / __/ / /| | / / / / /___
/_/ /_/_/ |_/___/_/ |_/_/ /_/ |_|/_/ /_/_____/
EOF
printf " \"Knowing your shell is half the battle.\"\n\n"
}
# =============================================================================
# COMMANDS
# =============================================================================
# List all available scripts
cmd_list() {
local category="${1:-all}"
local verbose="${2:-false}"
header "MAINFRAME Operations"
local categories
if [[ "$category" == "all" ]]; then
categories=(data agent git file api dev)
else
categories=("$category")
fi
for cat in "${categories[@]}"; do
local script_dir="$MAINFRAME_ROOT/scripts/$cat"
[[ -d "$script_dir" ]] || continue
subheader "${cat^} Scripts"
for script in "$script_dir"/*; do
[[ -f "$script" ]] || continue
local name
name=$(basename "$script" .sh)
if [[ "$verbose" == "true" ]]; then
# Extract description from script
local desc
desc=$(grep -m1 "^# Description:" "$script" 2>/dev/null | cut -d: -f2- | xargs || echo "No description")
printf " %-24s %s\n" "$name" "$desc"
else
printf " %s\n" "$name"
fi
done
printf "\n"
done
}
# Run a script
cmd_run() {
local script_name="${1:?Script name required}"
shift
# Find script
local script=""
for category in data agent git file api dev; do
local path="$MAINFRAME_ROOT/scripts/$category/$script_name"
if [[ -f "$path" ]]; then
script="$path"
break
fi
if [[ -f "${path}.sh" ]]; then
script="${path}.sh"
break
fi
done
if [[ -z "$script" ]]; then
die "$EXIT_NOINPUT" "Operation not found: $script_name"
fi
# Execute script
exec "$script" "$@"
}
# Show help for a script
cmd_help() {
local script_name="${1:-}"
if [[ -z "$script_name" ]]; then
show_usage
return 0
fi
# Find and run script with --help
cmd_run "$script_name" --help
}
# Show version
cmd_version() {
printf "MAINFRAME CLI Toolkit v%s\n" "$MAINFRAME_VERSION"
printf "Installation: %s\n" "$MAINFRAME_ROOT"
printf "\n"
printf "\"Mainframe can make a computer do anything short of tap dance.\"\n"
printf " - GI Joe Filecard, 1986\n"
}
# Update mainframe
cmd_update() {
info "Checking for updates..."
if [[ ! -d "$MAINFRAME_ROOT/.git" ]]; then
die "$EXIT_CONFIG" "Not a git repository. Cannot update."
fi
(
cd "$MAINFRAME_ROOT"
git fetch origin
local local_rev remote_rev
local_rev=$(git rev-parse HEAD)
remote_rev=$(git rev-parse origin/main)
if [[ "$local_rev" == "$remote_rev" ]]; then
success "Already up to date. YO JOE!"
else
info "Updating..."
git pull origin main
success "Updated to latest version. Mission accomplished!"
fi
)
}
# Check dependencies
cmd_doctor() {
show_banner
header "MAINFRAME Health Check"
local issues=0
# Check Bash version
printf "Bash version: "
if [[ "${BASH_VERSINFO[0]}" -gt 4 ]] || [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 ]]; then
success "$BASH_VERSION"
else
failure "$BASH_VERSION (4.4+ required)"
issues=$((issues + 1))
fi
# Check required commands
for cmd in git curl jq; do
printf "%-16s " "$cmd:"
if command_exists "$cmd"; then
local version
version=$("$cmd" --version 2>&1 | head -1)
success "$version"
else
failure "not found"
issues=$((issues + 1))
fi
done
# Check optional commands
subheader "Optional Dependencies"
for cmd in rg fd hyperfine csvkit xmlstarlet; do
printf "%-16s " "$cmd:"
if command_exists "$cmd"; then
success "installed"
else
warn "not installed"
fi
done
# Summary
printf "\n"
if [[ $issues -eq 0 ]]; then
success "All systems operational. YO JOE!"
else
failure "$issues issue(s) found. Run repairs."
return 1
fi
}
# =============================================================================
# MAIN
# =============================================================================
show_usage() {
show_banner
cat << EOF
${CLR_BOLD}MAINFRAME CLI Toolkit${CLR_RESET} v$MAINFRAME_VERSION
${CLR_BOLD}Usage:${CLR_RESET}
mainframe <command> [options]
mainframe <script-name> [args]
${CLR_BOLD}Commands:${CLR_RESET}
list [category] List available operations
run <script> [args] Execute an operation
help [script] Show operation details
version Show version information
update Update to latest version
doctor Check systems and configuration
${CLR_BOLD}Categories:${CLR_RESET}
data Data transformation operations
agent Agent orchestration operations
git Git workflow operations
file File operation scripts
api API/webhook operations
dev Developer utilities
${CLR_BOLD}Examples:${CLR_RESET}
mainframe list # List all operations
mainframe list data # List data operations
mainframe json-to-csv input.json # Run an operation directly
mainframe help json-to-csv # Get operation details
${CLR_BOLD}Documentation:${CLR_RESET}
https://github.com/mainframe-cli/mainframe
${CLR_DIM}YO JOE!${CLR_RESET}
EOF
}
main() {
local command="${1:-}"
if [[ -z "$command" ]]; then
show_usage
exit 0
fi
shift || true
case "$command" in
list|ls)
local category="all"
local verbose=false
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--verbose) verbose=true ;;
*) category="$1" ;;
esac
shift
done
cmd_list "$category" "$verbose"
;;
run)
cmd_run "$@"
;;
help|--help|-h)
cmd_help "$@"
;;
version|--version|-V)
cmd_version
;;
update)
cmd_update
;;
doctor|check)
cmd_doctor
;;
-*)
die_usage "Unknown option: $command"
;;
*)
# Assume it's a script name
cmd_run "$command" "$@"
;;
esac
}
main "$@"