diff --git a/README.md b/README.md index eee32a8..c8f2ac8 100644 --- a/README.md +++ b/README.md @@ -287,3 +287,13 @@ on several packages in parallel via git. Details can be found > and in the pack collection). > You can see an example of such usage [here](https://github.com/stefan-hoeck/idris2-pack-db/blob/bcc8dc61706c73361bb1e6e18dd1b0c5981f0e18/collections/HEAD.toml#L297). > Technical details can be found [here](https://github.com/stefan-hoeck/idris2-pack/issues/256#issuecomment-1689305587). + +## Uninstallation + +If you would like to uninstall pack from your system, you can simply use the following command: + +```sh +pack uninstall +``` + +This will delete the `$PACK_DIR` directory. diff --git a/install.bash b/install.bash index 0945805..7960e77 100755 --- a/install.bash +++ b/install.bash @@ -43,7 +43,7 @@ fi if [ -d "$PACK_DIR" ]; then echo "There is already a $PACK_DIR directory." - echo "Please remove it with 'rm -fr $PACK_DIR' and rerun this script." + echo "Please remove it with the 'pack uninstall' command and rerun this script." exit 1 fi diff --git a/src/Pack/CmdLn/Completion.idr b/src/Pack/CmdLn/Completion.idr index 0c13f9f..1461a9a 100644 --- a/src/Pack/CmdLn/Completion.idr +++ b/src/Pack/CmdLn/Completion.idr @@ -138,6 +138,7 @@ opts x "switch" = prefixOnlyIfNonEmpty x . ("latest" ::) opts x "clean" = prefixOnlyIfNonEmpty x <$> ipkgFiles opts x "typecheck" = prefixOnlyIfNonEmpty x <$> ipkgFiles opts x "new" = prefixOnlyIfNonEmpty x <$> pure packageTypes +opts x "uninstall" = pure Nil opts x "help" = prefixOnlyIfNonEmpty x <$> pure commands -- options diff --git a/src/Pack/CmdLn/Types.idr b/src/Pack/CmdLn/Types.idr index d0e5aac..3551b47 100644 --- a/src/Pack/CmdLn/Types.idr +++ b/src/Pack/CmdLn/Types.idr @@ -89,6 +89,9 @@ data Cmd : Type where Completion : Cmd CompletionScript : Cmd + -- Uninstall + Uninstall : Cmd + -- Help PrintHelp : Cmd @@ -126,6 +129,7 @@ commands = , Fuzzy , Completion , CompletionScript + , Uninstall , PrintHelp ] @@ -160,6 +164,7 @@ name Query = "query" name Fuzzy = "fuzzy" name Completion = "completion" name CompletionScript = "completion-script" +name Uninstall = "uninstall" name PrintHelp = "help" ||| List pairing a command with its name used for parsing commands. @@ -387,6 +392,11 @@ cmdDesc CompletionScript = """ for your shell. """ +cmdDesc Uninstall = """ + Uninstalls pack. + Deletes the $PACK_DIR directory. + """ + cmdDesc PrintHelp = """ Without an additional argument, this prints general information about using pack, including a list of available command-line options @@ -438,4 +448,5 @@ cmdInCommands Query = %search cmdInCommands Fuzzy = %search cmdInCommands Completion = %search cmdInCommands CompletionScript = %search +cmdInCommands Uninstall = %search cmdInCommands PrintHelp = %search diff --git a/src/Pack/Runner.idr b/src/Pack/Runner.idr index f66ac80..05637f5 100644 --- a/src/Pack/Runner.idr +++ b/src/Pack/Runner.idr @@ -13,6 +13,7 @@ import Pack.Runner.Develop import Pack.Runner.Query import Pack.Runner.Install import Pack.Runner.New +import Pack.Runner.Uninstall public export Command Cmd where @@ -52,6 +53,7 @@ Command Cmd where defaultLevel Fuzzy = Cache defaultLevel Completion = Silence defaultLevel CompletionScript = Silence + defaultLevel Uninstall = Info defaultLevel PrintHelp = Silence desc = cmdDesc @@ -84,6 +86,7 @@ Command Cmd where ArgTypes Fuzzy = [FuzzyQuery] ArgTypes Completion = [String, String] ArgTypes CompletionScript = [String] + ArgTypes Uninstall = [] ArgTypes PrintHelp = [Maybe Cmd] readCommand_ n = lookup n namesAndCommands @@ -127,6 +130,7 @@ Command Cmd where readArgs Fuzzy = %search readArgs Completion = %search readArgs CompletionScript = %search + readArgs Uninstall = %search readArgs PrintHelp = %search isFetch : Cmd -> Bool @@ -179,3 +183,4 @@ runCmd = do env <- idrisEnv mc fetch install [] writeCollection + (Uninstall ** []) => uninstallPack @{metaConfigToLogRef @{mc}} diff --git a/src/Pack/Runner/Uninstall.idr b/src/Pack/Runner/Uninstall.idr new file mode 100644 index 0000000..3e6540c --- /dev/null +++ b/src/Pack/Runner/Uninstall.idr @@ -0,0 +1,27 @@ +module Pack.Runner.Uninstall + +import Pack.Config.Types +import Pack.Core.IO +import Pack.Core.Logging +import Pack.Core.Types + +%hide Pack.Config.Types.Env.packDir + +%default total + +-------------------------------------------------------------------------------- +-- Uninstalling Pack +-------------------------------------------------------------------------------- + +export covering +uninstallPack : + {auto _ : LogRef} + -> {auto _ : PackDir} + -> {auto _ : HasIO io} + -> EitherT PackErr io () +uninstallPack = do + info "Uninstalling pack" + let msg := "This command will delete the $PACK_DIR directory at \{packDir}. Continue (yes/*no)?" + "yes" <- prompt Info msg + | _ => throwE SafetyAbort + rmDir packDir