feat: add replace subcommand with multi-pattern support

This commit is contained in:
Rogee
2025-10-29 17:46:54 +08:00
parent fa57af8a26
commit ceea09f7be
42 changed files with 1848 additions and 14 deletions

42
scripts/smoke-test-replace.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BIN="go run"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
mkdir -p "$TMP_DIR/nested"
touch "$TMP_DIR/foo_draft.txt"
touch "$TMP_DIR/nested/bar_draft.txt"
echo "Previewing replacements..."
$BIN "$ROOT_DIR/main.go" replace draft Draft final --path "$TMP_DIR" --recursive --dry-run >/dev/null
echo "Applying replacements..."
$BIN "$ROOT_DIR/main.go" replace draft Draft final --path "$TMP_DIR" --recursive --yes >/dev/null
if [[ ! -f "$TMP_DIR/foo_final.txt" ]]; then
echo "expected foo_final.txt to exist" >&2
exit 1
fi
if [[ ! -f "$TMP_DIR/nested/bar_final.txt" ]]; then
echo "expected bar_final.txt to exist" >&2
exit 1
fi
echo "Undoing replacements..."
$BIN "$ROOT_DIR/main.go" undo --path "$TMP_DIR" >/dev/null
if [[ ! -f "$TMP_DIR/foo_draft.txt" ]]; then
echo "undo failed to restore foo_draft.txt" >&2
exit 1
fi
if [[ ! -f "$TMP_DIR/nested/bar_draft.txt" ]]; then
echo "undo failed to restore nested/bar_draft.txt" >&2
exit 1
fi
echo "Smoke test succeeded."