@@ -14,40 +14,66 @@ import System.IO
14
14
import qualified System.Log.Logger as L
15
15
import Data.Foldable
16
16
17
+ data ProjectLoadingOpts = ProjectLoadingOpts
18
+ { optDryRun :: Bool
19
+ , optFiles :: [FilePath ]
20
+ } deriving (Show , Eq )
21
+
22
+ data RunMode = LspMode | ProjectLoadingMode ProjectLoadingOpts
23
+ deriving (Show , Eq )
24
+
17
25
data GlobalOpts = GlobalOpts
18
26
{ optDebugOn :: Bool
19
27
, optLogFile :: Maybe String
20
- , optLsp :: Bool
21
28
, projectRoot :: Maybe String
22
29
, optBiosVerbose :: Bool
23
30
, optCaptureFile :: Maybe FilePath
24
31
, optExamplePlugin :: Bool
25
- , optDryRun :: Bool
26
- , optFiles :: [FilePath ]
27
- } deriving (Show )
32
+ , optMode :: RunMode
33
+ } deriving (Show , Eq )
28
34
29
35
-- | Introduced as the common prefix of app/HieWrapper.hs/main and app/MainHie.hs/main
30
36
initApp :: String -> IO GlobalOpts
31
37
initApp namedesc = do
32
38
hSetBuffering stderr LineBuffering
33
- let numericVersion :: Parser (a -> a )
34
- numericVersion = infoOption (showVersion Meta. version)
35
- (long " numeric-version" <> help " Show only version number" )
36
- compiler :: Parser (a -> a )
37
- compiler = infoOption hieGhcDisplayVersion
38
- (long " compiler" <> help " Show only compiler and version supported" )
39
39
-- Parse the options and run
40
40
(opts, () ) <- simpleOptions
41
41
hieVersion
42
42
namedesc
43
43
" "
44
- (numericVersion <*> compiler <*> globalOptsParser)
44
+ optionParser
45
45
empty
46
46
Core. setupLogger (optLogFile opts) [" hie" , " hie-bios" ]
47
47
$ if optDebugOn opts then L. DEBUG else L. INFO
48
48
traverse_ setCurrentDirectory $ projectRoot opts
49
49
return opts
50
50
51
+ optionParser :: Parser GlobalOpts
52
+ optionParser = numericVersion <*> compiler <*> globalOptsParser
53
+
54
+ numericVersion :: Parser (a -> a )
55
+ numericVersion = infoOption (showVersion Meta. version)
56
+ (long " numeric-version" <> help " Show only version number" )
57
+
58
+ compiler :: Parser (a -> a )
59
+ compiler = infoOption hieGhcDisplayVersion
60
+ (long " compiler" <> help " Show only compiler and version supported" )
61
+
62
+ projectLoadingModeParser :: Parser RunMode
63
+ projectLoadingModeParser =
64
+ ProjectLoadingMode
65
+ <$> (ProjectLoadingOpts
66
+ <$> flag False True
67
+ ( long " dry-run"
68
+ <> help " Perform a dry-run of loading files. Only searches for Haskell source files to load. Does nothing if run as LSP server."
69
+ )
70
+ <*> many
71
+ ( argument str
72
+ ( metavar " FILES..."
73
+ <> help " Directories and Filepaths to load. Does nothing if run as LSP server." )
74
+ )
75
+ )
76
+
51
77
globalOptsParser :: Parser GlobalOpts
52
78
globalOptsParser = GlobalOpts
53
79
<$> switch
@@ -61,9 +87,6 @@ globalOptsParser = GlobalOpts
61
87
<> metavar " LOGFILE"
62
88
<> help " File to log to, defaults to stdout"
63
89
))
64
- <*> flag False True
65
- ( long " lsp"
66
- <> help " Start HIE as an LSP server. Otherwise it dumps debug info to stdout" )
67
90
<*> optional (strOption
68
91
( long " project-root"
69
92
<> short ' r'
@@ -88,13 +111,9 @@ globalOptsParser = GlobalOpts
88
111
<*> switch
89
112
( long " example"
90
113
<> help " Enable Example2 plugin. Useful for developers only" )
91
- <*> flag False True
92
- ( long " dry-run"
93
- <> help " Perform a dry-run of loading files. Only searches for Haskell source files to load. Does nothing if run as LSP server."
94
- )
95
- <*> many
96
- ( argument str
97
- ( metavar " FILES..."
98
- <> help " Directories and Filepaths to load. Does nothing if run as LSP server." )
99
- )
100
-
114
+ <*> (flag' LspMode
115
+ ( long " lsp"
116
+ <> help " Start HIE as an LSP server. Otherwise it dumps debug info to stdout" )
117
+ <|>
118
+ projectLoadingModeParser
119
+ )
0 commit comments