diff --git a/src/System/MemInfo/Choices.hs b/src/System/MemInfo/Choices.hs index c0732db..7cdabf0 100644 --- a/src/System/MemInfo/Choices.hs +++ b/src/System/MemInfo/Choices.hs @@ -26,7 +26,6 @@ import Options.Applicative ( Parser, ParserInfo, ReadM, - auto, eitherReader, execParser, help, @@ -149,7 +148,7 @@ positiveNum = | i > 0 = pure i | otherwise = readerError "Value must be greater than 0" in - auto >>= checkPositive + autoNicerError >>= checkPositive parsePrintOrder :: Parser PrintOrder @@ -197,4 +196,16 @@ data Style autoIgnoreCase :: (Read a) => ReadM a -autoIgnoreCase = eitherReader $ readEither . Text.unpack . Text.toTitle . Text.pack +autoIgnoreCase = + let toTitle' = Text.unpack . Text.toTitle . Text.pack + in eitherReader $ readEither' toTitle' + + +autoNicerError :: (Read a) => ReadM a +autoNicerError = eitherReader $ readEither' id + + +readEither' :: (Read a) => (String -> String) -> String -> Either String a +readEither' f x = case readEither $ f x of + Left _ -> Left $ "value '" ++ x ++ "' is not permitted" + right -> right