~samhh/unerf

ref: 331aa841fae49d0af630d07ca65007dd6bcbb601 unerf/exec/Main.hs -rw-r--r-- 912 bytes
331aa841 — Sam A. Horvath-Hunt Add build status to README 3 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
26
module Main (main) where

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

main :: IO ()
main = putTextLn =<< fmap (outputTools . M.toList) . checkAll =<< getPath
  where getPath = sanitisePath . fromMaybe defaultPath . path <$> parse

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

outputTools :: [(Tool, Scripts)] -> Text
outputTools [] = "Nothing found."
outputTools xs = T.intercalate "\n" $ uncurry outputTool <$> xs

outputTool :: Tool -> Scripts -> Text
outputTool x ys = show x <> foldMap (outputScripts . toList) ys

outputScripts :: [Text] -> Text
outputScripts = (": " <>) . T.intercalate ", "