Commit 81c2d4f7 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Move `readMaybe` to Client.Prelude and remove dupes

parent 70e2f902
{-# LANGUAGE CPP #-}
-- | This module does two things:
--
-- * Acts as a compatiblity layer, like @base-compat@.
......@@ -10,7 +12,21 @@
module Distribution.Client.Compat.Prelude
( module Distribution.Compat.Prelude
, Prelude.IO
, readMaybe
) where
import Prelude (IO)
import Distribution.Compat.Prelude hiding (IO)
#if MIN_VERSION_base(4,6,0)
import Text.Read
( readMaybe )
#endif
#if !MIN_VERSION_base(4,6,0)
-- | An implementation of readMaybe, for compatability with older base versions.
readMaybe :: Read a => String -> Maybe a
readMaybe s = case reads s of
[(x,"")] -> Just x
_ -> Nothing
#endif
......@@ -41,7 +41,7 @@ import Distribution.Simple.Utils
, copyFileVerbose, withTempFile
, rawSystemStdInOut, toUTF8, fromUTF8, normaliseLineEndings )
import Distribution.Client.Utils
( readMaybe, withTempFileName )
( withTempFileName )
import Distribution.Client.Types
( RemoteRepo(..) )
import Distribution.System
......
......@@ -603,11 +603,6 @@ promptList' displayItem numChoices choices def other = do
= return . Right $ choices !! (n-1)
| otherwise = Left `fmap` promptStr "Please specify" Nothing
readMaybe :: (Read a) => String -> Maybe a
readMaybe s = case reads s of
[(a,"")] -> Just a
_ -> Nothing
---------------------------------------------------------------------------
-- File generation ------------------------------------------------------
---------------------------------------------------------------------------
......
......@@ -1772,9 +1772,6 @@ initCommand = CommandUI {
, optionVerbosity IT.initVerbosity (\v flags -> flags { IT.initVerbosity = v })
]
}
where readMaybe s = case reads s of
[(x,"")] -> Just x
_ -> Nothing
-- ------------------------------------------------------------
-- * SDist flags
......
......@@ -31,10 +31,6 @@ import qualified Data.ByteString.Lazy as BS
import Data.Bits
( (.|.), shiftL, shiftR )
import System.FilePath
#if MIN_VERSION_base(4,6,0)
import Text.Read
( readMaybe )
#endif
import Data.List
( groupBy )
import Data.Word
......@@ -93,14 +89,6 @@ duplicatesBy cmp = filter moreThanOne . groupBy eq . sortBy cmp
moreThanOne (_:_:_) = True
moreThanOne _ = False
#if !MIN_VERSION_base(4,6,0)
-- | An implementation of readMaybe, for compatability with older base versions.
readMaybe :: Read a => String -> Maybe a
readMaybe s = case reads s of
[(x,"")] -> Just x
_ -> Nothing
#endif
-- | Like 'removeFile', but does not throw an exception when the file does not
-- exist.
removeExistingFile :: FilePath -> IO ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment