refactor: Improve script robustness by returning from functions
This commit is contained in:
parent
a78ae843a7
commit
d69b7622a3
5 changed files with 11 additions and 11 deletions
|
|
@ -16,10 +16,10 @@ check_deps() {
|
|||
|
||||
if [[ ${#missing[@]} -gt 0 ]]; then
|
||||
error "Missing required tools: ${missing[*]}"
|
||||
echo -e "\nInstall them using your package manager:"
|
||||
echo " Debian/Ubuntu: sudo apt install ${missing[*]}"
|
||||
echo " MacOS: brew install ${missing[*]}"
|
||||
exit 1
|
||||
printf "\nInstall them using your package manager:\n"
|
||||
printf " Debian/Ubuntu: sudo apt install %s\n" "${missing[*]}"
|
||||
printf " MacOS: brew install %s\n" "${missing[*]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
success "Environment check passed: all required tools found."
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ gcrypt_rotate_key() {
|
|||
else
|
||||
error "Old key not found at: ${old_key_path}"
|
||||
error "Unlock manually before rotating: git-crypt unlock /path/to/${genome_name}.key"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
info "Repository is already unlocked — proceeding."
|
||||
|
|
@ -92,7 +92,7 @@ gcrypt_rotate_key() {
|
|||
# 2. Ensure working tree is clean (private files excluded — they will be re-staged)
|
||||
if ! git diff --quiet -- ':!raw/private' ':!wiki/private' 2>/dev/null; then
|
||||
error "Working tree has uncommitted changes outside private/. Commit or stash them first."
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 3. Remove old key material only (preserves .git/git-crypt/ structure)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ render_template() {
|
|||
local template_file="$1"
|
||||
local output_file="$2"
|
||||
|
||||
[[ ! -f "$template_file" ]] && { error "Template not found: ${template_file}"; exit 1; }
|
||||
[[ ! -f "$template_file" ]] && { error "Template not found: ${template_file}"; return 1; }
|
||||
|
||||
local content
|
||||
content=$(cat "$template_file")
|
||||
content=$(<"$template_file")
|
||||
|
||||
# Placeholder replacement
|
||||
content="${content//\{\{GENOME_NAME\}\}/${GENOME_NAME}}"
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ provider_create_repo() {
|
|||
case "$http_code" in
|
||||
201) success "Repository '${name}' created successfully." ;;
|
||||
409) info "Repository '${name}' already exists - skipping." ;;
|
||||
401) error "Unauthorized. Check your FORGEJO_TOKEN."; exit 1 ;;
|
||||
*) error "Forgejo API returned HTTP ${http_code}. Check connectivity."; exit 1 ;;
|
||||
401) error "Unauthorized. Check your FORGEJO_TOKEN."; return 1 ;;
|
||||
*) error "Forgejo API returned HTTP ${http_code}. Check connectivity."; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ provider_create_repo() {
|
|||
case "$http_code" in
|
||||
201) success "Repository '${name}' created on GitHub." ;;
|
||||
422) info "Repository '${name}' already exists - skipping." ;;
|
||||
*) error "GitHub API returned HTTP ${http_code}. check token/permissions."; exit 1 ;;
|
||||
*) error "GitHub API returned HTTP ${http_code}. Check token/permissions."; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue