rename readMaybe to readish
a stricter (but also partial) readMaybe is getting added to base
This commit is contained in:
parent
5e172b43c4
commit
ba6088b249
9 changed files with 13 additions and 13 deletions
|
@ -101,7 +101,7 @@ hostport2socket host (Just port) = host ++ "!" ++ show port
|
||||||
socket2hostport :: FilePath -> (String, Maybe Integer)
|
socket2hostport :: FilePath -> (String, Maybe Integer)
|
||||||
socket2hostport socket
|
socket2hostport socket
|
||||||
| null p = (h, Nothing)
|
| null p = (h, Nothing)
|
||||||
| otherwise = (h, readMaybe p)
|
| otherwise = (h, readish p)
|
||||||
where
|
where
|
||||||
(h, p) = separate (== '!') $ takeFileName socket
|
(h, p) = separate (== '!') $ takeFileName socket
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ remoteConfig r key = "remote." ++ fromMaybe "" (Git.remoteName r) ++ ".annex-" +
|
||||||
remoteCost :: Git.Repo -> Int -> Annex Int
|
remoteCost :: Git.Repo -> Int -> Annex Int
|
||||||
remoteCost r def = do
|
remoteCost r def = do
|
||||||
cmd <- getConfig r "cost-command" ""
|
cmd <- getConfig r "cost-command" ""
|
||||||
(fromMaybe def . readMaybe) <$>
|
(fromMaybe def . readish) <$>
|
||||||
if not $ null cmd
|
if not $ null cmd
|
||||||
then liftIO $ snd <$> pipeFrom "sh" ["-c", cmd]
|
then liftIO $ snd <$> pipeFrom "sh" ["-c", cmd]
|
||||||
else getConfig r "cost" ""
|
else getConfig r "cost" ""
|
||||||
|
@ -78,7 +78,7 @@ getNumCopies v = perhaps (use v) =<< Annex.getState Annex.forcenumcopies
|
||||||
where
|
where
|
||||||
use (Just n) = return n
|
use (Just n) = return n
|
||||||
use Nothing = perhaps (return 1) =<<
|
use Nothing = perhaps (return 1) =<<
|
||||||
readMaybe <$> fromRepo (Git.Config.get config "1")
|
readish <$> fromRepo (Git.Config.get config "1")
|
||||||
perhaps fallback = maybe fallback (return . id)
|
perhaps fallback = maybe fallback (return . id)
|
||||||
config = "annex.numcopies"
|
config = "annex.numcopies"
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ port :: Repo -> Maybe Integer
|
||||||
port r =
|
port r =
|
||||||
case authpart uriPort r of
|
case authpart uriPort r of
|
||||||
":" -> Nothing
|
":" -> Nothing
|
||||||
(':':p) -> readMaybe p
|
(':':p) -> readish p
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
{- Hostname of an URL repo, including any username (ie, "user@host") -}
|
{- Hostname of an URL repo, including any username (ie, "user@host") -}
|
||||||
|
|
|
@ -119,7 +119,7 @@ options = Option.common ++
|
||||||
"skip files not using a key-value backend"
|
"skip files not using a key-value backend"
|
||||||
] ++ Option.matcher
|
] ++ Option.matcher
|
||||||
where
|
where
|
||||||
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readMaybe v }
|
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readish v }
|
||||||
setgitconfig :: String -> Annex ()
|
setgitconfig :: String -> Annex ()
|
||||||
setgitconfig v = do
|
setgitconfig v = do
|
||||||
newg <- inRepo $ Git.Config.store v
|
newg <- inRepo $ Git.Config.store v
|
||||||
|
|
2
Limit.hs
2
Limit.hs
|
@ -84,7 +84,7 @@ addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
|
||||||
- of copies. -}
|
- of copies. -}
|
||||||
addCopies :: String -> Annex ()
|
addCopies :: String -> Annex ()
|
||||||
addCopies num =
|
addCopies num =
|
||||||
case readMaybe num :: Maybe Int of
|
case readish num :: Maybe Int of
|
||||||
Nothing -> error "bad number for --copies"
|
Nothing -> error "bad number for --copies"
|
||||||
Just n -> addLimit $ check n
|
Just n -> addLimit $ check n
|
||||||
where
|
where
|
||||||
|
|
2
Seek.hs
2
Seek.hs
|
@ -36,7 +36,7 @@ withAttrFilesInGit attr a params = do
|
||||||
withNumCopies :: (Maybe Int -> FilePath -> CommandStart) -> CommandSeek
|
withNumCopies :: (Maybe Int -> FilePath -> CommandStart) -> CommandSeek
|
||||||
withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params
|
withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params
|
||||||
where
|
where
|
||||||
go (file, v) = a (readMaybe v) file
|
go (file, v) = a (readish v) file
|
||||||
|
|
||||||
withBackendFilesInGit :: (BackendFile -> CommandStart) -> CommandSeek
|
withBackendFilesInGit :: (BackendFile -> CommandStart) -> CommandSeek
|
||||||
withBackendFilesInGit a params =
|
withBackendFilesInGit a params =
|
||||||
|
|
|
@ -69,8 +69,8 @@ readKey s = if key == Just stubKey then Nothing else key
|
||||||
findfields _ v = v
|
findfields _ v = v
|
||||||
|
|
||||||
addbackend k v = Just k { keyBackendName = v }
|
addbackend k v = Just k { keyBackendName = v }
|
||||||
addfield 's' k v = Just k { keySize = readMaybe v }
|
addfield 's' k v = Just k { keySize = readish v }
|
||||||
addfield 'm' k v = Just k { keyMtime = readMaybe v }
|
addfield 'm' k v = Just k { keyMtime = readish v }
|
||||||
addfield _ _ _ = Nothing
|
addfield _ _ _ = Nothing
|
||||||
|
|
||||||
prop_idempotent_key_read_show :: Key -> Bool
|
prop_idempotent_key_read_show :: Key -> Bool
|
||||||
|
|
|
@ -88,7 +88,7 @@ gen = filter (not . empty) . fuse [] . scan [] . decode_c
|
||||||
| c == '}' = foundvar f var (readjustify $ reverse p) cs
|
| c == '}' = foundvar f var (readjustify $ reverse p) cs
|
||||||
| otherwise = inpad (c:p) f var cs
|
| otherwise = inpad (c:p) f var cs
|
||||||
inpad p f var [] = Const (novar $ p++";"++var) : f
|
inpad p f var [] = Const (novar $ p++";"++var) : f
|
||||||
readjustify = getjustify . fromMaybe 0 . readMaybe
|
readjustify = getjustify . fromMaybe 0 . readish
|
||||||
getjustify i
|
getjustify i
|
||||||
| i == 0 = UnJustified
|
| i == 0 = UnJustified
|
||||||
| i < 0 = LeftJustified (-1 * i)
|
| i < 0 = LeftJustified (-1 * i)
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Utility.PartialPrelude where
|
||||||
import qualified Data.Maybe
|
import qualified Data.Maybe
|
||||||
|
|
||||||
{- read should be avoided, as it throws an error
|
{- read should be avoided, as it throws an error
|
||||||
- Instead, use: readMaybe -}
|
- Instead, use: readish -}
|
||||||
read :: Read a => String -> a
|
read :: Read a => String -> a
|
||||||
read = Prelude.read
|
read = Prelude.read
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ last = Prelude.last
|
||||||
- readMaybe is available in Text.Read in new versions of GHC,
|
- readMaybe is available in Text.Read in new versions of GHC,
|
||||||
- but that one requires the entire string to be consumed.
|
- but that one requires the entire string to be consumed.
|
||||||
-}
|
-}
|
||||||
readMaybe :: Read a => String -> Maybe a
|
readish :: Read a => String -> Maybe a
|
||||||
readMaybe s = case reads s of
|
readish s = case reads s of
|
||||||
((x,_):_) -> Just x
|
((x,_):_) -> Just x
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue