fragr-0.1.0.0: app/App/Options.hs
-- | Command-line interface for the demo executable.
module App.Options
( Command (..)
, parseCommand
) where
import Options.Applicative
import Fragr.Snapshot.Dot qualified as Dot
-- | The mode to run in, selected by subcommand.
data Command
= Dot Dot.Options
| Json
| Execute
deriving stock (Eq, Show)
-- | Parse the process arguments, handling @--help@ and errors.
parseCommand :: IO Command
parseCommand = execParser (info (commandP <**> helper) desc)
where
desc = fullDesc <> progDesc "Build the demo frame graph and dump or execute it."
commandP :: Parser Command
commandP =
hsubparser
( command "dot" (info (Dot <$> dotOptionsP) (progDesc "Dump the graph as Graphviz DOT"))
<> command "json" (info (pure Json) (progDesc "Dump the graph as viewer JSON (SPEC §8.3)"))
<> command "execute" (info (pure Execute) (progDesc "Execute the graph with logging callbacks"))
)
dotOptionsP :: Parser Dot.Options
dotOptionsP = build <$> clusterImportsP <*> stratifyP <*> antiEdgesP
where
build clusterImports stratify antiEdges = Dot.Options{clusterImports, stratify, antiEdges}
clusterImportsP =
switch (long "cluster-imports" <> help "Group the imported resources")
stratifyP =
switch (long "stratify" <> help "Pin one row per dependency level, instead of letting the layout rank the passes")
antiEdgesP =
flag True False (long "no-anti-edges" <> help "Hide the write-after-read edges")