Add session resuming
This commit is contained in:
53
sloptrap
53
sloptrap
@@ -30,6 +30,8 @@ print_styled() {
|
||||
for arg in "$@"; do
|
||||
colored_args+=("$COLOR_HIGHLIGHT$arg$color")
|
||||
done
|
||||
# Format strings are defined within sloptrap, not user input.
|
||||
# shellcheck disable=SC2059
|
||||
printf "$fmt" "${colored_args[@]}"
|
||||
else
|
||||
printf '%b' "$fmt"
|
||||
@@ -50,6 +52,8 @@ print_styled_err() {
|
||||
for arg in "$@"; do
|
||||
colored_args+=("$COLOR_HIGHLIGHT$arg$color")
|
||||
done
|
||||
# Format strings are defined within sloptrap, not user input.
|
||||
# shellcheck disable=SC2059
|
||||
printf "$fmt" "${colored_args[@]}" >&2
|
||||
else
|
||||
printf '%b' "$fmt" >&2
|
||||
@@ -121,6 +125,7 @@ usage() {
|
||||
info_line "\n"
|
||||
info_line "Example targets:\n"
|
||||
comment_line " run Build if needed, then launch Codex\n"
|
||||
comment_line " resume <id> Build if needed, then run 'codex resume <id>'\n"
|
||||
comment_line " shell Drop into an interactive /bin/bash session\n"
|
||||
comment_line " clean Remove the project container/image cache\n"
|
||||
comment_line " prune Remove dangling/unused sloptrap images\n"
|
||||
@@ -1026,17 +1031,25 @@ prune_sloptrap_images() {
|
||||
run_or_print "${cmd[@]}"
|
||||
}
|
||||
|
||||
run_codex() {
|
||||
if ! $DRY_RUN; then
|
||||
status_line "Running %s\n" "$SLOPTRAP_IMAGE_NAME"
|
||||
fi
|
||||
run_codex_command() {
|
||||
local -a extra_args=("$@")
|
||||
local -a cmd=("${BASE_CONTAINER_CMD[@]}" "$SLOPTRAP_IMAGE_NAME")
|
||||
if [[ ${#CODEX_ARGS_ARRAY[@]} -gt 0 ]]; then
|
||||
cmd+=("${CODEX_ARGS_ARRAY[@]}")
|
||||
fi
|
||||
if [[ ${#extra_args[@]} -gt 0 ]]; then
|
||||
cmd+=("${extra_args[@]}")
|
||||
fi
|
||||
run_or_print "${cmd[@]}"
|
||||
}
|
||||
|
||||
run_codex() {
|
||||
if ! $DRY_RUN; then
|
||||
status_line "Running %s\n" "$SLOPTRAP_IMAGE_NAME"
|
||||
fi
|
||||
run_codex_command
|
||||
}
|
||||
|
||||
run_login_target() {
|
||||
if ! $DRY_RUN; then
|
||||
status_line "Login %s\n" "$SLOPTRAP_IMAGE_NAME"
|
||||
@@ -1053,6 +1066,23 @@ run_shell_target() {
|
||||
run_or_print "${cmd[@]}"
|
||||
}
|
||||
|
||||
run_resume_target() {
|
||||
local session_id=$1
|
||||
if ! $DRY_RUN; then
|
||||
status_line "Resume %s (%s)\n" "$SLOPTRAP_IMAGE_NAME" "$session_id"
|
||||
fi
|
||||
run_codex_command resume "$session_id"
|
||||
}
|
||||
|
||||
process_resume_target() {
|
||||
local session_id=$1
|
||||
if [[ -z $session_id ]]; then
|
||||
error "target 'resume' requires a session identifier"
|
||||
fi
|
||||
build_if_missing
|
||||
run_resume_target "$session_id"
|
||||
}
|
||||
|
||||
dispatch_target() {
|
||||
local target=$1
|
||||
case "$target" in
|
||||
@@ -1267,6 +1297,17 @@ if $AUTO_LOGIN; then
|
||||
dispatch_target login
|
||||
fi
|
||||
|
||||
for target in "${TARGETS[@]}"; do
|
||||
dispatch_target "$target"
|
||||
target_index=0
|
||||
while (( target_index < ${#TARGETS[@]} )); do
|
||||
current_target="${TARGETS[$target_index]}"
|
||||
if [[ $current_target == "resume" ]]; then
|
||||
if (( target_index + 1 >= ${#TARGETS[@]} )); then
|
||||
error "target 'resume' requires a session identifier"
|
||||
fi
|
||||
process_resume_target "${TARGETS[$((target_index + 1))]}"
|
||||
((target_index+=2))
|
||||
continue
|
||||
fi
|
||||
dispatch_target "$current_target"
|
||||
((target_index+=1))
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user