118 líneas
2.8 KiB
Bash
Archivo Ejecutable
118 líneas
2.8 KiB
Bash
Archivo Ejecutable
#!/usr/bin/env bash
|
|
# ejemplo_uso_avanzado.sh
|
|
# Demuestra diferentes casos de uso de topdir.sh
|
|
|
|
set -e
|
|
|
|
TOPDIR="./topdir.sh"
|
|
DEMO_DIR="./demo_avanzado"
|
|
|
|
echo "=== Limpiando demo anterior ==="
|
|
rm -rf "$DEMO_DIR"
|
|
mkdir -p "$DEMO_DIR"/{src,tests,docs,logs,build}
|
|
|
|
echo ""
|
|
echo "=== 1. Creando estructura inicial ==="
|
|
cat > "$DEMO_DIR/src/main.py" <<EOF
|
|
def main():
|
|
print("Hello World")
|
|
EOF
|
|
|
|
cat > "$DEMO_DIR/tests/test_main.py" <<EOF
|
|
def test_main():
|
|
assert True
|
|
EOF
|
|
|
|
echo "Documentation" > "$DEMO_DIR/docs/README.md"
|
|
echo "Build output" > "$DEMO_DIR/build/output.so"
|
|
echo "Log entry" > "$DEMO_DIR/logs/app.log"
|
|
|
|
echo ""
|
|
echo "=== 2. Primera ejecución - Crear snapshot (formato texto) ==="
|
|
$TOPDIR "$DEMO_DIR"
|
|
|
|
echo ""
|
|
echo "=== 3. Modificar archivos y añadir nuevos ==="
|
|
cat >> "$DEMO_DIR/src/main.py" <<EOF
|
|
|
|
def helper():
|
|
return 42
|
|
EOF
|
|
|
|
cat > "$DEMO_DIR/src/utils.py" <<EOF
|
|
def util_func():
|
|
pass
|
|
EOF
|
|
|
|
echo "More logs" >> "$DEMO_DIR/logs/app.log"
|
|
echo "More build" >> "$DEMO_DIR/build/output.so"
|
|
|
|
echo ""
|
|
echo "=== 4. Segunda ejecución - Ver cambios (formato texto) ==="
|
|
$TOPDIR "$DEMO_DIR"
|
|
|
|
echo ""
|
|
echo "=== 5. Usar snapshot personalizado con formato JSON ==="
|
|
$TOPDIR --snapshot-file /tmp/demo.snapshot --format json "$DEMO_DIR" | jq '.'
|
|
|
|
echo ""
|
|
echo "=== 6. Crear .topdirignore para excluir logs y build ==="
|
|
cat > "$DEMO_DIR/.topdirignore" <<EOF
|
|
logs/*
|
|
build/*
|
|
*.log
|
|
*.so
|
|
EOF
|
|
|
|
echo ""
|
|
echo "=== 7. Ejecutar con exclusiones (formato CSV) ==="
|
|
$TOPDIR --format csv "$DEMO_DIR"
|
|
|
|
echo ""
|
|
echo "=== 8. Usar diferentes algoritmos de hash ==="
|
|
echo "Snapshot con MD5:"
|
|
$TOPDIR --hash md5 --snapshot-file /tmp/demo_md5.snap "$DEMO_DIR"
|
|
|
|
echo ""
|
|
echo "Añadir un archivo nuevo:"
|
|
echo "New content" > "$DEMO_DIR/src/new_file.py"
|
|
|
|
echo ""
|
|
echo "Detectar con MD5 + JSON:"
|
|
$TOPDIR --hash md5 --snapshot-file /tmp/demo_md5.snap --format json "$DEMO_DIR" | jq '.new'
|
|
|
|
echo ""
|
|
echo "=== 9. Exclusiones múltiples por CLI ==="
|
|
echo "Test file" > "$DEMO_DIR/tests/test_new.py"
|
|
echo "Temp file" > "$DEMO_DIR/temp.tmp"
|
|
echo "Cache file" > "$DEMO_DIR/.cache"
|
|
|
|
$TOPDIR --exclude "*.tmp" --exclude ".*" --exclude "tests/*" --format csv "$DEMO_DIR"
|
|
|
|
echo ""
|
|
echo "=== 10. Comparación completa con todas las opciones ==="
|
|
$TOPDIR \
|
|
--hash sha1 \
|
|
--format json \
|
|
--exclude "logs/*" \
|
|
--exclude "build/*" \
|
|
--snapshot-file /tmp/demo_final.snap \
|
|
"$DEMO_DIR" | jq '{
|
|
total_new: (.new | length),
|
|
total_modified: (.modified | length),
|
|
total_deleted: (.deleted | length),
|
|
files: {
|
|
new: .new,
|
|
modified: .modified,
|
|
deleted: .deleted
|
|
}
|
|
}'
|
|
|
|
echo ""
|
|
echo "=== Demo completada ==="
|
|
echo "Archivos de snapshot creados:"
|
|
ls -lh /tmp/demo*.snap 2>/dev/null || echo " (ninguno en /tmp)"
|
|
echo ""
|
|
echo "Estructura final de $DEMO_DIR:"
|
|
tree "$DEMO_DIR" 2>/dev/null || find "$DEMO_DIR" -type f
|