fountainhead/app/Main.hs

54 lines
1.4 KiB
Haskell
Raw Normal View History

2023-03-14 09:52:02 +01:00
module Main
( main
) where
2023-11-10 16:45:45 +01:00
import qualified Data.Text.Lazy.Builder as Text.Builder
import qualified Data.Text.Lazy.IO as Text.Lazy
2024-02-03 11:58:47 +01:00
import Graphics.Fountainhead (dumpFontFile)
2023-11-10 11:57:08 +01:00
import System.Exit (exitWith)
import GHC.IO.Exception (ExitCode(..))
2024-02-03 11:58:47 +01:00
import Options.Applicative
( Parser
, ParserInfo(..)
, argument
, command
, execParser
, info
, fullDesc
, metavar
, progDesc
, str
, subparser
)
2023-03-14 09:52:02 +01:00
2024-02-03 11:58:47 +01:00
data Operation
= Dump FilePath
| Afm FilePath
deriving (Eq, Show)
2023-11-10 16:45:45 +01:00
2024-02-03 11:58:47 +01:00
dump :: Parser Operation
dump = Dump
<$> argument str (metavar "FONTFILE")
2023-12-27 16:19:21 +01:00
2024-02-03 11:58:47 +01:00
afm :: Parser Operation
afm = Afm
<$> argument str (metavar "FONTFILE")
operationOptions :: ParserInfo Operation
operationOptions = info commands fullDesc
where
commands = subparser
$ command "dump" (info dump (progDesc "Dumping the contents of a TrueType Font file"))
<> command "afm" (info afm (progDesc "Generating Adobe Font Metrics files for TrueType fonts"))
2023-11-10 16:45:45 +01:00
2023-03-14 09:52:02 +01:00
main :: IO ()
2024-02-03 11:58:47 +01:00
main = execParser operationOptions >>= handleArguments
where
handleArguments (Dump fontFile)
= putStrLn ("Dumping File:" <> fontFile <> "\n\n")
>> dumpFontFile fontFile
>>= either print (Text.Lazy.putStrLn . Text.Builder.toLazyText)
handleArguments (Afm _)
= putStrLn "The program expects exactly one argument, the font file path."
>> exitWith (ExitFailure 2)