Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 559 lines (492 sloc) 20.381 kb
aff37c25 »
2005-09-05 First release of HackPort, the Hackage tool for Portage
1 module Main where
2
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
3 import Control.Applicative
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
4 import Control.Monad
7d1091ea »
2007-08-29 Change parameter to merge and remove --portage-category
5 import Data.Maybe
cfd83a3f »
2005-09-24 Introducing a local cache to speed things up
6 import Data.List
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
7 import Data.Monoid
8 ( Monoid(..) )
9
10 -- cabal
11 import Distribution.Simple.Setup
12 ( Flag(..), fromFlag
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
13 , trueArg
2d84418a »
2010-07-09 Remove useless imports and variables.
14 , flagToList
a973398e »
2008-09-01 Fix verbosity flag
15 , optionVerbosity
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
16 )
17 import Distribution.ReadE ( succeedReadE )
18 import Distribution.Simple.Command -- commandsRun
6c58c4af »
2010-05-13 Add stub for distromap
19 import Distribution.Simple.Utils ( die, cabalVersion, warn )
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
20 import qualified Distribution.PackageDescription.Parse as Cabal
21 import qualified Distribution.Package as Cabal
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
22 import Distribution.Verbosity (Verbosity, normal)
6b6ca6bf »
2010-08-04 Fix the broken 'hackport make-ebuild'
23 import Distribution.Text (display, simpleParse)
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
24
25 import Distribution.Client.Types
26 import Distribution.Client.Update
60d04de6 »
2009-11-29 adapt to cabal-1.8 and cabal-install-0.7.5 (HEADs)
27
28 import qualified Distribution.Client.PackageIndex as Index
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
29 import qualified Distribution.Client.IndexUtils as Index
30
bf26c18d »
2012-02-26 cleanup: factor out Main.defaultRepo{,URI} to separate Hackage file
31 import Hackage (defaultRepo, defaultRepoURI)
32
27f08f37 »
2009-03-23 Move host information code into Portage.Host
33 import Portage.Overlay as Overlay ( loadLazy, inOverlay )
34 import Portage.Host as Host ( getInfo, portage_dir )
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
35 import Portage.PackageId ( normalizeCabalPackageId )
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
36
bf26c18d »
2012-02-26 cleanup: factor out Main.defaultRepo{,URI} to separate Hackage file
37 import Network.URI ( URI(..), parseURI )
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
38 import System.Environment ( getArgs, getProgName )
6c58c4af »
2010-05-13 Add stub for distromap
39 import System.Directory ( doesDirectoryExist )
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
40 import System.Exit ( exitFailure )
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
41 import System.FilePath ( (</>) )
263875af »
2005-09-21 Less ugly debug method
42
03de0f6e »
2005-09-21 Adding diff command to HackPort
43 import Diff
9448bb73 »
2007-08-13 Rewritten overlayonly functionality
44 import Error
78d22a26 »
2007-08-19 Rename overlayonly to status
45 import Status
47991e57 »
2008-04-18 Add stub for supporting overlays defined in paludis
46 import Overlays
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
47 import Merge
6c58c4af »
2010-05-13 Add stub for distromap
48 import DistroMap ( distroMap )
9448bb73 »
2007-08-13 Rewritten overlayonly functionality
49
d5f677b2 »
2009-12-20 Main.hs: removed unused instances and trivial name clashes
50 import qualified Paths_cabal_install
afdf716f »
2009-02-19 Add --version and --numeric-version flags
51 import qualified Paths_hackport
52
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
53 -----------------------------------------------------------------------
54 -- List
55 -----------------------------------------------------------------------
56
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
57 data ListFlags = ListFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
58 listVerbosity :: Flag Verbosity
59 -- , listOverlayPath :: Flag FilePath
60 -- , listServerURI :: Flag String
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
61 }
62
63 instance Monoid ListFlags where
64 mempty = ListFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
65 listVerbosity = mempty
66 -- , listOverlayPath = mempty
67 -- , listServerURI = mempty
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
68 }
69 mappend a b = ListFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
70 listVerbosity = combine listVerbosity
71 -- , listOverlayPath = combine listOverlayPath
72 -- , listServerURI = combine listServerURI
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
73 }
74 where combine field = field a `mappend` field b
75
76 defaultListFlags :: ListFlags
77 defaultListFlags = ListFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
78 listVerbosity = Flag normal
79 -- , listOverlayPath = NoFlag
80 -- , listServerURI = Flag defaultHackageServerURI
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
81 }
82
83 listCommand :: CommandUI ListFlags
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
84 listCommand = CommandUI {
85 commandName = "list",
86 commandSynopsis = "List packages",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
87 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
88 "TODO: this is the commandDescription for listCommand\n",
89 commandUsage = usagePackages "list",
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
90 commandDefaultFlags = defaultListFlags,
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
91 commandOptions = \_showOrParseArgs ->
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
92 [ optionVerbosity listVerbosity (\v flags -> flags { listVerbosity = v })
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
93 {-
7b506822 »
2008-09-01 Move portdir and overlay flags to respective command
94 , option [] ["overlay"]
95 "Use cached packages list from specified overlay"
96 listOverlayPath (\v flags -> flags { listOverlayPath = v })
97 (reqArgFlag "PATH")
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
98 -}
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
99 ]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
100 }
101
04af916b »
2008-09-01 Enable --verbose for 'hackport list'
102 listAction :: ListFlags -> [String] -> GlobalFlags -> IO ()
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
103 listAction flags extraArgs globalFlags = do
225135fd »
2008-09-07 Switch to using Portage.{PackageId,Version}
104 let verbosity = fromFlag (listVerbosity flags)
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
105 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
106 let repo = defaultRepo overlayPath
ac5deac3 »
2011-10-06 port to (bundled) Cabal-1.12
107 index <- fmap packageIndex (Index.getSourcePackages verbosity [ repo ])
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
108 overlay <- Overlay.loadLazy overlayPath
60d04de6 »
2009-11-29 adapt to cabal-1.8 and cabal-install-0.7.5 (HEADs)
109 let pkgs | null extraArgs = Index.allPackages index
ac5deac3 »
2011-10-06 port to (bundled) Cabal-1.12
110 | otherwise = concatMap (concatMap snd . Index.searchByNameSubstring index) extraArgs
88e7a14e »
2009-02-08 Fix 'hackport list' to handle package names properly
111 normalized = map (normalizeCabalPackageId . packageInfoId) pkgs
112 let decorated = map (\p -> (Overlay.inOverlay overlay p, p)) normalized
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
113 mapM_ (putStrLn . pretty) decorated
114 where
88e7a14e »
2009-02-08 Fix 'hackport list' to handle package names properly
115 pretty :: (Bool, Cabal.PackageIdentifier) -> String
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
116 pretty (isInOverlay, pkgId) =
117 let dec | isInOverlay = " * "
118 | otherwise = " "
88e7a14e »
2009-02-08 Fix 'hackport list' to handle package names properly
119 in dec ++ display pkgId
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
120
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
121
122 -----------------------------------------------------------------------
123 -- Make Ebuild
124 -----------------------------------------------------------------------
125
a096cbf6 »
2008-09-01 Enable --verbose for 'hackport make-ebuild'
126 data MakeEbuildFlags = MakeEbuildFlags {
127 makeEbuildVerbosity :: Flag Verbosity
128 }
129
130 instance Monoid MakeEbuildFlags where
131 mempty = MakeEbuildFlags {
132 makeEbuildVerbosity = mempty
133 }
134 mappend a b = MakeEbuildFlags {
135 makeEbuildVerbosity = combine makeEbuildVerbosity
136 }
137 where combine field = field a `mappend` field b
138
139 defaultMakeEbuildFlags :: MakeEbuildFlags
140 defaultMakeEbuildFlags = MakeEbuildFlags {
141 makeEbuildVerbosity = Flag normal
142 }
143
144 makeEbuildAction :: MakeEbuildFlags -> [String] -> GlobalFlags -> IO ()
6b6ca6bf »
2010-08-04 Fix the broken 'hackport make-ebuild'
145 makeEbuildAction flags args globalFlags = do
146 (catstr,cabals) <- case args of
147 (category:cabal1:cabaln) -> return (category, cabal1:cabaln)
148 _ -> throwEx (ArgumentError "make-ebuild needs at least two arguments. <category> <cabal-1> <cabal-n>")
149 cat <- case simpleParse catstr of
150 Just c -> return c
151 Nothing -> throwEx (ArgumentError ("could not parse category: " ++ catstr))
152 let verbosity = fromFlag (makeEbuildVerbosity flags)
153 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
154 forM_ cabals $ \cabalFileName -> do
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
155 pkg <- Cabal.readPackageDescription normal cabalFileName
6b6ca6bf »
2010-08-04 Fix the broken 'hackport make-ebuild'
156 mergeGenericPackageDescription verbosity overlayPath cat pkg False
32a344ce »
2008-08-23 hackport-cabal2ebuild.patch
157
a096cbf6 »
2008-09-01 Enable --verbose for 'hackport make-ebuild'
158 makeEbuildCommand :: CommandUI MakeEbuildFlags
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
159 makeEbuildCommand = CommandUI {
160 commandName = "make-ebuild",
161 commandSynopsis = "Make an ebuild from a .cabal file",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
162 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
163 "TODO: this is the commandDescription for makeEbuildCommand\n",
164 commandUsage = \_ -> [],
a096cbf6 »
2008-09-01 Enable --verbose for 'hackport make-ebuild'
165 commandDefaultFlags = defaultMakeEbuildFlags,
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
166 commandOptions = \_showOrParseArgs ->
a096cbf6 »
2008-09-01 Enable --verbose for 'hackport make-ebuild'
167 [ optionVerbosity makeEbuildVerbosity (\v flags -> flags { makeEbuildVerbosity = v })
168 ]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
169 }
170
171 -----------------------------------------------------------------------
172 -- Diff
173 -----------------------------------------------------------------------
174
175 data DiffFlags = DiffFlags {
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
176 -- diffMode :: Flag String, -- DiffMode,
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
177 diffVerbosity :: Flag Verbosity
178 -- , diffServerURI :: Flag String
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
179 }
180
181 instance Monoid DiffFlags where
182 mempty = DiffFlags {
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
183 -- diffMode = mempty,
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
184 diffVerbosity = mempty
185 -- , diffServerURI = mempty
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
186 }
187 mappend a b = DiffFlags {
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
188 -- diffMode = combine diffMode,
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
189 diffVerbosity = combine diffVerbosity
190 -- , diffServerURI = combine diffServerURI
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
191 }
192 where combine field = field a `mappend` field b
193
194 defaultDiffFlags :: DiffFlags
195 defaultDiffFlags = DiffFlags {
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
196 -- diffMode = Flag "all",
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
197 diffVerbosity = Flag normal
198 -- , diffServerURI = Flag defaultHackageServerURI
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
199 }
200
201 diffCommand :: CommandUI DiffFlags
202 diffCommand = CommandUI {
203 commandName = "diff",
204 commandSynopsis = "Run diff",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
205 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
206 "TODO: this is the commandDescription for diffCommand\n",
207 commandUsage = usagePackages "diff",
208 commandDefaultFlags = defaultDiffFlags,
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
209 commandOptions = \_showOrParseArgs ->
a08b0e74 »
2008-09-01 Enable --verbose for 'hackport diff'
210 [ optionVerbosity diffVerbosity (\v flags -> flags { diffVerbosity = v })
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
211 {-
878c612a »
2008-09-22 Fix mode flags for 'hackport diff'
212 , option [] ["mode"]
213 "Diff mode, one of: all, newer, missing, additions, common"
214 diffMode (\v flags -> flags { diffMode = v })
215 (reqArgFlag "MODE") -- I don't know how to map it strictly to DiffMode
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
216 -}
a08b0e74 »
2008-09-01 Enable --verbose for 'hackport diff'
217 ]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
218 }
219
220 diffAction :: DiffFlags -> [String] -> GlobalFlags -> IO ()
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
221 diffAction flags args globalFlags = do
b7d874ef »
2008-09-07 Rename verbose -> verbosity
222 let verbosity = fromFlag (diffVerbosity flags)
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
223 -- dm0 = fromFlag (diffMode flags)
224 dm <- case args of
225 [] -> return ShowAll
226 ["all"] -> return ShowAll
227 ["missing"] -> return ShowMissing
228 ["additions"] -> return ShowAdditions
229 ["newer"] -> return ShowNewer
230 ["common"] -> return ShowCommon
eef57f0f »
2008-10-04 Allow to diff by package name
231 ("package": pkgs) -> return (ShowPackages pkgs)
fa219c2a »
2008-10-01 Switch back to the old syntax, the new was quite annoying
232 -- TODO: ["package",packagePattern] ->
233 -- return ShowPackagePattern packagePattern
234 _ -> die $ "Unknown mode: " ++ unwords args
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
235 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
d5f677b2 »
2009-12-20 Main.hs: removed unused instances and trivial name clashes
236 let repo = defaultRepo overlayPath
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
237 runDiff verbosity overlayPath dm repo
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
238
239 -----------------------------------------------------------------------
240 -- Update
241 -----------------------------------------------------------------------
242
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
243 data UpdateFlags = UpdateFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
244 updateVerbosity :: Flag Verbosity
245 -- , updateServerURI :: Flag String
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
246 }
247
248 instance Monoid UpdateFlags where
249 mempty = UpdateFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
250 updateVerbosity = mempty
251 -- , updateServerURI = mempty
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
252 }
253 mappend a b = UpdateFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
254 updateVerbosity = combine updateVerbosity
255 -- , updateServerURI = combine updateServerURI
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
256 }
257 where combine field = field a `mappend` field b
258
259 defaultUpdateFlags :: UpdateFlags
260 defaultUpdateFlags = UpdateFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
261 updateVerbosity = Flag normal
262 -- , updateServerURI = Flag defaultHackageServerURI
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
263 }
264
265 updateCommand :: CommandUI UpdateFlags
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
266 updateCommand = CommandUI {
267 commandName = "update",
268 commandSynopsis = "Update the local cache",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
269 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
270 "TODO: this is the commandDescription for updateCommand\n",
271 commandUsage = usageFlags "update",
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
272 commandDefaultFlags = defaultUpdateFlags,
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
273 commandOptions = \_ ->
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
274 [ optionVerbosity updateVerbosity (\v flags -> flags { updateVerbosity = v })
275
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
276 {-
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
277 , option [] ["server"]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
278 "Set the server you'd like to update the cache from"
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
279 updateServerURI (\v flags -> flags { updateServerURI = v} )
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
280 (reqArgFlag "SERVER")
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
281 -}
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
282 ]
283 }
284
c4d52c54 »
2008-09-01 Enable --verbose for 'hackport update'
285 updateAction :: UpdateFlags -> [String] -> GlobalFlags -> IO ()
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
286 updateAction flags extraArgs globalFlags = do
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
287 unless (null extraArgs) $
288 die $ "'update' doesn't take any extra arguments: " ++ unwords extraArgs
b7d874ef »
2008-09-07 Rename verbose -> verbosity
289 let verbosity = fromFlag (updateVerbosity flags)
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
290 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
291 update verbosity [ defaultRepo overlayPath ]
292
cfd83a3f »
2005-09-24 Introducing a local cache to speed things up
293
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
294 -----------------------------------------------------------------------
295 -- Status
296 -----------------------------------------------------------------------
297
298 data StatusFlags = StatusFlags {
72143bad »
2008-09-01 Enable --verbose for 'hackport status'
299 statusVerbosity :: Flag Verbosity,
dd1447b0 »
2012-02-21 hackport status: now it works with hackage!
300 statusDirection :: Flag StatusDirection
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
301 }
302
303 defaultStatusFlags :: StatusFlags
304 defaultStatusFlags = StatusFlags {
72143bad »
2008-09-01 Enable --verbose for 'hackport status'
305 statusVerbosity = Flag normal,
dd1447b0 »
2012-02-21 hackport status: now it works with hackage!
306 statusDirection = Flag PortagePlusOverlay
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
307 }
308
309 statusCommand :: CommandUI StatusFlags
310 statusCommand = CommandUI {
311 commandName = "status",
312 commandSynopsis = "Show status(??)",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
313 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
314 "TODO: this is the commandDescription for statusCommand\n",
315 commandUsage = usagePackages "status",
316 commandDefaultFlags = defaultStatusFlags,
7b506822 »
2008-09-01 Move portdir and overlay flags to respective command
317 commandOptions = \_ ->
72143bad »
2008-09-01 Enable --verbose for 'hackport status'
318 [ optionVerbosity statusVerbosity (\v flags -> flags { statusVerbosity = v })
319 , option [] ["to-portage"]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
320 "Print only packages likely to be interesting to move to the portage tree."
dd1447b0 »
2012-02-21 hackport status: now it works with hackage!
321 statusDirection (\v flags -> flags { statusDirection = v })
322 (noArg (Flag OverlayToPortage))
323 , option [] ["from-hackage"]
324 "Print only packages likely to be interesting to move from hackage tree."
325 statusDirection (\v flags -> flags { statusDirection = v })
326 (noArg (Flag HackageToOverlay))
7b506822 »
2008-09-01 Move portdir and overlay flags to respective command
327 ]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
328 }
329
330 statusAction :: StatusFlags -> [String] -> GlobalFlags -> IO ()
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
331 statusAction flags args globalFlags = do
b7d874ef »
2008-09-07 Rename verbose -> verbosity
332 let verbosity = fromFlag (statusVerbosity flags)
dd1447b0 »
2012-02-21 hackport status: now it works with hackage!
333 direction = fromFlag (statusDirection flags)
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
334 portagePath <- getPortageDir verbosity globalFlags
335 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
dd1447b0 »
2012-02-21 hackport status: now it works with hackage!
336 runStatus verbosity portagePath overlayPath direction args
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
337
338 -----------------------------------------------------------------------
339 -- Merge
340 -----------------------------------------------------------------------
341
dab787f8 »
2008-09-01 Fix more flags
342 data MergeFlags = MergeFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
343 mergeVerbosity :: Flag Verbosity
344 -- , mergeServerURI :: Flag String
dab787f8 »
2008-09-01 Fix more flags
345 }
346
347 instance Monoid MergeFlags where
348 mempty = MergeFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
349 mergeVerbosity = mempty
350 -- , mergeServerURI = mempty
dab787f8 »
2008-09-01 Fix more flags
351 }
352 mappend a b = MergeFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
353 mergeVerbosity = combine mergeVerbosity
354 -- , mergeServerURI = combine mergeServerURI
dab787f8 »
2008-09-01 Fix more flags
355 }
356 where combine field = field a `mappend` field b
357
358 defaultMergeFlags :: MergeFlags
359 defaultMergeFlags = MergeFlags {
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
360 mergeVerbosity = Flag normal
361 -- , mergeServerURI = Flag defaultHackageServerURI
dab787f8 »
2008-09-01 Fix more flags
362 }
363
364 mergeCommand :: CommandUI MergeFlags
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
365 mergeCommand = CommandUI {
366 commandName = "merge",
367 commandSynopsis = "Make an ebuild out of hackage package",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
368 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
369 "TODO: this is the commandDescription for mergeCommand\n",
370 commandUsage = usagePackages "merge",
dab787f8 »
2008-09-01 Fix more flags
371 commandDefaultFlags = defaultMergeFlags,
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
372 commandOptions = \_showOrParseArgs ->
dab787f8 »
2008-09-01 Fix more flags
373 [ optionVerbosity mergeVerbosity (\v flags -> flags { mergeVerbosity = v })
374
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
375 {-
dab787f8 »
2008-09-01 Fix more flags
376 , option [] ["server"]
377 "Set the server you'd like to update the cache from"
378 mergeServerURI (\v flags -> flags { mergeServerURI = v} )
379 (reqArgFlag "SERVER")
8273e68c »
2009-02-07 Update the CLI and start using cabal-install features
380 -}
dab787f8 »
2008-09-01 Fix more flags
381 ]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
382 }
383
dab787f8 »
2008-09-01 Fix more flags
384 mergeAction :: MergeFlags -> [String] -> GlobalFlags -> IO ()
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
385 mergeAction flags extraArgs globalFlags = do
b7d874ef »
2008-09-07 Rename verbose -> verbosity
386 let verbosity = fromFlag (mergeVerbosity flags)
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
387 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
f3093658 »
2009-02-19 Reimplement 'hackport merge'
388 let repo = defaultRepo overlayPath
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
389 merge verbosity repo (defaultRepoURI overlayPath) extraArgs overlayPath
6ec3592d »
2008-11-12 Hackport now uses Cabal-1.6
390
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
391 -----------------------------------------------------------------------
6c58c4af »
2010-05-13 Add stub for distromap
392 -- DistroMap
393 -----------------------------------------------------------------------
394
395 data DistroMapFlags = DistroMapFlags {
396 distroMapVerbosity :: Flag Verbosity
397 }
398
399 instance Monoid DistroMapFlags where
400 mempty = DistroMapFlags {
401 distroMapVerbosity = mempty
402 -- , mergeServerURI = mempty
403 }
404 mappend a b = DistroMapFlags {
405 distroMapVerbosity = combine distroMapVerbosity
406 }
407 where combine field = field a `mappend` field b
408
409 defaultDistroMapFlags :: DistroMapFlags
410 defaultDistroMapFlags = DistroMapFlags {
411 distroMapVerbosity = Flag normal
412 }
413
414 distroMapCommand :: CommandUI DistroMapFlags
415 distroMapCommand = CommandUI {
416 commandName = "distromap",
417 commandSynopsis = "Build a distromap file",
418 commandDescription = Just $ \_pname ->
419 "TODO: this is the commandDescription for distroMapCommand\n",
420 commandUsage = usagePackages "distromap",
421 commandDefaultFlags = defaultDistroMapFlags,
422 commandOptions = \_showOrParseArgs ->
423 [ optionVerbosity distroMapVerbosity (\v flags -> flags { distroMapVerbosity = v })
424 ]
425 }
426
427 distroMapAction :: DistroMapFlags-> [String] -> GlobalFlags -> IO ()
428 distroMapAction flags extraArgs globalFlags = do
429 let verbosity = fromFlag (distroMapVerbosity flags)
430 overlayPath <- getOverlayPath verbosity (fromFlag $ globalPathToOverlay globalFlags)
431 let repo = defaultRepo overlayPath
432 portagePath <- getPortageDir verbosity globalFlags
433 distroMap verbosity repo portagePath overlayPath extraArgs
434
435 -----------------------------------------------------------------------
7b506822 »
2008-09-01 Move portdir and overlay flags to respective command
436 -- Utils
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
437 -----------------------------------------------------------------------
438
225135fd »
2008-09-07 Switch to using Portage.{PackageId,Version}
439 getServerURI :: String -> IO URI
440 getServerURI str =
441 case parseURI str of
442 Just uri -> return uri
443 Nothing -> throwEx (InvalidServer str)
444
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
445 reqArgFlag :: ArgPlaceHolder -> SFlags -> LFlags -> Description ->
446 (b -> Flag String) -> (Flag String -> b -> b) -> OptDescr b
447 reqArgFlag ad = reqArg ad (succeedReadE Flag) flagToList
448
449 usagePackages :: String -> String -> String
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
450 usagePackages op_name pname =
451 "Usage: " ++ pname ++ " " ++ op_name ++ " [FLAGS] [PACKAGE]\n\n"
452 ++ "Flags for " ++ op_name ++ ":"
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
453
454 usageFlags :: String -> String -> String
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
455 usageFlags flag_name pname =
456 "Usage: " ++ pname ++ " " ++ flag_name ++ " [FLAGS]\n\n"
457 ++ "Flags for " ++ flag_name ++ ":"
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
458
6c58c4af »
2010-05-13 Add stub for distromap
459 getPortageDir :: Verbosity -> GlobalFlags -> IO FilePath
460 getPortageDir verbosity globalFlags = do
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
461 let portagePathM = fromFlag (globalPathToPortage globalFlags)
462 portagePath <- case portagePathM of
463 Nothing -> Host.portage_dir <$> Host.getInfo
464 Just path -> return path
6c58c4af »
2010-05-13 Add stub for distromap
465 exists <- doesDirectoryExist $ portagePath </> "dev-haskell"
466 when (not exists) $
467 warn verbosity $ "Looks like an invalid portage directory: " ++ portagePath
468 return portagePath
469
7b506822 »
2008-09-01 Move portdir and overlay flags to respective command
470 -----------------------------------------------------------------------
471 -- Main
472 -----------------------------------------------------------------------
473
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
474 data GlobalFlags =
475 GlobalFlags { globalVersion :: Flag Bool
476 , globalNumericVersion :: Flag Bool
477 , globalPathToOverlay :: Flag (Maybe FilePath)
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
478 , globalPathToPortage :: Flag (Maybe FilePath)
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
479 }
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
480
481 defaultGlobalFlags :: GlobalFlags
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
482 defaultGlobalFlags =
483 GlobalFlags { globalVersion = Flag False
484 , globalNumericVersion = Flag False
485 , globalPathToOverlay = Flag Nothing
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
486 , globalPathToPortage = Flag Nothing
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
487 }
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
488
489 globalCommand :: CommandUI GlobalFlags
490 globalCommand = CommandUI {
491 commandName = "",
492 commandSynopsis = "",
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
493 commandDescription = Just $ \_pname ->
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
494 "TODO: this is the commandDescription for globalCommand\n",
495 commandUsage = \_ -> [],
496 commandDefaultFlags = defaultGlobalFlags,
cc5f55ff »
2009-03-07 -Wall fixes for Main.hs (name collisions, unused vars in cmdline proc…
497 commandOptions = \_showOrParseArgs ->
afdf716f »
2009-02-19 Add --version and --numeric-version flags
498 [ option ['V'] ["version"]
499 "Print version information"
500 globalVersion (\v flags -> flags { globalVersion = v })
501 trueArg
502 , option [] ["numeric-version"]
503 "Print just the version number"
504 globalNumericVersion (\v flags -> flags { globalNumericVersion = v })
505 trueArg
df59c138 »
2009-03-29 resurrected support of global '-p' (aka --overlay-path' flag
506 , option ['p'] ["overlay-path"]
507 "Override search path list where .hackport/ lives (default list: ['.', paludis-ovls or emerge-ovls])"
6c58c4af »
2010-05-13 Add stub for distromap
508 globalPathToOverlay (\ovrl_path flags -> flags { globalPathToOverlay = ovrl_path })
509 (reqArg' "PATH" (Flag . Just) (\(Flag ms) -> catMaybes [ms]))
510 , option [] ["portage-path"]
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
511 "Override path to your portage tree"
6c58c4af »
2010-05-13 Add stub for distromap
512 globalPathToPortage (\port_path flags -> flags { globalPathToPortage = port_path })
a08cf8e8 »
2010-05-13 status: use global flags instead of flags specific to status
513 (reqArg' "PATH" (Flag . Just) (\(Flag ms) -> catMaybes [ms]))
afdf716f »
2009-02-19 Add --version and --numeric-version flags
514 ]
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
515 }
516
517 mainWorker :: [String] -> IO ()
518 mainWorker args =
519 case commandsRun globalCommand commands args of
520 CommandHelp help -> printHelp help
521 CommandList opts -> printOptionsList opts
522 CommandErrors errs -> printErrors errs
523 CommandReadyToGo (globalflags, commandParse) -> do
6ec3592d »
2008-11-12 Hackport now uses Cabal-1.6
524 case commandParse of
afdf716f »
2009-02-19 Add --version and --numeric-version flags
525 _ | fromFlag (globalVersion globalflags) -> printVersion
526 | fromFlag (globalNumericVersion globalflags) -> printNumericVersion
527 CommandHelp help -> printHelp help
528 CommandList opts -> printOptionsList opts
529 CommandErrors errs -> printErrors errs
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
530 CommandReadyToGo action -> catchEx (action globalflags) errorHandler
531 where
532 printHelp help = getProgName >>= putStr . help
533 printOptionsList = putStr . unlines
534 printErrors errs = do
535 putStr (concat (intersperse "\n" errs))
536 exitFailure
afdf716f »
2009-02-19 Add --version and --numeric-version flags
537 printNumericVersion = putStrLn $ display Paths_hackport.version
538 printVersion = putStrLn $ "hackport version "
539 ++ display Paths_hackport.version
540 ++ "\nusing cabal-install "
541 ++ display Paths_cabal_install.version
542 ++ " and the Cabal library version "
543 ++ display cabalVersion
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
544 errorHandler :: HackPortError -> IO ()
545 errorHandler e = do
546 putStrLn (hackPortShowError e)
547 commands =
548 [ listCommand `commandAddAction` listAction
549 , makeEbuildCommand `commandAddAction` makeEbuildAction
550 , statusCommand `commandAddAction` statusAction
551 , diffCommand `commandAddAction` diffAction
552 , updateCommand `commandAddAction` updateAction
553 , mergeCommand `commandAddAction` mergeAction
6c58c4af »
2010-05-13 Add stub for distromap
554 , distroMapCommand `commandAddAction` distroMapAction
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
555 ]
6ec3592d »
2008-11-12 Hackport now uses Cabal-1.6
556
aff37c25 »
2005-09-05 First release of HackPort, the Hackage tool for Portage
557 main :: IO ()
a1730ad8 »
2008-08-31 Switch to using Cabal's CLI API
558 main = getArgs >>= mainWorker
Something went wrong with that request. Please try again.