svgsym-0.1.0.0: src-exe/Svgsym/Options.hs
module Svgsym.Options (Options (..), parser) where
import Data.List (intercalate, intersperse)
import Data.Version (showVersion)
import Options.Applicative
import Options.Applicative.Types (readerAsk)
import Paths_svgsym (version)
import System.FilePattern (FilePattern)
data Options = Options
{ svgFile :: FilePath,
contentPats :: [FilePattern],
symbolPat :: String,
prettyPrint :: Bool,
debug :: Bool
}
deriving (Show)
parser :: ParserInfo Options
parser =
info (opts <**> helper <**> versioner) $
fullDesc
<> progDesc "A tool to prune unused symbols from icon SVG files."
versionMsg :: String
versionMsg =
intercalate
"\n"
[ "svgsym " <> showVersion version,
"Copyright (C) 2022 Robert Helgesson",
"License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.",
"This is free software: you are free to change and redistribute it.",
"There is NO WARRANTY, to the extent permitted by law."
]
versioner :: Parser (a -> a)
versioner =
option versionReader $
mconcat
[ value id,
metavar "",
noArgError (InfoMsg versionMsg),
long "version",
help "print version information and exit",
hidden
]
where
versionReader = do
potentialCommand <- readerAsk
readerAbort $
InfoMsg versionMsg
opts :: Parser Options
opts =
Options
<$> strArgument
( metavar "FILE"
<> help "SVG file to prune"
)
<*> some
( strOption
( long "content"
<> short 'c'
<> help "add glob pattern of files to include in search"
<> metavar "GLOB"
)
)
<*> strOption
( long "symbol"
<> short 's'
<> help "regular expression that extracts symbol name"
<> metavar "REGEX"
)
<*> switch
( long "pretty"
<> help "pretty print the output SVG file"
)
<*> switch
( long "debug"
<> help "enable debug output"
<> internal
)