Skip to content

Commit

Permalink
Refactor partial functions
Browse files Browse the repository at this point in the history
Closes: #21
Signed-off-by: hololeap <[email protected]>
  • Loading branch information
hololeap committed Mar 4, 2024
1 parent d15f475 commit d39a04f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Distribution/Gentoo/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Distribution.Gentoo.Packages
-- Cabal imports
import qualified Distribution.Simple.Utils as DSU
import Distribution.Verbosity(silent)
import Distribution.Package(PackageIdentifier, packageId)
import Distribution.Package(packageId)
import Distribution.InstalledPackageInfo(InstalledPackageInfo)
import Distribution.Text(display)

Expand All @@ -51,7 +51,13 @@ import Output

-- Get only the first line of output
rawSysStdOutLine :: FilePath -> [String] -> IO String
rawSysStdOutLine app = fmap (head . lines) . rawCommand app
rawSysStdOutLine app args = do
out <- rawCommand app args
case lines out of
[] -> error $ unwords
[ "rawSysStdOutLine: Empty output from rawCommand"
, show app, show args ]
(s:_) -> pure s

rawCommand :: FilePath -> [String] -> IO String
rawCommand cmd args = do (out,_,_) <- DSU.rawSystemStdInOut
Expand Down Expand Up @@ -157,11 +163,9 @@ parse_as_cabal_package cont =
-- ebuilds that have CABAL_CORE_LIB_GHC_PV set
-- for this version of GHC will have a .conf
-- file containing just []
[([],_)] -> Nothing
rd -> Just $ CPV $ display $ cfNm rd
where
cfNm :: [([InstalledPackageInfo], String)] -> PackageIdentifier
cfNm = packageId . head . fst . head
(([] ,_):_) -> Nothing
((i:_,_):_) -> Just $ CPV $ display
$ packageId (i :: InstalledPackageInfo)

-- ghc package text format
-- "name: zlib-conduit\n
Expand Down

0 comments on commit d39a04f

Please sign in to comment.