#!/usr/bin/env bash # hosts.module.sh — host resolution helpers function hosts::exists() { local entry_type="${1:-host}" key="${2:-}" [[ "$(json::hosts_exists "$(ctx::hosts)" "$entry_type" "$key")" == "true" ]] } function hosts::require_exists() { local entry_type="${1:-host}" key="${2:-}" if ! hosts::exists "$entry_type" "$key"; then log::error "${entry_type^} not found: ${key}" return 1 fi } function hosts::resolve_ip() { local ip="${1:-}" [[ -z "$ip" ]] && return 0 [[ ! -f "$(ctx::hosts)" ]] && echo "" && return 0 json::hosts_lookup "$(ctx::hosts)" "$ip" }