Skip to content

Commit fea76d9

Browse files
committed
Main: refactor
1 parent 8bf5fbc commit fea76d9

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

main/Main.hs

Lines changed: 16 additions & 11 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 hiding (list)
41+
import Prettyprinter hiding ( list )
4242
import Prettyprinter.Render.Text
4343
import qualified Repl
4444
import System.FilePath
@@ -49,24 +49,29 @@ main :: IO ()
4949
main = do
5050
time <- getCurrentTime
5151
opts <- execParser (nixOptionsInfo time)
52-
runWithBasicEffectsIO opts $
52+
53+
runWithBasicEffectsIO opts $ execContentsFilesOrRepl opts
54+
55+
where
56+
execContentsFilesOrRepl opts =
5357
maybe
5458
(maybe
5559
(maybe
5660
(list
57-
(withNixContext mempty Repl.main)
61+
(withNixContext mempty Repl.main) -- run REPL
5862
(\case
59-
["-"] ->
60-
handleResult opts mempty
61-
. parseNixTextLoc
62-
=<< liftIO Text.getContents
63+
["-"] -> handleResult opts mempty . parseNixTextLoc =<< liftIO Text.getContents
6364
_paths -> traverse_ (processFile opts) _paths
6465
)
6566
(filePaths opts)
6667
)
67-
(\case
68-
"-" -> traverse_ (processFile opts) . lines =<< liftIO getContents
69-
_path -> traverse_ (processFile opts) . lines =<< liftIO (readFile _path)
68+
(\ x ->
69+
-- use Text as in the base case, requires changing FilePath -> Text
70+
traverse_ (processFile opts) . lines =<< liftIO
71+
(case x of
72+
"-" -> getContents -- get user input
73+
_path -> readFile _path
74+
)
7075
)
7176
(fromFile opts)
7277
)
@@ -79,7 +84,7 @@ main = do
7984
process opts (pure file) =<< liftIO (readCache path)
8085
)
8186
(readFrom opts)
82-
where
87+
8388
processFile opts path = do
8489
eres <- parseNixFileLoc path
8590
handleResult opts (pure path) eres

0 commit comments

Comments
 (0)