diff --git a/changelog/dub-remove.dd b/changelog/dub-remove.dd new file mode 100644 index 0000000..b297d45 --- /dev/null +++ b/changelog/dub-remove.dd @@ -0,0 +1,9 @@ +`dub remove --non-interactive` will now remove all packages by default + +When calling a command with a package name and no version specification, +the latest version is usually assumed. +While this behavior makes sense for `dub fetch` or `dub run`, +it can come as a surprise when cleaning up local packages through `dub remove`, +and so previous version would simply error out when more than one version was available. +From this version, `dub remove -n $PKGNAME` will just remove all cached versions +of the package named `$PKGNAME`, without asking you to use `$PKGNAME@*`. diff --git a/source/dub/dub.d b/source/dub/dub.d index 39a5b71..318b79a 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -1026,17 +1026,9 @@ void remove(string package_id, string version_, PlacementLocation location) { remove(package_id, location, (in packages) { - if (version_ == RemoveVersionWildcard) + if (version_ == RemoveVersionWildcard || version_.empty) return packages.length; - if (version_.empty && packages.length > 1) { - logError("Cannot remove package '" ~ package_id ~ "', there are multiple possibilities at location\n" - ~ "'" ~ to!string(location) ~ "'."); - logError("Available versions:"); - foreach(pack; packages) - logError(" %s", pack.version_); - throw new Exception("Please specify a individual version using --version=... or use the" - ~ " wildcard --version=" ~ RemoveVersionWildcard ~ " to remove all versions."); - } + foreach (i, p; packages) { if (p.version_ == Version(version_)) return i; diff --git a/test/fetchzip.sh b/test/fetchzip.sh index 226b0e8..7b760f8 100755 --- a/test/fetchzip.sh +++ b/test/fetchzip.sh @@ -5,7 +5,7 @@ PORT=$(getRandomPort) -$DUB remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null || true +$DUB remove gitcompatibledubpackage --non-interactive 2>/dev/null || true "$DUB" build --single "$DIR"/test_registry.d "$DIR"/test_registry --folder="$DIR/issue1336-registry" --port=$PORT & @@ -32,7 +32,7 @@ elif [ $rc -eq 124 ]; then die 'DUB timed out unexpectedly.' fi -if dub remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null; then +if dub remove gitcompatibledubpackage --non-interactive 2>/dev/null; then die 'DUB should not have installed a broken package.' fi @@ -47,7 +47,7 @@ elif [ $rc -eq 124 ]; then die 'DUB timed out unexpectedly.' fi -if $DUB remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null; then +if $DUB remove gitcompatibledubpackage --non-interactive 2>/dev/null; then die 'DUB should not have installed a package.' fi diff --git a/test/interactive-remove.sh b/test/interactive-remove.sh index 387323d..c3148d1 100755 --- a/test/interactive-remove.sh +++ b/test/interactive-remove.sh @@ -7,32 +7,34 @@ # Ideally, we should not have this run by default / run it in a container. # In the meantime, in order to make it pass on developer's machines, # we need to nuke every `dub` version in the user cache... -$DUB remove dub -n --version=* || true +$DUB remove dub -n || true $DUB fetch dub --version=1.9.0 && [ -d $HOME/.dub/packages/dub-1.9.0/dub ] $DUB fetch dub --version=1.10.0 && [ -d $HOME/.dub/packages/dub-1.10.0/dub ] -if $DUB remove dub --non-interactive 2>/dev/null; then - die $LINENO 'Non-interactive remove should fail' -fi + echo 1 | $DUB remove dub | tr -d '\n' | grep --ignore-case 'select.*1\.9\.0.*1\.10\.0.*' if [ -d $HOME/.dub/packages/dub-1.9.0/dub ]; then die $LINENO 'Failed to remove dub-1.9.0' fi + $DUB fetch dub --version=1.9.0 && [ -d $HOME/.dub/packages/dub-1.9.0/dub ] # EOF aborts remove echo -xn '' | $DUB remove dub if [ ! -d $HOME/.dub/packages/dub-1.9.0/dub ] || [ ! -d $HOME/.dub/packages/dub-1.10.0/dub ]; then die $LINENO 'Aborted dub still removed a package' fi + # validates input echo -e 'abc\n4\n-1\n3' | $DUB remove dub if [ -d $HOME/.dub/packages/dub-1.9.0/dub ] || [ -d $HOME/.dub/packages/dub-1.10.0/dub ]; then die $LINENO 'Failed to remove all version of dub' fi + $DUB fetch dub --version=1.9.0 && [ -d $HOME/.dub/packages/dub-1.9.0/dub ] $DUB fetch dub@1.10.0 && [ -d $HOME/.dub/packages/dub-1.10.0/dub ] -# is non-interactive with --version= -$DUB remove dub --version=\* +# is non-interactive with `--version=` +$DUB remove dub@1.9.0 +$DUB remove dub@1.10.0 if [ -d $HOME/.dub/packages/dub-1.9.0/dub ] || [ -d $HOME/.dub/packages/dub-1.10.0/dub ]; then die $LINENO 'Failed to non-interactively remove specified versions' fi diff --git a/test/issue1180-local-cache-broken.sh b/test/issue1180-local-cache-broken.sh index 0a83177..6615a32 100755 --- a/test/issue1180-local-cache-broken.sh +++ b/test/issue1180-local-cache-broken.sh @@ -5,7 +5,7 @@ PORT=$(getRandomPort) -"$DUB" remove maven-dubpackage --root="$DIR/issue1180-local-cache-broken" --non-interactive --version=* 2>/dev/null || true +"$DUB" remove maven-dubpackage --root="$DIR/issue1180-local-cache-broken" --non-interactive 2>/dev/null || true "$DUB" build --single "$DIR"/test_registry.d "$DIR"/test_registry --folder="$DIR/issue1416-maven-repo-pkg-supplier" --port=$PORT & diff --git a/test/issue1401-filesystem-supplier.sh b/test/issue1401-filesystem-supplier.sh index 1367fc6..2fe7e9b 100755 --- a/test/issue1401-filesystem-supplier.sh +++ b/test/issue1401-filesystem-supplier.sh @@ -3,8 +3,8 @@ . "$DIR"/common.sh -dub remove fs-json-dubpackage --non-interactive --version=* 2>/dev/null || true -dub remove fs-sdl-dubpackage --non-interactive --version=* 2>/dev/null || true +dub remove fs-json-dubpackage --non-interactive 2>/dev/null || true +dub remove fs-sdl-dubpackage --non-interactive 2>/dev/null || true echo "Trying to get fs-sdl-dubpackage (1.0.5)" "$DUB" fetch fs-sdl-dubpackage --version=1.0.5 --skip-registry=all --registry=file://"$DIR"/issue1401-file-system-pkg-supplier diff --git a/test/issue1416-maven-repo-pkg-supplier.sh b/test/issue1416-maven-repo-pkg-supplier.sh index 3aca25b..10eb68d 100755 --- a/test/issue1416-maven-repo-pkg-supplier.sh +++ b/test/issue1416-maven-repo-pkg-supplier.sh @@ -5,7 +5,7 @@ PORT=$(getRandomPort) -dub remove maven-dubpackage --non-interactive --version=* 2>/dev/null || true +$DUB remove maven-dubpackage --non-interactive 2>/dev/null || true "$DUB" build --single "$DIR"/test_registry.d "$DIR"/test_registry --folder="$DIR/issue1416-maven-repo-pkg-supplier" --port=$PORT & diff --git a/test/issue1524-maven-upgrade-dependency-tree.sh b/test/issue1524-maven-upgrade-dependency-tree.sh index 24f5f65..c77cb36 100755 --- a/test/issue1524-maven-upgrade-dependency-tree.sh +++ b/test/issue1524-maven-upgrade-dependency-tree.sh @@ -5,8 +5,8 @@ PORT=$(getRandomPort) -dub remove maven-dubpackage-a --non-interactive --version=* 2>/dev/null || true -dub remove maven-dubpackage-b --non-interactive --version=* 2>/dev/null || true +dub remove maven-dubpackage-a --non-interactive 2>/dev/null || true +dub remove maven-dubpackage-b --non-interactive 2>/dev/null || true "$DUB" build --single "$DIR"/test_registry.d "$DIR"/test_registry --folder="$DIR/issue1524-maven-upgrade-dependency-tree" --port=$PORT & diff --git a/test/issue1556-fetch-and-build.sh b/test/issue1556-fetch-and-build.sh index 9e2fec4..6bef98d 100755 --- a/test/issue1556-fetch-and-build.sh +++ b/test/issue1556-fetch-and-build.sh @@ -3,8 +3,8 @@ . "$DIR"/common.sh -dub remove main-package --non-interactive --version=* 2>/dev/null || true -dub remove dependency-package --non-interactive --version=* 2>/dev/null || true +dub remove main-package --non-interactive 2>/dev/null || true +dub remove dependency-package --non-interactive 2>/dev/null || true echo "Trying to fetch fs-sdl-dubpackage" diff --git a/test/issue1567-fetch-sub-package.sh b/test/issue1567-fetch-sub-package.sh index 98ec125..7be7d17 100755 --- a/test/issue1567-fetch-sub-package.sh +++ b/test/issue1567-fetch-sub-package.sh @@ -4,9 +4,9 @@ packname="fetch-sub-package-dubpackage" sub_packagename="my-sub-package" -$DUB remove $packname --non-interactive --version=* 2>/dev/null || true +$DUB remove $packname --non-interactive 2>/dev/null || true $DUB fetch "$packname:$sub_packagename" --skip-registry=all --registry=file://"$DIR"/issue1567-fetch-sub-package if ! dub remove $packname --non-interactive --version=1.0.1 2>/dev/null; then die 'DUB did not install package $packname:$sub_packagename.' -fi \ No newline at end of file +fi diff --git a/test/issue1651-custom-dub-init-type.sh b/test/issue1651-custom-dub-init-type.sh index 5c48313..0efafa9 100755 --- a/test/issue1651-custom-dub-init-type.sh +++ b/test/issue1651-custom-dub-init-type.sh @@ -3,7 +3,7 @@ DIR=$(dirname "${BASH_SOURCE[0]}") packname="custom-dub-init-type-sample" -$DUB remove custom-dub-init-dubpackage --non-interactive --version=* 2>/dev/null || true +$DUB remove custom-dub-init-dubpackage --non-interactive 2>/dev/null || true $DUB init -n $packname --format sdl -t custom-dub-init-dubpackage --skip-registry=all --registry=file://"$DIR"/issue1651-custom-dub-init-type -- --foo=bar function cleanup { @@ -22,4 +22,4 @@ die $LINENO 'Custom init type.' fi cd .. -cleanup \ No newline at end of file +cleanup diff --git a/test/issue990-download-optional-selected.sh b/test/issue990-download-optional-selected.sh index f46e4ca..36fd4ad 100755 --- a/test/issue990-download-optional-selected.sh +++ b/test/issue990-download-optional-selected.sh @@ -3,5 +3,5 @@ . $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue990-download-optional-selected ${DUB} clean -${DUB} remove gitcompatibledubpackage -n --version=* 2>/dev/null || true +${DUB} remove gitcompatibledubpackage -n 2>/dev/null || true ${DUB} run