mirror of
https://oauth2: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@github.com/m1ngsama/automa.git
synced 2026-05-10 19:11:07 +08:00
feat: add -y/--yes non-interactive flag for CI and scripted deploys
Skip all prompts: accept defaults, auto-generate secrets, keep existing .env files, and auto-confirm deploy. Follows npm init -y pattern.
This commit is contained in:
parent
e5542de818
commit
ccb424286c
1 changed files with 81 additions and 46 deletions
41
automa
41
automa
|
|
@ -9,6 +9,7 @@ set -euo pipefail
|
|||
|
||||
AUTOMA_VERSION="1.0.0"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
YES=0 # set to 1 by -y/--yes to skip all prompts
|
||||
|
||||
# ============================================================================
|
||||
# Terminal
|
||||
|
|
@ -208,6 +209,10 @@ configure_env() {
|
|||
|
||||
# Handle existing .env
|
||||
if [[ -f "$env_file" ]]; then
|
||||
if [[ $YES -eq 1 ]]; then
|
||||
info "Keeping existing .env for ${name}"
|
||||
return 0
|
||||
fi
|
||||
echo ""
|
||||
dim ".env already exists for ${BOLD}${name}${NC}"
|
||||
echo ""
|
||||
|
|
@ -252,14 +257,27 @@ configure_env() {
|
|||
has_notes=1
|
||||
done < <(project_notes "$slug")
|
||||
|
||||
local tmp_env
|
||||
tmp_env="$(mktemp)"
|
||||
|
||||
if [[ $YES -eq 1 ]]; then
|
||||
# Non-interactive: accept all defaults, generate secrets
|
||||
while IFS= read -r line; do
|
||||
[[ -z "$line" || "$line" =~ ^# ]] && continue
|
||||
local key="${line%%=*}"
|
||||
local default="${line#*=}"
|
||||
if [[ -z "$default" && "$key" =~ PASSWORD|SECRET|TOKEN|AUTHKEY ]]; then
|
||||
default=$(generate_password)
|
||||
fi
|
||||
echo "${key}=${default}" >> "$tmp_env"
|
||||
done < "$env_example"
|
||||
info "Configuration generated for ${name}"
|
||||
else
|
||||
echo ""
|
||||
divider
|
||||
dim "Press ${BOLD}Enter${NC}${DIM} to accept [default] values${NC}"
|
||||
echo ""
|
||||
|
||||
local tmp_env
|
||||
tmp_env="$(mktemp)"
|
||||
|
||||
while IFS= read -r line; do
|
||||
# Blank line
|
||||
[[ -z "$line" ]] && continue
|
||||
|
|
@ -301,6 +319,7 @@ configure_env() {
|
|||
|
||||
echo ""
|
||||
divider
|
||||
fi
|
||||
|
||||
mv "$tmp_env" "$env_file"
|
||||
chmod 600 "$env_file"
|
||||
|
|
@ -410,8 +429,10 @@ cmd_deploy() {
|
|||
echo -e " ${CYAN}\xe2\x96\xb6${NC} ${s} ${DIM}${desc:-}${NC}"
|
||||
done
|
||||
echo ""
|
||||
if [[ $YES -eq 0 ]]; then
|
||||
read -rp " Proceed? [Y/n] " confirm
|
||||
[[ "${confirm:-y}" =~ ^[Nn] ]] && { echo ""; dim "Cancelled."; return 0; }
|
||||
fi
|
||||
|
||||
divider
|
||||
|
||||
|
|
@ -610,6 +631,9 @@ cmd_help() {
|
|||
${BOLD}Usage${NC}
|
||||
automa <command> [options]
|
||||
|
||||
${BOLD}Global flags${NC}
|
||||
${BOLD}-y, --yes${NC} Skip all prompts (accept defaults, auto-generate secrets)
|
||||
|
||||
${BOLD}Commands${NC}
|
||||
${BOLD}deploy${NC} [project...] Deploy projects interactively or by name
|
||||
${BOLD}list${NC} List all projects and their status
|
||||
|
|
@ -624,6 +648,7 @@ cmd_help() {
|
|||
${BOLD}Examples${NC}
|
||||
${DIM}\$${NC} automa deploy ${DIM}# interactive selection${NC}
|
||||
${DIM}\$${NC} automa deploy forgejo nextcloud ${DIM}# deploy by name${NC}
|
||||
${DIM}\$${NC} automa -y deploy forgejo ${DIM}# non-interactive (CI/scripts)${NC}
|
||||
${DIM}\$${NC} automa status ${DIM}# overview dashboard${NC}
|
||||
${DIM}\$${NC} automa logs minecraft ${DIM}# follow logs${NC}
|
||||
|
||||
|
|
@ -638,6 +663,16 @@ EOF
|
|||
# Main
|
||||
# ============================================================================
|
||||
main() {
|
||||
# Parse global flags
|
||||
while [[ "${1:-}" =~ ^- ]]; do
|
||||
case "$1" in
|
||||
-y|--yes) YES=1; shift ;;
|
||||
-h|--help) cmd_help; return ;;
|
||||
-v|--version) echo "automa v${AUTOMA_VERSION}"; return ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
local cmd="${1:-}"
|
||||
[[ -z "$cmd" ]] && { cmd_help; return; }
|
||||
shift
|
||||
|
|
|
|||
Loading…
Reference in a new issue