Add mutual exclusion validation for conflict handling options

Ensure --force, --skip, --backup, --rename options are used exclusively
to prevent ambiguous conflict resolution behavior.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka Company
2026-01-28 14:05:32 +08:00
parent 51eae214cc
commit 45c8623666

View File

@@ -67,6 +67,19 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
# Validate mutual exclusion of conflict handling options
CONFLICT_OPTS_COUNT=0
[ "$FORCE" = true ] && CONFLICT_OPTS_COUNT=$((CONFLICT_OPTS_COUNT + 1))
[ "$SKIP" = true ] && CONFLICT_OPTS_COUNT=$((CONFLICT_OPTS_COUNT + 1))
[ "$BACKUP" = true ] && CONFLICT_OPTS_COUNT=$((CONFLICT_OPTS_COUNT + 1))
[ "$RENAME" = true ] && CONFLICT_OPTS_COUNT=$((CONFLICT_OPTS_COUNT + 1))
if [ $CONFLICT_OPTS_COUNT -gt 1 ]; then
echo "Error: Conflict handling options are mutually exclusive." >&2
echo "Use only one of: --force, --skip, --backup, --rename" >&2
exit 1
fi
# Check file path argument # Check file path argument
if [ -z "$FILE_PATH" ]; then if [ -z "$FILE_PATH" ]; then
echo "Usage: $0 <file_path> [subpath] [--force|--skip|--backup|--rename]" >&2 echo "Usage: $0 <file_path> [subpath] [--force|--skip|--backup|--rename]" >&2