PoC: flat and advanced mode

This commit is contained in:
2025-10-10 18:13:54 +02:00
commit 2b25bc17b3
14 changed files with 2040 additions and 0 deletions

78
example-api-usage.sh Normal file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# Example: Programmatic script generation using the API
# Demonstration of how to integrate the tool into automation workflows
# set -euo pipefail
# Start the server in the background
./argparse-builder &
SERVER_PID=$!
# Wait for server to be ready
sleep 2
# Define the script configuration
cat > config.json << 'EOF'
{
"header": "Database Backup Tool v1.0 - Automated PostgreSQL backup",
"arguments": [
{
"params": "-H --host HOST",
"command": "host",
"helpText": "Database host (default: localhost)"
},
{
"params": "-p --port NUM",
"command": "port",
"helpText": "Database port (default: 5432)"
},
{
"params": "-d --database NAME",
"command": "database",
"helpText": "Database name to backup"
},
{
"params": "-u --user NAME",
"command": "user",
"helpText": "Database username"
},
{
"params": "-o --output PATH",
"command": "output",
"helpText": "Output directory for backups"
},
{
"params": "-c --compress",
"command": "compress",
"helpText": "Compress backup with gzip"
},
{
"params": "-v --verbose",
"command": "verbose",
"helpText": "Enable verbose logging"
}
]
}
EOF
# Generate the script
curl -s -X POST http://localhost:8080/generate \
-H "Content-Type: application/json" \
-d @config.json \
-o db_backup.sh
# Make it executable
chmod +x db_backup.sh
echo "Generated script: db_backup.sh"
echo ""
echo "Test it with: ./db_backup.sh --help"
# Cleanup
kill $SERVER_PID 2>/dev/null || true
rm config.json
echo ""
echo "Generated script contents:"
echo "=========================="
cat db_backup.sh