module CmdLine where import Data.Monoid import Options.Applicative import Network.Wai.Handler.Warp (Port) data CmdLine = CmdLine { mode :: Mode } data Mode = UserMode UserOpts | DeveloperMode DeveloperOpts | GraphvizMode GraphvizOpts | ReplayMode ReplayOpts | ServerMode ServerOpts data UserOpts = UserOpts { } data DeveloperOpts = DeveloperOpts { debugUrl :: String } data GraphvizOpts = GraphvizOpts { graphvizLogFile :: FilePath , graphvizShowHashes :: Bool } data ReplayOpts = ReplayOpts { replayLogFile :: FilePath } data ServerOpts = ServerOpts { serverDirectory :: FilePath , serverPort :: Port } parseCmdLine :: Parser CmdLine parseCmdLine = CmdLine <$> parseMode parseMode :: Parser Mode parseMode = (GraphvizMode <$> parsegraphviz) <|> (ReplayMode <$> parsereplay) <|> (ServerMode <$> parseserver) <|> (DeveloperMode <$> parsedeveloper) <|> pure (UserMode (UserOpts {})) -- default, so last where parsegraphviz = GraphvizOpts <$> option str ( long "graphviz" <> metavar "logfile" <> help "visualize log file with graphviz" ) <*> switch ( long "show-hashes" <> help "display hashes in graphviz" ) parsereplay = ReplayOpts <$> option str ( long "replay" <> metavar "logfile" <> help "replay log file" ) parseserver = ServerOpts <$> option str ( long "server" <> metavar "logdir" <> help "run server, storing logs in the specified directory" ) <*> option auto ( long "port" <> metavar "N" <> value 8081 <> showDefault <> help "port for server to listen on" ) parsedeveloper = DeveloperOpts <$> option str ( long "debug" <> metavar "url" <> help "debug a user on the given url" ) getCmdLine :: IO CmdLine getCmdLine = execParser opts where opts = info (helper <*> parseCmdLine) ( fullDesc <> header "debug-me - provable remote debugging sessions" )