feat(setup): add force flag

This commit is contained in:
Oscar Wallberg
2024-08-03 04:01:41 +02:00
parent 6af7e68509
commit 5384722cd5
+9 -1
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"
@@ -174,6 +177,7 @@ print_help() {
echo "" echo ""
echo "Options:" echo "Options:"
echo " -h, --help Print this help message" echo " -h, --help Print this help message"
echo " -f, --force Overwrite any existing links"
echo " -i, --ignore-existing Ignore existing symlinks" echo " -i, --ignore-existing Ignore existing symlinks"
echo " -r, --remove-existing Remove any existing symlinks" echo " -r, --remove-existing Remove any existing symlinks"
} }
@@ -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