packages feed

brok 0.1.5.0 → 0.1.6.0

raw patch · 8 files changed

+78/−27 lines, 8 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Brok.IO.CLI: successMessage :: Text -> IO ()
+ Brok.Types.Config: [onlyFailures] :: Config -> Bool
- Brok.IO.Output: output :: Result -> IO Bool
+ Brok.IO.Output: output :: Bool -> [Result] -> IO Bool
- Brok.Types.Config: Config :: Maybe Integer -> [URL] -> Integer -> [Text] -> Config
+ Brok.Types.Config: Config :: Maybe Integer -> [URL] -> Integer -> [Text] -> Bool -> Config

Files

README.md view
@@ -58,7 +58,7 @@  #### Cache -By default brök will cache successes for a day. It will always recheck errors.+By default brök will cache successes for a day in a `.brokdb` file. It will always recheck errors.  If you want to adjust the cache length, you can enter the number of seconds after which the cache invalidates: @@ -67,6 +67,14 @@ brok --cache 604800 test.md links.tex ``` +If you want to avoid creating the `.brokdb` file or ignore the cache entirely you can use the `--no-cache` option:++```bash+# do not cache results+# and don't use previously generated cache+brok --no-cache test.md links.tex+```+ #### Ignore URLs  You can tell brök to ignore URLs with specified prefixes:@@ -84,6 +92,18 @@ # wait for 1 second between checks brok --interval 1000 test.md links.tex ```++#### Only Show Failures++If you want to see what's going on, but you're not interested in successes, then you can use the `--only-failures` option:++```bash+# see what's going on, but only show failures+brok --only-failures test.md links.tex+```++If you're using brök as part of a script then you should [redirect `stdout`](#basic-usage).+  ### Git Pre-Commit Hook 
brok.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: brok-version: 0.1.5.0+version: 0.1.6.0 license: BSD3 license-file: LICENSE copyright: 2019 Small Hadron Collider
src/Brok.hs view
@@ -18,7 +18,7 @@ import           Brok.IO.Output    (output) import           Brok.Options      (parse) import           Brok.Parser.Links (links)-import qualified Brok.Types.Config as C (Config, cache, files, ignore, interval)+import qualified Brok.Types.Config as C (Config, cache, files, ignore, interval, onlyFailures) import           Brok.Types.Link   (getURL, isSuccess) import           Brok.Types.Next   (Next (..)) import           Brok.Types.Result (cachedLinks, ignoredLinks, justLinks, linkIOMap, parseLinks,@@ -42,11 +42,11 @@     -- display results     putStrLn ""     header "Results"-    anyErrors <- sequence $ output <$> checked+    anyErrors <- output (C.onlyFailures config) checked     -- cache successes     setCached (C.cache config) $ getURL <$> filter isSuccess (concat (justLinks <$> checked))     -- exit with appropriate status code-    if foldl' (||) False anyErrors+    if anyErrors         then void exitFailure         else void exitSuccess 
src/Brok/IO/CLI.hs view
@@ -28,6 +28,12 @@     hPutStrLn stdout $ "*** " ++ msg ++ " ***"     hSetSGR stdout [Reset] +successMessage :: Text -> IO ()+successMessage msg = do+    hSetSGR stdout [SetColor Foreground Dull Green]+    hPutStrLn stdout msg+    hSetSGR stdout [Reset]+ errorMessage :: Text -> IO () errorMessage msg = do     hSetSGR stderr [SetColor Foreground Dull Red]
src/Brok/IO/Output.hs view
@@ -27,29 +27,41 @@ statusError (Link _ Ignored)     = False statusError _                    = True -countErrors :: [Link] -> Int-countErrors statuses = length $ filter statusError statuses- outputPath :: TFilePath -> Text outputPath path = concat ["\n", "[", path, "]"] -output :: Result -> IO Bool-output (Result path NotFound) = do+outputMap :: Bool -> Result -> IO Bool+outputMap _ (Result path NotFound) = do     errorMessage $ outputPath path     errorMessage "  - File not found"     return True-output (Result path (ParseError err)) = do+outputMap _ (Result path (ParseError err)) = do     errorMessage $ outputPath path     errorMessage "  - Parse error:"     errorMessage err     return True-output (Result path (Links links)) = do-    let errs = countErrors links /= 0-    if errs-        then errorMessage $ outputPath path-        else message $ outputPath path-    if not (null links)-        then sequence_ $ linkOutput <$> links-        else putStrLn "- No links found in file"-    return errs-output _ = return False+outputMap onlyFailures (Result path (Links links)) = do+    let errs = filter statusError links+    let anyErrs = not (null errs)+    if anyErrs+        then do+            errorMessage $ outputPath path+            sequence_ $+                linkOutput <$>+                (if onlyFailures+                     then errs+                     else links)+        else unless onlyFailures $ do+                 message $ outputPath path+                 if not (null links)+                     then sequence_ $ linkOutput <$> links+                     else putStrLn "- No links found in file"+    return anyErrs+outputMap _ _ = return False++output :: Bool -> [Result] -> IO Bool+output onlyFailures results = do+    errs <- sequence $ outputMap onlyFailures <$> results+    let anyErrs = foldl' (||) False errs+    when (not anyErrs && onlyFailures) $ successMessage "All links working"+    return anyErrs
src/Brok/Parser/Options.hs view
@@ -19,7 +19,11 @@     | Interval Integer     | Ignore [Text]     | Files [Text]+    | OnlyFailures +onlyFailuresP :: Parser Option+onlyFailuresP = lexeme $ string "--only-failures" $> OnlyFailures+ noCacheP :: Parser Option noCacheP = lexeme $ string "--no-cache" $> Cache Nothing @@ -45,10 +49,11 @@     convert dc (Ignore i)   = dc {ignore = i}     convert dc (Interval i) = dc {interval = i}     convert dc (Files i)    = dc {files = i}+    convert dc OnlyFailures = dc {onlyFailures = True}  arguments :: Parser Config arguments = do-    opts <- many' (noCacheP <|> cacheP <|> intervalP <|> ignoreP)+    opts <- many' (noCacheP <|> cacheP <|> intervalP <|> ignoreP <|> onlyFailuresP)     fls <- many1 fileP     return . optsToConfig $ opts ++ [Files fls] 
src/Brok/Types/Config.hs view
@@ -7,11 +7,13 @@ import Brok.Types.Link (URL)  data Config = Config-    { cache    :: Maybe Integer-    , ignore   :: [URL]-    , interval :: Integer-    , files    :: [Text]+    { cache        :: Maybe Integer+    , ignore       :: [URL]+    , interval     :: Integer+    , files        :: [Text]+    , onlyFailures :: Bool     } deriving (Show, Eq)  defaultConfig :: Config-defaultConfig = Config {cache = Just 84600, ignore = [], interval = 100, files = []}+defaultConfig =+    Config {cache = Just 84600, ignore = [], interval = 100, files = [], onlyFailures = False}
test/OptionsTest.hs view
@@ -34,6 +34,12 @@                    (Right (Continue (defaultConfig {files = ["blah.md", "tests/spoon.md"]})))                    (parse ["blah.md", "tests/spoon.md"]))         , testCase+              "single file with only-failures option"+              (assertEqual+                   "gives back files"+                   (Right (Continue (defaultConfig {onlyFailures = True, files = ["blah.md"]})))+                   (parse ["--only-failures", "blah.md"]))+        , testCase               "single file with no-cache option"               (assertEqual                    "gives back files"