From 561173b40bb00ed90676ddb455d2e531ec72eb78 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 30 Sep 2018 02:58:55 +0800 Subject: [PATCH] Add rm subcommand --- ghcup | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/ghcup b/ghcup index eb3944b..9b6d62a 100755 --- a/ghcup +++ b/ghcup @@ -59,6 +59,7 @@ SUBCOMMANDS: show Show current/installed GHC set Set currently active GHC version self-update Update this script in-place + rm Remove an already installed GHC DISCUSSION: ghcup installs the Glasgow Haskell Compiler from the official @@ -143,6 +144,22 @@ FLAGS: exit 1 } +rm_usage() { + (>&2 echo "ghcup-rm +Remove the given GHC version installed by ghcup + +USAGE: + ${SCRIPT} rm [FLAGS] + +FLAGS: + -h, --help Prints help information + +ARGS: + E.g. \"8.4.3\" or \"8.6.1\" +") + exit 1 +} + ## utilities ## @@ -474,6 +491,29 @@ show_ghc_installed() { unset real_ghc } +## rm subcommand ## + +rm_ghc() { + myghcver=$1 + inst_location=$(get_ghc_location "${myghcver}") + + [ -z "${myghcver}" ] && die "We are paranoid, ghcver not set" + + if ghc_already_installed "${myghcver}" ; then + for f in "${BIN_LOCATION}"/*-"${myghcver}" ; do + # https://tanguy.ortolo.eu/blog/article113/test-symlink + [ ! -e "${f}" ] && [ ! -h "${f}" ] && die "Something went wrong, ${f} does not exist!" + edo rm "${f}" + done + edo rm -r "${inst_location}" + else + warning_message "${myghcver} doesn't appear to be installed, skipping" + fi + + unset myghcver inst_location f +} + + ## command line parsing and entry point ## @@ -553,6 +593,18 @@ while [ $# -gt 0 ] ; do show_ghc fi break;; + rm) + shift 1 + while [ $# -gt 0 ] ; do + case $1 in + -h|--help) rm_usage;; + *) GHC_VER=$1 + break;; + esac + done + [ "${GHC_VER}" ] || rm_usage + rm_ghc "${GHC_VER}" + break;; *) usage;; esac break;;