summaryrefslogtreecommitdiff
path: root/src/Toml/Checker.hs
blob: f5d3596349c28ebb90d88341ae9033f9ee64595d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators     #-}

module Toml.Checker
    ( exec
    ) where

import qualified Data.Text.IO    as TIO
import           GHC.Generics    (Generic)
import           Options.Generic
import           Text.Megaparsec (parseErrorPretty)
import           Text.Toml       (parseTomlDoc)

newtype Program = Program { file :: FilePath <?> "Path to file to be checked." }
    deriving (Generic)

programModifiers :: Modifiers
programModifiers = defaultModifiers { shortNameModifier = firstLetter }

instance ParseRecord Program where
    parseRecord = parseRecordWithModifiers programModifiers

exec :: IO ()
exec = do
    x <- getRecord "Command-line wrapper around htoml"
    let path = unHelpful $ file x
    contents <- TIO.readFile path
    case parseTomlDoc path contents of
        Right{} -> pure ()
        Left e  -> putStrLn $ parseErrorPretty e