~samhh/unerf

ref: 0.1.0 unerf/exec/Main.hs -rw-r--r-- 981 bytes
20359087 — Sam A. Horvath-Hunt 0.1.0 8 months ago
                                                                                
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
module Main (main) where

import           CLI              (Opts (..), parse)
import qualified Data.Text        as T
import           Prelude
import           Unerf            (checkAll, defaultPath)
import           Unerf.Tool       (ToolResult (..))

main :: IO ()
main = putTextLn =<< fmap renderToolResults . checkAll . sanitisePath . fromMaybe defaultPath . path =<< parse

-- Fixes inputs without a trailing slash, doesn't break those with one.
sanitisePath :: Text -> Text
sanitisePath = (<> "/")

renderToolResults :: [ToolResult] -> Text
renderToolResults [] = "Nothing found."
renderToolResults xs = T.intercalate "\n" $ renderToolResult <$> xs

renderToolResult :: ToolResult -> Text
renderToolResult x = show (tool x) <> renderScripts (toolScripts x)
  where renderScripts :: Maybe (NonEmpty Text) -> Text
        renderScripts Nothing   = ""
        renderScripts (Just xs) = let ns = T.intercalate ", " . toList $ xs
                                   in ": " <> ns