{-# LANGUAGE PackageImports, ScopedTypeVariables, TupleSections #-} {-# OPTIONS -fno-warn-name-shadowing #-} module Debian.Repo.Package.Internal.ParseSourceParagraph ( parseSourceParagraph ) where import Debian.Control (ControlFunctions(stripWS)) import qualified Debian.Control.Text as B (fieldValue, Paragraph) import Debian.Repo.Types.PackageIndex (SourceControl(..)) parseSourceParagraph :: B.Paragraph -> Either [String] SourceControl parseSourceParagraph p = -- Look up the required fields case (B.fieldValue "Package" p, B.fieldValue "Maintainer" p) of (Just source', Just maintainer') -> -- The optional fields can be parsed as pure values Right (SourceControl { source = source' , maintainer = maintainer' , uploaders = maybe [] (: []) $ B.fieldValue "Uploaders" p , packageSection = fmap stripWS $ B.fieldValue "Section" p , packagePriority = fmap stripWS $ B.fieldValue "Priority" p , buildDepends = maybe [] (: []) $ B.fieldValue "Build-Depends" p , buildDependsIndep = maybe [] (: []) $ B.fieldValue "Build-Depends-Indep" p , buildConflicts = maybe [] (: []) $ B.fieldValue "Build-Conflicts" p , buildConflictsIndep = maybe [] (: []) $ B.fieldValue "Build-Conflicts-Indep" p , standardsVersion = fmap stripWS $ B.fieldValue "Standards-Version" p , homepage = fmap stripWS $ B.fieldValue "Homepage" p }) _x -> Left ["parseSourceParagraph - One or more required fields (Package, Maintainer, Standards-Version) missing: " ++ show p]