feat(setup): add force flag

This commit is contained in:
2024-08-03 04:01:41 +02:00
parent e5e6e83488
commit d89c157503
+12 -4
View File
@@ -12,6 +12,7 @@ SOURCE_DIR="$SCRIPT_DIR"
DEST_DIR="$HOME" DEST_DIR="$HOME"
PRINT_HELP=false PRINT_HELP=false
FORCE=false
REMOVE_EXISTING=false REMOVE_EXISTING=false
IGNORE_EXISTING=false IGNORE_EXISTING=false
ERROR=false ERROR=false
@@ -131,8 +132,10 @@ create_symlink() {
fi fi
if test -L "$dst"; then if test -L "$dst"; then
if $IGNORE_EXISTING; then if $FORCE; then
remove_symlink "$2" remove_symlink "$2"
elif $IGNORE_EXISTING; then
return
else else
error "path already exists:" error "path already exists:"
error "$dst" error "$dst"
@@ -173,9 +176,10 @@ print_help() {
echo "Usage: $SCRIPT_NAME [...]" echo "Usage: $SCRIPT_NAME [...]"
echo "" echo ""
echo "Options:" echo "Options:"
echo " -h, --help Print this help message" echo " -h, --help Print this help message"
echo " -i, --ignore-existing Ignore existing symlinks" echo " -f, --force Overwrite any existing links"
echo " -r, --remove-existing Remove any existing symlinks" echo " -i, --ignore-existing Ignore existing symlinks"
echo " -r, --remove-existing Remove any existing symlinks"
} }
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
@@ -184,6 +188,10 @@ while [ $# -gt 0 ]; do
PRINT_HELP=true PRINT_HELP=true
shift shift
;; ;;
-f|--force)
FORCE=true
shift
;;
-r|--remove-existing) -r|--remove-existing)
REMOVE_EXISTING=true REMOVE_EXISTING=true
shift shift