spreadsheet-0.1.3.6: example/Option.hs
module Option where
import qualified Options.Applicative as OP
import Data.Monoid ((<>))
delimiter :: OP.Parser Char
delimiter =
OP.option (character "delimiter") $
OP.short 'd' <>
OP.long "delimiter" <>
OP.metavar "CHAR" <>
OP.value ',' <>
OP.help "Field delimiter character"
quotation :: OP.Parser Char
quotation =
OP.option (character "quotation") $
OP.short 'q' <>
OP.long "quotation" <>
OP.metavar "CHAR" <>
OP.value '"' <>
OP.help "Quotation mark character"
character :: String -> OP.ReadM Char
character name =
OP.eitherReader $ \str ->
case str of
[c] -> Right c
"\\t" -> Right '\t'
_ -> Left $
name ++ " must be one character, which " ++ show str ++ " is not"