summaryrefslogtreecommitdiffhomepage
path: root/CmdLine.hs
blob: 2c713278f7fd52441dd70c6a464156167590e264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module CmdLine where

import Data.Monoid
import Options.Applicative
import Network.Wai.Handler.Warp (Port)

data CmdLine = CmdLine
	{ mode :: Mode
	}

data Mode
	= Test 
	| Graphviz GraphvizOpts
	| Replay ReplayOpts
	| Server ServerOpts

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 = (Graphviz <$> parsegraphviz)
	<|> (Replay <$> parsereplay)
	<|> (Server <$> parseserver)
	<|> pure Test -- 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 8080
			<> showDefault
			<> help "port for server to listen on"
			)

getCmdLine :: IO CmdLine
getCmdLine = execParser opts
  where
	opts = info (helper <*> parseCmdLine)
		( fullDesc
		<> header "debug-me - provable remote debugging sessions"
		)