Add uninstall command

main v0.0.3
William Beuil 2021-01-25 15:36:44 +01:00
parent 5eed7949c1
commit aa8e822c71
No known key found for this signature in database
GPG Key ID: BED2072C5C2BF537
2 changed files with 31 additions and 0 deletions

View File

@ -94,6 +94,16 @@ $ dctlenv list-remote
0.2.3
```
### `dctlenv uninstall [<version>]`
Uninstall a specific version of driftctl.
```shell
$ dctlenv uninstall 0.2.3
Uninstall driftctl v0.2.3
driftctl v0.2.3 is successfully uninstalled
```
### `dctlenv root`
Display the root directory where dctlenv is.

21
libexec/dctlenv-uninstall Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -uo pipefail
[ "$#" -gt 1 ] && log_error "Need 1 version instead of $#" 'usage: dctlenv uninstall [<version>]'
version_requested="${1:-""}"
[ -n "$version_requested" ] || log_error 'Version is not specified' 'usage: dctlenv uninstall [<version>]'
version="$(dctlenv-list 2>/dev/null | sed -E 's/^(\*| )? //g; s/ \(set by .+\)$//' | grep -e "$version_requested" | head -n 1)"
[ -n "$version" ] || log_error "No versions matching '$version_requested' found in local"
dst_path="$DCTLENV_ROOT/versions/$version"
if [ -f "$dst_path/driftctl" ]; then
echo "Uninstall driftctl v$version"
rm -r "$dst_path"
# If no versions remain, remove the versions directory
rmdir "$DCTLENV_ROOT/versions" 2>/dev/null
echo "driftctl v$version is successfully uninstalled"
fi