A cli database for some FFX stuff
module Options.Parsers
    ( printableText
    , singleChar
    ) where

import           Options.Applicative

import           Data.Attoparsec.Text (anyChar, endOfInput, parseOnly)
import qualified Data.Attoparsec.Text as Atto
import           Data.Bifunctor       (bimap, first)
import           Data.Either.Extra    (maybeToEither)
import qualified Data.Text            as Text

import           Control.Monad

import           Data.PrintableText   (PrintableText)
import qualified Data.PrintableText   as PrintableText

singleChar :: ReadM Char
singleChar = eitherReader $
    first parseError . (parseOnly oneChar . Text.pack)
    where
        parseError = const "Expecting a single character"
        oneChar = anyChar <* endOfInput

printableText :: ReadM PrintableText
printableText = eitherReader $
    input >=> location
    where
        input = Right
        location = maybeToEither "Location can't contain only whitespace" . PrintableText.fromText . Text.pack