Skip to content

Commit 8bf5fbc

Browse files
committed
Main: refactor
1 parent 0b26e1c commit 8bf5fbc

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

main/Main.hs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Nix.Utils
3838
import Nix.Var
3939
import Nix.Value.Monad
4040
import Options.Applicative hiding ( ParserResult(..) )
41-
import Prettyprinter
41+
import Prettyprinter hiding (list)
4242
import Prettyprinter.Render.Text
4343
import qualified Repl
4444
import System.FilePath
@@ -50,23 +50,35 @@ main = do
5050
time <- getCurrentTime
5151
opts <- execParser (nixOptionsInfo time)
5252
runWithBasicEffectsIO opts $
53-
case readFrom opts of
54-
Nothing -> case expression opts of
55-
Nothing -> case fromFile opts of
56-
Nothing -> case filePaths opts of
57-
[] -> withNixContext mempty Repl.main
58-
["-"] ->
59-
handleResult opts mempty
60-
. parseNixTextLoc
61-
=<< liftIO Text.getContents
62-
paths -> traverse_ (processFile opts) paths
63-
Just "-" -> traverse_ (processFile opts) . lines =<< liftIO getContents
64-
Just path ->
65-
traverse_ (processFile opts) . lines =<< liftIO (readFile path)
66-
Just s -> handleResult opts mempty (parseNixTextLoc s)
67-
Just path -> do
68-
let file = addExtension (dropExtension path) "nixc"
69-
process opts (pure file) =<< liftIO (readCache path)
53+
maybe
54+
(maybe
55+
(maybe
56+
(list
57+
(withNixContext mempty Repl.main)
58+
(\case
59+
["-"] ->
60+
handleResult opts mempty
61+
. parseNixTextLoc
62+
=<< liftIO Text.getContents
63+
_paths -> traverse_ (processFile opts) _paths
64+
)
65+
(filePaths opts)
66+
)
67+
(\case
68+
"-" -> traverse_ (processFile opts) . lines =<< liftIO getContents
69+
_path -> traverse_ (processFile opts) . lines =<< liftIO (readFile _path)
70+
)
71+
(fromFile opts)
72+
)
73+
(handleResult opts mempty . parseNixTextLoc)
74+
(expression opts)
75+
)
76+
(\ path ->
77+
do
78+
let file = addExtension (dropExtension path) "nixc"
79+
process opts (pure file) =<< liftIO (readCache path)
80+
)
81+
(readFrom opts)
7082
where
7183
processFile opts path = do
7284
eres <- parseNixFileLoc path

0 commit comments

Comments
 (0)