Skip to content

Commit

Permalink
Remove code duplication introduced in current PR (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Oct 7, 2023
1 parent 8fcdfc2 commit 620ee0c
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -806,21 +806,13 @@ mainWithOptions Options {..} = do

AddBound ab@AddBoundOptions{ optABFiles } -> do
-- Run add-bound for all given cabal files, skipping to next on error.
results <- forM optABFiles $ \fp -> do
runExceptT (addBound (fp <$ ab)) >>= \case
Left err -> False <$ log err
Right () -> return True
-- If add-bound failed for one cabal file, report failure.
unless (and results) $ exitFailure
sequenceExceptT_ $ map (addBound . (<$ ab)) optABFiles

GetBounds gb@GetBoundsOptions{ optGBFiles } -> do
-- Run get-bounds for all given cabal files, skipping to next on error.
results <- forM optGBFiles $ \fp -> do
runExceptT (getBounds (fp <$ gb)) >>= \case
Left err -> False <$ log err
Right () -> return True
-- If get-bounds failed for one cabal file, report failure.
unless (and results) $ exitFailure
sequenceExceptT_ $ map (getBounds . (<$ gb)) optGBFiles

return ()
where
Expand Down Expand Up @@ -894,16 +886,14 @@ extractRange :: LC.GenericPackageDescription -> C.PackageName -> C.VersionRange
extractRange gpd pkgName =
List.foldl' C.intersectVersionRanges C.anyVersion vss
where
-- TODO: can re-use extractRanges here somehow
vss = gpd ^.. LC.condLibrary . _Just . condTreeDataL . LC.targetBuildDepends . traverse . to ext . _Just
ext (C.Dependency pkgName' vr _)
| pkgName == pkgName' = Just vr
| otherwise = Nothing
vss :: [C.VersionRange]
vss = map snd $ filter ((pkgName ==) . fst) $ extractRanges gpd

extractRanges :: LC.GenericPackageDescription -> [(C.PackageName, C.VersionRange)]
extractRanges =
(^.. LC.condLibrary . _Just . condTreeDataL . LC.targetBuildDepends . traverse . to ext)
where
ext :: C.Dependency -> (C.PackageName, C.VersionRange)
ext (C.Dependency pkgName' vr _) = (pkgName', vr)

condTreeDataL :: Functor f => (a -> f a) -> C.CondTree v c a -> f (C.CondTree v c a)
Expand Down Expand Up @@ -1007,6 +997,20 @@ getBounds GetBoundsOptions{ optGBFiles = fp } = do
log :: MonadIO m => String -> m ()
log = liftIO . hPutStrLn stderr

-- | Run a sequence of IO actions.
-- If any of these throws a user exception, exit with failure after trying all.
sequenceExceptT_ :: [ExceptT IO ()] -> IO ()

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.6.3)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.6.3)

• Expecting one more argument to ‘IO’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.6.3)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.4.7)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.4.7)

• Expecting one more argument to ‘IO’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.4.7)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 8.10.7)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 8.10.7)

• Expecting one more argument to ‘IO’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 8.10.7)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.2.8)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.2.8)

• Expecting one more argument to ‘IO’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.2.8)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.0.2)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.0.2)

• Expecting one more argument to ‘IO’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.0.2)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (windows-latest, 9.6.3)

* Expecting one more argument to `ExceptT IO ()'

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (windows-latest, 9.6.3)

* Expecting one more argument to `IO'

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (windows-latest, 9.6.3)

* Expected kind `* -> *', but `()' has kind `*'

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (macos-latest, 9.6.3)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (macos-latest, 9.6.3)

• Expecting one more argument to ‘IO’

Check failure on line 1002 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (macos-latest, 9.6.3)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’
sequenceExceptT_ ms = do
results <- mapM runExceptToBool ms
unless (and results) exitFailure

-- | Run an IO action. If it throws a user exception, 'log' it and return @False@, else @True@.
runExceptToBool :: ExceptT IO () -> IO Bool

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.6.3)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.6.3)

• Expecting one more argument to ‘IO’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.6.3)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.4.7)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.4.7)

• Expecting one more argument to ‘IO’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.4.7)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 8.10.7)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 8.10.7)

• Expecting one more argument to ‘IO’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 8.10.7)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.2.8)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.2.8)

• Expecting one more argument to ‘IO’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.2.8)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.0.2)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.0.2)

• Expecting one more argument to ‘IO’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 9.0.2)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (windows-latest, 9.6.3)

* Expecting one more argument to `ExceptT IO ()'

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (windows-latest, 9.6.3)

* Expecting one more argument to `IO'

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (windows-latest, 9.6.3)

* Expected kind `* -> *', but `()' has kind `*'

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (macos-latest, 9.6.3)

• Expecting one more argument to ‘ExceptT IO ()’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (macos-latest, 9.6.3)

• Expecting one more argument to ‘IO’

Check failure on line 1008 in src/Main.hs

View workflow job for this annotation

GitHub Actions / check (macos-latest, 9.6.3)

• Expected kind ‘* -> *’, but ‘()’ has kind ‘*’
runExceptToBool m =
runExceptT m >>= \case
Left err -> False <$ log err
Right () -> return True

-- | Try to clean-up HTML fragments to be more readable
tidyHtml :: ByteString -> ByteString
tidyHtml =
Expand Down

0 comments on commit 620ee0c

Please sign in to comment.