remove :: Options -> VersionTest -> [FilePath] -> IO ()
remove opts rt fps = do
    case sort fps of
        [] -> message opts "** Nothing to remove"
        sfps -> do
            mapM_ (removeDirectoryRecursive opts) sfps
            findOrphanSymlinks fps >>= mapM_ (removeFile opts)
            findEmptyPackages rt >>= mapM_ removePackage
            updateFrameworks opts rt
            removeHints
  where
    removePackage (empty, fp) = do
        if empty
            then removeDirectoryRecursive opts fp
            else message opts
                ("** " ++ fp ++
                 " is not empty, but has no more GHC libs. Consider removing.")

    removeHints = when (optRemove opts == OptDryRun) $
        putStrLn
            "-- To actually remove these files, \
                \sudo run the command again with --remove\n\
            \-- To generate a script to remove these files, \
                \run the command again with --script\n"

-- | Remove all Haskell versions, and the top level directories.
remove :: Options -> VersionTest -> [FilePath] -> IO ()
remove opts rt fps = do
    case sort fps of
        [] -> message opts "** Nothing to remove"
        sfps -> do
            mapM_ (removeDirectoryRecursive opts) sfps
            findOrphanSymlinks fps >>= mapM_ (removeFile opts)
            findEmptyPackages rt >>= mapM_ removePackage
            updateFrameworks opts rt
            removeHints
  where
    removePackage (empty, fp) = do
        if empty
            then removeDirectoryRecursive opts fp
            else message opts
                ("** " ++ fp ++
                 " is not empty, but has no more GHC libs. Consider removing.")

    removeHints = when (optRemove opts == OptDryRun) $
        putStrLn
            "-- To actually remove these files, \
                \sudo run the command again with --remove\n\
            \-- To generate a script to remove these files, \
                \run the command again with --script\n"

-- | Remove all Haskell versions, and the top level directories.
remove opts rt fps = do
    case sort fps of
        [] -> message opts "** Nothing to remove"
        sfps -> do
            mapM_ (removeDirectoryRecursive opts) sfps
            findOrphanSymlinks fps >>= mapM_ (removeFile opts)
            findEmptyPackages rt >>= mapM_ removePackage
            updateFrameworks opts rt
            removeHints
  where
    removePackage (empty, fp) = do
        if empty
            then removeDirectoryRecursive opts fp
            else message opts
                ("** " ++ fp ++
                 " is not empty, but has no more GHC libs. Consider removing.")

    removeHints = when (optRemove opts == OptDryRun) $
        putStrLn
            "-- To actually remove these files, \
                \sudo run the command again with --remove\n\
            \-- To generate a script to remove these files, \
                \run the command again with --script\n"

-- | Remove all Haskell versions, and the top level directories.