Haskellator/app/Main.hs

27 lines
724 B
Haskell
Raw Normal View History

2024-11-17 14:20:29 +00:00
module Main where
import System.Environment (getArgs)
import System.IO
import Control.Exception (catch, IOException)
import Haskellator
2024-11-17 14:20:29 +00:00
main :: IO ()
main = do
-- Get the command-line arguments
args <- getArgs
-- Check if a file name is provided
case args of
(filePath:_) -> do
-- Attempt to read the file
contents <- catch (readFile filePath) handleReadError
putStrLn "File Contents:"
putStrLn contents
[] -> putStrLn "cabal run Haskellator -- <file-path>"
putStrLn $ show Haskellator.val
2024-11-17 14:20:29 +00:00
-- Handle potential file reading errors
handleReadError :: IOException -> IO String
handleReadError _ = return "Error: Could not read the file."