Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ feature ] New Pack Command: Uninstall #299

Merged
merged 7 commits into from
Aug 13, 2024
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Pack/CmdLn/Completion.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/Pack/CmdLn/Types.idr
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ data Cmd : Type where
Completion : Cmd
CompletionScript : Cmd

-- Uninstall
Uninstall : Cmd

-- Help
PrintHelp : Cmd

Expand Down Expand Up @@ -126,6 +129,7 @@ commands =
, Fuzzy
, Completion
, CompletionScript
, Uninstall
, PrintHelp
]

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -387,6 +392,11 @@ cmdDesc CompletionScript = """
for your shell.
"""

cmdDesc Uninstall = """
Uninstalls pack.
Deletes the $PACK_DIR directory.
"""

cmdDesc PrintHelp = """
Without an additional <cmd> argument, this prints general information
about using pack, including a list of available command-line options
Expand Down Expand Up @@ -438,4 +448,5 @@ cmdInCommands Query = %search
cmdInCommands Fuzzy = %search
cmdInCommands Completion = %search
cmdInCommands CompletionScript = %search
cmdInCommands Uninstall = %search
cmdInCommands PrintHelp = %search
5 changes: 5 additions & 0 deletions src/Pack/Runner.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,6 +53,7 @@ Command Cmd where
defaultLevel Fuzzy = Cache
defaultLevel Completion = Silence
defaultLevel CompletionScript = Silence
defaultLevel Uninstall = Info
defaultLevel PrintHelp = Silence

desc = cmdDesc
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -179,3 +183,4 @@ runCmd = do
env <- idrisEnv mc fetch
install []
writeCollection
(Uninstall ** []) => uninstallPack @{metaConfigToLogRef @{mc}}
27 changes: 27 additions & 0 deletions src/Pack/Runner/Uninstall.idr
Original file line number Diff line number Diff line change
@@ -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
Loading