Skip to content

Commit

Permalink
add --yes option for --delete
Browse files Browse the repository at this point in the history
eg on Stackage delete-work maybe requires 1000s of prompts
  • Loading branch information
juhp committed Sep 13, 2023
1 parent a407eb8 commit 3ee83e6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ removeGhcVersionInstallation deletion ghcver msystem = do
if isMajorVersion ghcver
then do
yes <-
if isDelete deletion then
yesNo $ "Delete all stack ghc" +-+ showVersion ghcver +-+ "installations"
else return True
if deletePrompt deletion
then yesNo $ "Delete all stack ghc" +-+ showVersion ghcver +-+ "installations"
else return True
when yes $
mapM_ (doRemoveGhcVersion deletion) gs
else error' "more than one match found!!"
Expand Down
6 changes: 3 additions & 3 deletions src/GHCTarball.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ removeGhcVersionTarball deletion ghcver msystem = do
if isMajorVersion ghcver
then do
yes <-
if isDelete deletion then
yesNo $ "Delete all stack ghc" +-+ showVersion ghcver +-+ "tarballs"
else return True
if deletePrompt deletion
then yesNo $ "Delete all stack ghc" +-+ showVersion ghcver +-+ "tarballs"
else return True
when yes $
mapM_ (doRemoveGhcTarballVersion deletion) gs
else error' "more than one match found!!"
Expand Down
5 changes: 4 additions & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ main = do
flagWith' Tarballs 'T' "tarballs" ("Act on" +-+ stackroot </> "programs/ tarballs") <|>
flagWith Default Global 'G' "global" ("Act on both" +-+ stackroot </> "{programs,snapshots}/ [default outside project dir]")

deleteOpt = flagWith Dryrun Delete 'd' "delete" "Do deletion [default is dryrun]"
deleteOpt =
(flagWith' Delete 'd' "delete" "Do deletion [default is dryrun]" <*>
switchWith 'y' "yes" "Assume yes for all prompts") <|>
pure Dryrun

recursionOpt =
optional (
Expand Down
4 changes: 2 additions & 2 deletions src/Snapshots.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cleanGhcSnapshots deletion cwd ghcver platform = do
unless (null ghcs) $
putStrLn (platform ++ ":")
yes <-
if isMajorVersion ghcver && isDelete deletion
if isMajorVersion ghcver && deletePrompt deletion
then yesNo $ "Delete all" +-+ showVersion ghcver +-+ "builds"
else return True
when yes $
Expand Down Expand Up @@ -181,7 +181,7 @@ printTotalGhcSize versnaps = do
removeStackWork :: Deletion -> IO ()
removeStackWork deletion = do
yes <-
if isDelete deletion
if deletePrompt deletion
then yesNo "Delete .stack-work"
else return True
when yes $
Expand Down
13 changes: 9 additions & 4 deletions src/Types.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module Types (
Deletion (..),
isDelete
isDelete,
deletePrompt
)
where

data Deletion = Dryrun | Delete
deriving Eq
data Deletion = Dryrun | Delete Bool

isDelete :: Deletion -> Bool
isDelete = (== Delete)
isDelete (Delete _) = True
isDelete Dryrun = False

deletePrompt :: Deletion -> Bool
deletePrompt (Delete False) = True
deletePrompt _ = False

0 comments on commit 3ee83e6

Please sign in to comment.