feat: Updates to hpa script.

This commit is contained in:
2025-11-05 17:22:19 -05:00
parent 36fd0558b0
commit ba81c53054

View File

@@ -27,10 +27,15 @@ CONSULT_TEMPLATE_URL="ssh://git@git.housh.dev:2222/hhe/consult-template.git"
HPA_PLAYBOOK_URL="ssh://git@git.housh.dev:2222/michael/ansible-hpa-playbook.git"
HPA_VAULT_SECRET_KEY="${HPA_VAULT_SECRET_KEY:-vault-pass}"
echoerr() {
echo -e "\e[31m[ERROR]:\e[0m $*"
}
generate-completion() {
local type=${1:-"zsh"}
local output=${2:-$HOME/.zsh/completions/_hpa}
local output_dir=$(dirname $output)
local output_dir output type
type=${1:-"zsh"}
output=${2:-$HOME/.zsh/completions/_hpa}
output_dir=$(dirname "$output")
[[ ! -d "$output_dir" ]] && mkdir -p "$output_dir"
(
@@ -41,8 +46,9 @@ generate-completion() {
}
gnnerate-secret() {
local secret="$(pass -c ansible/vault-pass)"
printf "$secret" | podman secret create "$HPA_VAULT_SECRET_KEY" -
local secret=""
secret="$(pass -c ansible/vault-pass)"
printf "%s" "$secret" | podman secret create "$HPA_VAULT_SECRET_KEY" -
}
# Ensure the dependencies are installed / setup.
@@ -65,13 +71,47 @@ run() {
"$HPA_DOCKER_IMAGE:$HPA_DOCKER_TAG" "$@"
}
# Helper to generate the project directory properly.
#
# This allows project to be created using `hpa create Customer`, and the project
# will be created with an actual directory named '25.11.05.Customer'.
#
# This also handles setting parent directory to the `/consults` directory inside
# the container, otherwise the project fails to get created.
#
# We also suppress all output and then generate the actual directory path on the local
# file system, so this command can be used like `cd -- $(hpa create Foo | tr -d '\r' | head -1)`.
create() {
local project project_container_name dir_name
project=${1:-""}
[[ -z $project ]] && echoerr "Must supply a project name." && exit 1
project_container_name="$(run create --quiet "/consults/$(date '+%Y.%m.%d').$project")"
dir_name="$(basename "$project_container_name")"
echo "$CONSULTS_DIR/$dir_name"
}
############################## MAIN ##############################
first_arg=${1:-""}
if [[ $first_arg == "init" ]]; then
shift
init "$@" && exit 0
init "$@"
elif [[ $first_arg == "create" ]]; then
shift
dir=$(create "$@")
# Initialize project as a git repo.
pushd "$(echo "$dir" | tr -d '\r' | head -1)" &>/dev/null || exit 1
(
git init
git add .
git commit --all --message="Initial commit"
) >&/dev/null
popd &>/dev/null
# Echo the project directory.
echo "$dir"
else
run "$@"
fi