not evaluating in hnix executable, only parsing
This commit is contained in:
parent
04f210c47e
commit
b4c66b4876
|
@ -59,7 +59,7 @@ Library
|
|||
|
||||
Executable hnix
|
||||
Default-language: Haskell2010
|
||||
Main-is: Nix.hs
|
||||
Main-is: Main.hs
|
||||
Hs-source-dirs: main
|
||||
Default-extensions:
|
||||
DataKinds
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
{-# LANGUAGE LambdaCase #-}
|
||||
module Main where
|
||||
|
||||
import Nix.Parser
|
||||
import Nix.Pretty
|
||||
|
||||
import System.Environment
|
||||
import System.IO
|
||||
import Text.PrettyPrint.ANSI.Leijen
|
||||
|
||||
nix :: FilePath -> IO ()
|
||||
nix path = do
|
||||
res <- parseNixFile path
|
||||
case res of
|
||||
Failure e -> hPutStrLn stderr $ "Parse failed: " ++ show e
|
||||
Success n -> do
|
||||
displayIO stdout $ renderPretty 0.4 80 (prettyNix n)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let usageStr = "Parses a nix file and prints to stdout.\n\
|
||||
\\n\
|
||||
\Usage:\n\
|
||||
\ hnix --help\n\
|
||||
\ hnix <path>\n"
|
||||
let argErr msg = error $ "Invalid arguments: " ++ msg ++ "\n" ++ usageStr
|
||||
getArgs >>= \case
|
||||
"--help":_ -> putStrLn usageStr
|
||||
('-':_):_ -> argErr "Provide a path to a nix file."
|
||||
path:_ -> nix path
|
||||
_ -> argErr "Provide a path to a nix file."
|
28
main/Nix.hs
28
main/Nix.hs
|
@ -1,28 +0,0 @@
|
|||
module Main where
|
||||
|
||||
import Nix.Parser
|
||||
import Nix.Pretty
|
||||
import Nix.Eval
|
||||
import Nix.Types
|
||||
|
||||
import Data.Fix
|
||||
import System.Environment
|
||||
import System.IO
|
||||
import Text.PrettyPrint.ANSI.Leijen
|
||||
|
||||
import qualified Data.Map as Map
|
||||
|
||||
nix :: FilePath -> IO ()
|
||||
nix path = do
|
||||
res <- parseNixFile path
|
||||
case res of
|
||||
Failure e -> hPutStrLn stderr $ "Parse failed: " ++ show e
|
||||
Success n -> do
|
||||
displayIO stdout $ renderPretty 0.4 80 (prettyNix n)
|
||||
putStrLn ""
|
||||
evalExpr n (Fix $ NVSet Map.empty) >>= print
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
[path] <- getArgs
|
||||
nix path
|
Loading…
Reference in New Issue