From bf86d3c21b694c9a7c47e7b4f2ce73cf384e141e Mon Sep 17 00:00:00 2001 From: Matthew-Mosior Date: Fri, 2 Aug 2024 18:04:19 -0400 Subject: [PATCH 1/7] Adding files to support a uninstall pack command. --- src/Pack/CmdLn/Completion.idr | 1 + src/Pack/CmdLn/Types.idr | 12 ++++++++++++ src/Pack/Runner.idr | 7 +++++++ src/Pack/Runner/Uninstall.idr | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 src/Pack/Runner/Uninstall.idr diff --git a/src/Pack/CmdLn/Completion.idr b/src/Pack/CmdLn/Completion.idr index 0c13f9f..de9855d 100644 --- a/src/Pack/CmdLn/Completion.idr +++ b/src/Pack/CmdLn/Completion.idr @@ -139,6 +139,7 @@ opts x "clean" = prefixOnlyIfNonEmpty x <$> ipkgFiles opts x "typecheck" = prefixOnlyIfNonEmpty x <$> ipkgFiles opts x "new" = prefixOnlyIfNonEmpty x <$> pure packageTypes opts x "help" = prefixOnlyIfNonEmpty x <$> pure commands +opts x "uninstall" = pure Nil -- options opts x _ = pure $ diff --git a/src/Pack/CmdLn/Types.idr b/src/Pack/CmdLn/Types.idr index d0e5aac..a5bb842 100644 --- a/src/Pack/CmdLn/Types.idr +++ b/src/Pack/CmdLn/Types.idr @@ -92,6 +92,9 @@ data Cmd : Type where -- Help PrintHelp : Cmd + -- Uninstall + Uninstall : Cmd + ||| List of all available commands. ||| ||| `Pack.CmdLn.Types.cmdInCommands` proofs that none was forgotten. @@ -127,6 +130,7 @@ commands = , Completion , CompletionScript , PrintHelp + , Uninstall ] ||| Name to use at the command-line for running a pack command @@ -161,6 +165,7 @@ name Fuzzy = "fuzzy" name Completion = "completion" name CompletionScript = "completion-script" name PrintHelp = "help" +name Uninstall = "uninstall" ||| List pairing a command with its name used for parsing commands. public export @@ -399,6 +404,12 @@ cmdDesc PrintHelp = """ \{unlines $ map (indent 2 . fst) namesAndCommands} """ +cmdDesc Uninstall = """ + Uninstalls pack. + + Deletes the $PACK_DIR directory. +""" + export Arg Cmd where argDesc_ = "" @@ -439,3 +450,4 @@ cmdInCommands Fuzzy = %search cmdInCommands Completion = %search cmdInCommands CompletionScript = %search cmdInCommands PrintHelp = %search +cmdInCommands Uninstall = %search diff --git a/src/Pack/Runner.idr b/src/Pack/Runner.idr index f66ac80..bae939f 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 @@ -53,6 +54,7 @@ Command Cmd where defaultLevel Completion = Silence defaultLevel CompletionScript = Silence defaultLevel PrintHelp = Silence + defaultLevel Uninstall = Info desc = cmdDesc @@ -85,6 +87,7 @@ Command Cmd where ArgTypes Completion = [String, String] ArgTypes CompletionScript = [String] ArgTypes PrintHelp = [Maybe Cmd] + ArgTypes Uninstall = [] readCommand_ n = lookup n namesAndCommands @@ -128,6 +131,7 @@ Command Cmd where readArgs Completion = %search readArgs CompletionScript = %search readArgs PrintHelp = %search + readArgs Uninstall = %search isFetch : Cmd -> Bool isFetch Fetch = True @@ -179,3 +183,6 @@ runCmd = do env <- idrisEnv mc fetch install [] writeCollection + (Uninstall ** []) => do + env <- idrisEnv mc fetch + uninstallPack diff --git a/src/Pack/Runner/Uninstall.idr b/src/Pack/Runner/Uninstall.idr new file mode 100644 index 0000000..a38779a --- /dev/null +++ b/src/Pack/Runner/Uninstall.idr @@ -0,0 +1,19 @@ +module Pack.Runner.Uninstall + +import Pack.Config +import Pack.Core + +%default total + +-------------------------------------------------------------------------------- +-- Uninstalling Pack +-------------------------------------------------------------------------------- + +export covering +uninstallPack : + {auto _ : HasIO io} + -> {auto _ : Env} + -> EitherT PackErr io () +uninstallPack = do + info "Uninstalling pack" + rmDir packDir From 2b762ea1f55bbc3c1c173264e16e03ff81ab84df Mon Sep 17 00:00:00 2001 From: Matthew-Mosior Date: Fri, 2 Aug 2024 18:11:40 -0400 Subject: [PATCH 2/7] Updating README.md. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) 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. From 6090c48d443e408da6fd9f93e79216c6a02187a2 Mon Sep 17 00:00:00 2001 From: Matthew-Mosior Date: Sat, 3 Aug 2024 17:42:57 -0400 Subject: [PATCH 3/7] Adding user prompt to ensure choice when deciding to uninstall pack. --- src/Pack/CmdLn/Completion.idr | 2 +- src/Pack/CmdLn/Types.idr | 23 +++++++++++------------ src/Pack/Runner.idr | 6 +++--- src/Pack/Runner/Uninstall.idr | 11 +++++++++-- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Pack/CmdLn/Completion.idr b/src/Pack/CmdLn/Completion.idr index de9855d..1461a9a 100644 --- a/src/Pack/CmdLn/Completion.idr +++ b/src/Pack/CmdLn/Completion.idr @@ -138,8 +138,8 @@ 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 "help" = prefixOnlyIfNonEmpty x <$> pure commands opts x "uninstall" = pure Nil +opts x "help" = prefixOnlyIfNonEmpty x <$> pure commands -- options opts x _ = pure $ diff --git a/src/Pack/CmdLn/Types.idr b/src/Pack/CmdLn/Types.idr index a5bb842..3551b47 100644 --- a/src/Pack/CmdLn/Types.idr +++ b/src/Pack/CmdLn/Types.idr @@ -89,12 +89,12 @@ data Cmd : Type where Completion : Cmd CompletionScript : Cmd - -- Help - PrintHelp : Cmd - -- Uninstall Uninstall : Cmd + -- Help + PrintHelp : Cmd + ||| List of all available commands. ||| ||| `Pack.CmdLn.Types.cmdInCommands` proofs that none was forgotten. @@ -129,8 +129,8 @@ commands = , Fuzzy , Completion , CompletionScript - , PrintHelp , Uninstall + , PrintHelp ] ||| Name to use at the command-line for running a pack command @@ -164,8 +164,8 @@ name Query = "query" name Fuzzy = "fuzzy" name Completion = "completion" name CompletionScript = "completion-script" -name PrintHelp = "help" name Uninstall = "uninstall" +name PrintHelp = "help" ||| List pairing a command with its name used for parsing commands. public export @@ -392,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 @@ -404,12 +409,6 @@ cmdDesc PrintHelp = """ \{unlines $ map (indent 2 . fst) namesAndCommands} """ -cmdDesc Uninstall = """ - Uninstalls pack. - - Deletes the $PACK_DIR directory. -""" - export Arg Cmd where argDesc_ = "" @@ -449,5 +448,5 @@ cmdInCommands Query = %search cmdInCommands Fuzzy = %search cmdInCommands Completion = %search cmdInCommands CompletionScript = %search -cmdInCommands PrintHelp = %search cmdInCommands Uninstall = %search +cmdInCommands PrintHelp = %search diff --git a/src/Pack/Runner.idr b/src/Pack/Runner.idr index bae939f..93eb2cd 100644 --- a/src/Pack/Runner.idr +++ b/src/Pack/Runner.idr @@ -53,8 +53,8 @@ Command Cmd where defaultLevel Fuzzy = Cache defaultLevel Completion = Silence defaultLevel CompletionScript = Silence - defaultLevel PrintHelp = Silence defaultLevel Uninstall = Info + defaultLevel PrintHelp = Silence desc = cmdDesc @@ -86,8 +86,8 @@ Command Cmd where ArgTypes Fuzzy = [FuzzyQuery] ArgTypes Completion = [String, String] ArgTypes CompletionScript = [String] - ArgTypes PrintHelp = [Maybe Cmd] ArgTypes Uninstall = [] + ArgTypes PrintHelp = [Maybe Cmd] readCommand_ n = lookup n namesAndCommands @@ -130,8 +130,8 @@ Command Cmd where readArgs Fuzzy = %search readArgs Completion = %search readArgs CompletionScript = %search - readArgs PrintHelp = %search readArgs Uninstall = %search + readArgs PrintHelp = %search isFetch : Cmd -> Bool isFetch Fetch = True diff --git a/src/Pack/Runner/Uninstall.idr b/src/Pack/Runner/Uninstall.idr index a38779a..e961d65 100644 --- a/src/Pack/Runner/Uninstall.idr +++ b/src/Pack/Runner/Uninstall.idr @@ -1,7 +1,11 @@ module Pack.Runner.Uninstall -import Pack.Config -import Pack.Core +import Pack.Config.Types +import Pack.Core.IO +import Pack.Core.Logging +import Pack.Core.Types + +%hide Pack.Config.Types.Env.packDir %default total @@ -16,4 +20,7 @@ uninstallPack : -> EitherT PackErr io () uninstallPack = do info "Uninstalling pack" + let msg := "$PACK_DIR: \{packDir}. Continue (yes/*no)?" + "yes" <- prompt Info msg + | _ => throwE SafetyAbort rmDir packDir From 30c5cd8ab52a5885342e093179279491ae1a44da Mon Sep 17 00:00:00 2001 From: Matthew-Mosior Date: Sun, 4 Aug 2024 21:26:18 -0400 Subject: [PATCH 4/7] Updating install.bash with new instructions handling when there is already an existing pack installation. --- install.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 1b99a87fb55a97b8ede6fbfb1a6e2d6d820e756d Mon Sep 17 00:00:00 2001 From: Matthew-Mosior Date: Tue, 6 Aug 2024 08:35:49 -0400 Subject: [PATCH 5/7] Addressing comments for simplifying type signature of the uninstallPack function, and the way it is called. --- src/Pack/Runner.idr | 4 +--- src/Pack/Runner/Uninstall.idr | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Pack/Runner.idr b/src/Pack/Runner.idr index 93eb2cd..5c2b808 100644 --- a/src/Pack/Runner.idr +++ b/src/Pack/Runner.idr @@ -183,6 +183,4 @@ runCmd = do env <- idrisEnv mc fetch install [] writeCollection - (Uninstall ** []) => do - env <- idrisEnv mc fetch - uninstallPack + (Uninstall ** []) => uninstallPack @{%search} @{metaConfigToLogRef @{mc}} diff --git a/src/Pack/Runner/Uninstall.idr b/src/Pack/Runner/Uninstall.idr index e961d65..8dc4927 100644 --- a/src/Pack/Runner/Uninstall.idr +++ b/src/Pack/Runner/Uninstall.idr @@ -16,7 +16,8 @@ import Pack.Core.Types export covering uninstallPack : {auto _ : HasIO io} - -> {auto _ : Env} + -> {auto _ : LogRef} + -> {auto _ : PackDir} -> EitherT PackErr io () uninstallPack = do info "Uninstalling pack" From 0484958605bcb12c634a8964fbb81ddc716c8a17 Mon Sep 17 00:00:00 2001 From: Matthew-Mosior Date: Tue, 6 Aug 2024 10:55:21 -0400 Subject: [PATCH 6/7] Adding more descriptive message when calling pack uninstall. --- src/Pack/Runner/Uninstall.idr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pack/Runner/Uninstall.idr b/src/Pack/Runner/Uninstall.idr index 8dc4927..3264667 100644 --- a/src/Pack/Runner/Uninstall.idr +++ b/src/Pack/Runner/Uninstall.idr @@ -21,7 +21,7 @@ uninstallPack : -> EitherT PackErr io () uninstallPack = do info "Uninstalling pack" - let msg := "$PACK_DIR: \{packDir}. Continue (yes/*no)?" + let msg := "This command will delete the $PACK_DIR directory at \{packDir}. Continue (yes/*no)?" "yes" <- prompt Info msg | _ => throwE SafetyAbort rmDir packDir From 5840ee5a75b7b549ccbc2005908ab27a6b86dc96 Mon Sep 17 00:00:00 2001 From: Denis Buzdalov Date: Tue, 13 Aug 2024 14:19:26 +0300 Subject: [PATCH 7/7] [ refactor ] Swap auto arguments to reduce to call's code --- src/Pack/Runner.idr | 2 +- src/Pack/Runner/Uninstall.idr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Pack/Runner.idr b/src/Pack/Runner.idr index 5c2b808..05637f5 100644 --- a/src/Pack/Runner.idr +++ b/src/Pack/Runner.idr @@ -183,4 +183,4 @@ runCmd = do env <- idrisEnv mc fetch install [] writeCollection - (Uninstall ** []) => uninstallPack @{%search} @{metaConfigToLogRef @{mc}} + (Uninstall ** []) => uninstallPack @{metaConfigToLogRef @{mc}} diff --git a/src/Pack/Runner/Uninstall.idr b/src/Pack/Runner/Uninstall.idr index 3264667..3e6540c 100644 --- a/src/Pack/Runner/Uninstall.idr +++ b/src/Pack/Runner/Uninstall.idr @@ -15,9 +15,9 @@ import Pack.Core.Types export covering uninstallPack : - {auto _ : HasIO io} - -> {auto _ : LogRef} + {auto _ : LogRef} -> {auto _ : PackDir} + -> {auto _ : HasIO io} -> EitherT PackErr io () uninstallPack = do info "Uninstalling pack"