This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.hs
74 lines (67 loc) · 1.87 KB
/
Main.hs
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
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Data.Version (showVersion)
import Development.GitRev (gitHash)
import Options.Applicative
import Paths_unison_code_explorer (version)
import qualified UCE
import UCE.Prelude
data Config = Config
{ configPort :: Int,
configDirectory :: String,
configJson :: Bool
}
deriving (Show)
main :: IO ()
main = do
conf <- runParser
if configJson conf
then UCE.dumpJson (configDirectory conf)
else do
logLine ("Starting on port " <> show (configPort conf))
UCE.run (configPort conf) (configDirectory conf)
where
runParser :: IO Config
runParser =
customExecParser (prefs showHelpOnError) parserInfo
parserInfo :: ParserInfo Config
parserInfo =
info
(helper <*> versionOption <*> parser)
( fullDesc
<> progDesc "Web UI for viewing a Unison codebase"
)
versionOption :: Parser (a -> a)
versionOption =
infoOption
(showVersion version <> " " <> $(gitHash))
( long "version"
<> help "Show version"
)
-- Make sure you include the `help` section or that flag won't show up
-- under "Available options".
parser :: Parser Config
parser = do
configPort <-
option
auto
( long "port"
<> help "Port to run server on"
<> value 8080
<> showDefault
)
configDirectory <-
strOption
( long "directory"
<> help "Project directory to explore"
<> value "."
<> showDefault
)
configJson <-
switch
( long "json"
<> help "Output a JSON dump of the project instead of running a server"
<> showDefault
)
pure Config {configPort, configDirectory, configJson}