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) -- | Isomorphic to `Maybe` but with distinct meaning. data Result a = Output a | NoOutput main :: IO () main = exit =<< fmap toOutput . checkAll =<< getPath where getPath = sanitisePath . fromMaybe defaultPath . path <$> parse toOutput = outputTools . M.toList exit NoOutput = exitFailure exit (Output x) = putTextLn x -- | Fixes inputs without a trailing slash, doesn't break those with one. sanitisePath :: Text -> Text sanitisePath = (<> "/") outputTools :: [(Tool, Scripts)] -> Result Text outputTools  = NoOutput outputTools xs = Output . 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 ", "