Replace manual confirmations with [confirm] attribute in destructive commands

- Add [confirm] attribute to all destructive operations:
  - volumes-clean-all, volumes-remove, volumes-remove-pattern
  - postgres-drop-database, postgres-restore
  - mysql-drop-database, mysql-restore
- Remove manual read -p confirmations and conditional logic
- Simplifies code and uses Just's built-in confirmation system
- Ensures consistent confirmation behavior across all destructive operations

This provides better UX and cleaner code using Just's native features.
This commit is contained in:
sha
2025-09-27 01:44:12 +03:00
parent 5fd0e0370c
commit c359858ee9
4 changed files with 53 additions and 55 deletions
+6 -17
View File
@@ -128,6 +128,7 @@ mysql-create-database database service="mysql" compose-file="":
fi
# Drop MySQL database
[confirm]
mysql-drop-database database service="mysql" compose-file="":
#!/usr/bin/env bash
set -euo pipefail
@@ -149,18 +150,12 @@ mysql-drop-database database service="mysql" compose-file="":
fi
echo -e "{{YELLOW}}WARNING: This will permanently delete database: $database{{NC}}"
read -p "Are you sure? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "{{BLUE}}Dropping MySQL database: $database{{NC}}"
echo -e "{{BLUE}}Dropping MySQL database: $database{{NC}}"
if [ -n "$file_arg" ]; then
just exec "$service" "mysql -u root -p\${MYSQL_ROOT_PASSWORD} -e 'DROP DATABASE \`$database\`;'" "$file_arg"
else
just exec "$service" "mysql -u root -p\${MYSQL_ROOT_PASSWORD} -e 'DROP DATABASE \`$database\`;'"
fi
if [ -n "$file_arg" ]; then
just exec "$service" "mysql -u root -p\${MYSQL_ROOT_PASSWORD} -e 'DROP DATABASE \`$database\`;'" "$file_arg"
else
echo "Operation cancelled"
just exec "$service" "mysql -u root -p\${MYSQL_ROOT_PASSWORD} -e 'DROP DATABASE \`$database\`;'"
fi
# Create MySQL user
@@ -247,6 +242,7 @@ mysql-shell service="mysql" compose-file="":
# Restore MySQL database from backup file
[group('database')]
[confirm]
mysql-restore backup_file database service="mysql" compose-file="" backup_path="./backups":
#!/usr/bin/env bash
set -euo pipefail
@@ -302,13 +298,6 @@ mysql-restore backup_file database service="mysql" compose-file="" backup_path="
echo -e "{{YELLOW}}Make sure you have a backup of current data if needed{{NC}}"
echo ""
read -p "Are you sure you want to restore '$database' from '$backup_file'? Type 'yes' to continue: " confirm
if [ "$confirm" != "yes" ]; then
echo "Restore cancelled"
exit 1
fi
echo -e "{{BLUE}}Restoring database '$database' from $backup_file...{{NC}}"
# Restore database from backup file