summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-02-06 12:14:07 +0100
committerEugen Wissner <belka@caraus.de>2024-02-06 12:14:07 +0100
commit23271d6f6cf033230106f07ae14985f3b85f906a (patch)
tree4299eb1ccae58f52a450bf86497b311e1f31ccad /src
parent3160ceab080fca8fef0cf2cf196b46284d15c19f (diff)
downloadfountainhead-23271d6f6cf033230106f07ae14985f3b85f906a.tar.gz
Add an option for dumping a single table
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/Main.hs b/src/Main.hs
index a87bf85..984f2d7 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE RecordWildCards #-}
module Main
( main
) where
@@ -5,49 +6,49 @@ module Main
import qualified Data.Text.Lazy.Builder as Text.Builder
import qualified Data.Text.Lazy.IO as Text.Lazy
import Graphics.Fountainhead (dumpFontFile)
-import System.Exit (exitWith)
-import GHC.IO.Exception (ExitCode(..))
import Options.Applicative
- ( Parser
- , ParserInfo(..)
+ ( ParserInfo(..)
, (<**>)
, argument
- , command
, execParser
+ , header
+ , help
, helper
, info
+ , long
, fullDesc
, metavar
+ , optional
, progDesc
+ , short
, str
- , subparser
+ , strOption
)
-data Operation
- = Dump
- | Afm
- deriving (Eq, Show)
-
-data Options = Options Operation FilePath
- deriving (Eq, Show)
+data Options = Options
+ { tableName :: Maybe String
+ , fontFile :: FilePath
+ } deriving (Eq, Show)
operationOptions :: ParserInfo Options
-operationOptions = info (options <**> helper) fullDesc
+operationOptions = info (options <**> helper)
+ $ fullDesc
+ <> progDesc "Dumping the contents of a TrueType Font file."
+ <> header "fountainhead - font parser"
where
options = Options
- <$> commands
+ <$> tableNameArgument
<*> argument str (metavar "FONTFILE")
- commands = subparser
- $ command "dump" (info (pure Dump) (progDesc "Dumping the contents of a TrueType Font file."))
- <> command "afm" (info (pure Afm) (progDesc "Generating Adobe Font Metrics files for TrueType fonts."))
+ tableNameArgument = optional $ strOption
+ $ long "table"
+ <> short 't'
+ <> metavar "tablename"
+ <> help "Dump only the specified table. Otherwise dump all tables"
main :: IO ()
main = execParser operationOptions >>= handleArguments
where
- handleArguments (Options Dump fontFile)
+ handleArguments Options{..}
= putStrLn ("Dumping File:" <> fontFile <> "\n\n")
- >> dumpFontFile fontFile
+ >> dumpFontFile fontFile tableName
>>= either print (Text.Lazy.putStrLn . Text.Builder.toLazyText)
- handleArguments (Options Afm _)
- = putStrLn "The program expects exactly one argument, the font file path."
- >> exitWith (ExitFailure 2)