Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 485 lines (426 sloc) 16.187 kB
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
1 module Main where
2
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
3 import Control.Monad
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
4 import Data.Char
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
5 import Data.Maybe
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
6 import Data.List
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
7 import Data.Monoid
8 ( Monoid(..) )
9
10 -- cabal
11 import Distribution.Simple.Setup
12 ( Flag(..), fromFlag
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
13 , falseArg
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
14 , flagToMaybe, flagToList
a973398 @kolmodin Fix verbosity flag
kolmodin authored
15 , optionVerbosity
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
16 )
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
17 import Distribution.PackageDescription.Configuration
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
18 ( flattenPackageDescription )
19 import Distribution.ReadE ( succeedReadE )
20 import Distribution.Simple.Command -- commandsRun
21 import Distribution.Simple.Utils ( die )
22 import qualified Distribution.PackageDescription as Cabal
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
23 import qualified Distribution.PackageDescription.Parse as ParseCabal
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
24 import Distribution.Verbosity (Verbosity, normal)
25
26 import Network.URI
27 import System.Environment ( getArgs, getProgName )
28 import System.Exit ( exitFailure )
e35e41e @kolmodin Make merging respect categories
kolmodin authored
29 import System.IO
263875a Less ugly debug method
der_eq@freenet.de authored
30
9b8eb4b @kolmodin Fix broken flag handling for 'hackport status'
kolmodin authored
31 import Bash
5078263 @kolmodin Make diffing respect categories
kolmodin authored
32 import qualified Cabal2Ebuild as E
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
33 import Cache
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
34 import Diff
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
35 import Error
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
36 import Index
78d22a2 @kolmodin Rename overlayonly to status
kolmodin authored
37 import Status
47991e5 @kolmodin Add stub for supporting overlays defined in paludis
kolmodin authored
38 import Overlays
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
39 import Merge
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
40
32a344c @trofi hackport-cabal2ebuild.patch
trofi authored
41 import Cabal2Ebuild
42
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
43 -----------------------------------------------------------------------
44 -- List
45 -----------------------------------------------------------------------
46
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
47 data ListFlags = ListFlags {
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
48 listVerbosity :: Flag Verbosity,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
49 listOverlayPath :: Flag FilePath,
50 listServerURI :: Flag String
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
51 }
52
53 instance Monoid ListFlags where
54 mempty = ListFlags {
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
55 listVerbosity = mempty,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
56 listOverlayPath = mempty,
57 listServerURI = mempty
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
58 }
59 mappend a b = ListFlags {
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
60 listVerbosity = combine listVerbosity,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
61 listOverlayPath = combine listOverlayPath,
62 listServerURI = combine listServerURI
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
63 }
64 where combine field = field a `mappend` field b
65
66 defaultListFlags :: ListFlags
67 defaultListFlags = ListFlags {
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
68 listVerbosity = Flag normal,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
69 listOverlayPath = NoFlag,
70 listServerURI = Flag defaultHackageServerURI
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
71 }
72
73 listCommand :: CommandUI ListFlags
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
74 listCommand = CommandUI {
75 commandName = "list",
76 commandSynopsis = "List packages",
77 commandDescription = Just $ \pname ->
78 "TODO: this is the commandDescription for listCommand\n",
79 commandUsage = usagePackages "list",
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
80 commandDefaultFlags = defaultListFlags,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
81 commandOptions = \showOrParseArgs ->
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
82 [ optionVerbosity listVerbosity (\v flags -> flags { listVerbosity = v })
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
83 , option [] ["overlay"]
84 "Use cached packages list from specified overlay"
85 listOverlayPath (\v flags -> flags { listOverlayPath = v })
86 (reqArgFlag "PATH")
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
87 ]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
88 }
89
04af916 @kolmodin Enable --verbose for 'hackport list'
kolmodin authored
90 listAction :: ListFlags -> [String] -> GlobalFlags -> IO ()
91 listAction flags args globalFlags = do
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
92 let verbosity = fromFlag (listVerbosity flags)
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
93 portdirM = flagToMaybe (listOverlayPath flags)
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
94 serverURI <- getServerURI (fromFlag $ listServerURI flags)
95 overlay <- maybe (getOverlayPath verbosity) return portdirM
96 index <- readCache verbosity overlay serverURI
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
97 let index' | null name = index
98 | otherwise = filterIndexByPV matchSubstringCaseInsensitive index
99 pkgs = [ pkg ++ "-" ++ ver | (pkg,ver,_) <- index']
100 if null pkgs
101 then throwEx (PackageNotFound name)
102 else putStr . unlines . sort $ pkgs
103 where
104 name | null args = []
105 | otherwise = head args
106 matchSubstringCaseInsensitive otherName _pVver =
107 map toLower name `isInfixOf` map toLower otherName
108
109 -----------------------------------------------------------------------
110 -- Make Ebuild
111 -----------------------------------------------------------------------
112
a096cbf @kolmodin Enable --verbose for 'hackport make-ebuild'
kolmodin authored
113 data MakeEbuildFlags = MakeEbuildFlags {
114 makeEbuildVerbosity :: Flag Verbosity
115 }
116
117 instance Monoid MakeEbuildFlags where
118 mempty = MakeEbuildFlags {
119 makeEbuildVerbosity = mempty
120 }
121 mappend a b = MakeEbuildFlags {
122 makeEbuildVerbosity = combine makeEbuildVerbosity
123 }
124 where combine field = field a `mappend` field b
125
126 defaultMakeEbuildFlags :: MakeEbuildFlags
127 defaultMakeEbuildFlags = MakeEbuildFlags {
128 makeEbuildVerbosity = Flag normal
129 }
130
131 makeEbuildAction :: MakeEbuildFlags -> [String] -> GlobalFlags -> IO ()
132 makeEbuildAction flags args globalFlags = do
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
133 when (null args) $
134 die "make-ebuild needs at least one argument"
a096cbf @kolmodin Enable --verbose for 'hackport make-ebuild'
kolmodin authored
135 let _verbosity = fromFlag (makeEbuildVerbosity flags)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
136 forM_ args $ \cabalFileName -> do
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
137 pkg <- ParseCabal.readPackageDescription normal cabalFileName
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
138 let ebuild = cabal2ebuild (flattenPackageDescription pkg)
32a344c @trofi hackport-cabal2ebuild.patch
trofi authored
139 let ebuildFileName = name ebuild ++ "-" ++ version ebuild ++ ".ebuild"
140 writeFile ebuildFileName (showEBuild ebuild)
141
a096cbf @kolmodin Enable --verbose for 'hackport make-ebuild'
kolmodin authored
142 makeEbuildCommand :: CommandUI MakeEbuildFlags
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
143 makeEbuildCommand = CommandUI {
144 commandName = "make-ebuild",
145 commandSynopsis = "Make an ebuild from a .cabal file",
146 commandDescription = Just $ \pname ->
147 "TODO: this is the commandDescription for makeEbuildCommand\n",
148 commandUsage = \_ -> [],
a096cbf @kolmodin Enable --verbose for 'hackport make-ebuild'
kolmodin authored
149 commandDefaultFlags = defaultMakeEbuildFlags,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
150 commandOptions = \showOrParseArgs ->
a096cbf @kolmodin Enable --verbose for 'hackport make-ebuild'
kolmodin authored
151 [ optionVerbosity makeEbuildVerbosity (\v flags -> flags { makeEbuildVerbosity = v })
152 ]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
153 }
154
155 -----------------------------------------------------------------------
156 -- Diff
157 -----------------------------------------------------------------------
158
159 data DiffFlags = DiffFlags {
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
160 -- diffMode :: Flag String, -- DiffMode,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
161 diffVerbosity :: Flag Verbosity,
162 diffServerURI :: Flag String
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
163 }
164
165 instance Monoid DiffFlags where
166 mempty = DiffFlags {
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
167 -- diffMode = mempty,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
168 diffVerbosity = mempty,
169 diffServerURI = mempty
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
170 }
171 mappend a b = DiffFlags {
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
172 -- diffMode = combine diffMode,
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
173 diffVerbosity = combine diffVerbosity,
174 diffServerURI = combine diffServerURI
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
175 }
176 where combine field = field a `mappend` field b
177
178 defaultDiffFlags :: DiffFlags
179 defaultDiffFlags = DiffFlags {
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
180 -- diffMode = Flag "all",
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
181 diffVerbosity = Flag normal,
182 diffServerURI = Flag defaultHackageServerURI
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
183 }
184
185 diffCommand :: CommandUI DiffFlags
186 diffCommand = CommandUI {
187 commandName = "diff",
188 commandSynopsis = "Run diff",
189 commandDescription = Just $ \pname ->
190 "TODO: this is the commandDescription for diffCommand\n",
191 commandUsage = usagePackages "diff",
192 commandDefaultFlags = defaultDiffFlags,
193 commandOptions = \showOrParseArgs ->
a08b0e7 @kolmodin Enable --verbose for 'hackport diff'
kolmodin authored
194 [ optionVerbosity diffVerbosity (\v flags -> flags { diffVerbosity = v })
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
195 {-
878c612 @kolmodin Fix mode flags for 'hackport diff'
kolmodin authored
196 , option [] ["mode"]
197 "Diff mode, one of: all, newer, missing, additions, common"
198 diffMode (\v flags -> flags { diffMode = v })
199 (reqArgFlag "MODE") -- I don't know how to map it strictly to DiffMode
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
200 -}
a08b0e7 @kolmodin Enable --verbose for 'hackport diff'
kolmodin authored
201 ]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
202 }
203
204 diffAction :: DiffFlags -> [String] -> GlobalFlags -> IO ()
205 diffAction flags args globalFlags = do
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
206 let verbosity = fromFlag (diffVerbosity flags)
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
207 -- dm0 = fromFlag (diffMode flags)
208 dm <- case args of
209 [] -> return ShowAll
210 ["all"] -> return ShowAll
211 ["missing"] -> return ShowMissing
212 ["additions"] -> return ShowAdditions
213 ["newer"] -> return ShowNewer
214 ["common"] -> return ShowCommon
eef57f0 @kolmodin Allow to diff by package name
kolmodin authored
215 ("package": pkgs) -> return (ShowPackages pkgs)
fa219c2 @kolmodin Switch back to the old syntax, the new was quite annoying
kolmodin authored
216 -- TODO: ["package",packagePattern] ->
217 -- return ShowPackagePattern packagePattern
218 _ -> die $ "Unknown mode: " ++ unwords args
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
219 serverURI <- getServerURI (fromFlag $ diffServerURI flags)
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
220 overlayPath <- getOverlayPath verbosity
221 runDiff verbosity overlayPath serverURI dm
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
222
223 -----------------------------------------------------------------------
224 -- Update
225 -----------------------------------------------------------------------
226
c4d52c5 @kolmodin Enable --verbose for 'hackport update'
kolmodin authored
227 data UpdateFlags = UpdateFlags {
228 updateVerbosity :: Flag Verbosity,
229 updateServerURI :: Flag String
230 }
231
232 instance Monoid UpdateFlags where
233 mempty = UpdateFlags {
234 updateVerbosity = mempty,
235 updateServerURI = mempty
236 }
237 mappend a b = UpdateFlags {
238 updateVerbosity = combine updateVerbosity,
239 updateServerURI = combine updateServerURI
240 }
241 where combine field = field a `mappend` field b
242
243 defaultUpdateFlags :: UpdateFlags
244 defaultUpdateFlags = UpdateFlags {
245 updateVerbosity = Flag normal,
246 updateServerURI = Flag defaultHackageServerURI
247 }
248
249 updateCommand :: CommandUI UpdateFlags
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
250 updateCommand = CommandUI {
251 commandName = "update",
252 commandSynopsis = "Update the local cache",
253 commandDescription = Just $ \pname ->
254 "TODO: this is the commandDescription for updateCommand\n",
255 commandUsage = usageFlags "update",
c4d52c5 @kolmodin Enable --verbose for 'hackport update'
kolmodin authored
256 commandDefaultFlags = defaultUpdateFlags,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
257 commandOptions = \_ ->
c4d52c5 @kolmodin Enable --verbose for 'hackport update'
kolmodin authored
258 [ optionVerbosity updateVerbosity (\v flags -> flags { updateVerbosity = v })
259
260 , option [] ["server"]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
261 "Set the server you'd like to update the cache from"
c4d52c5 @kolmodin Enable --verbose for 'hackport update'
kolmodin authored
262 updateServerURI (\v flags -> flags { updateServerURI = v} )
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
263 (reqArgFlag "SERVER")
264 ]
265 }
266
c4d52c5 @kolmodin Enable --verbose for 'hackport update'
kolmodin authored
267 updateAction :: UpdateFlags -> [String] -> GlobalFlags -> IO ()
268 updateAction flags args globalFlags = do
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
269 let verbosity = fromFlag (updateVerbosity flags)
c4d52c5 @kolmodin Enable --verbose for 'hackport update'
kolmodin authored
270 server = fromFlag (updateServerURI flags)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
271 case parseURI server of
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
272 Just uri -> updateCache verbosity uri
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
273 Nothing -> throwEx (InvalidServer server)
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
274
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
275 -----------------------------------------------------------------------
276 -- Status
277 -----------------------------------------------------------------------
278
279 data StatusFlags = StatusFlags {
72143ba @kolmodin Enable --verbose for 'hackport status'
kolmodin authored
280 statusVerbosity :: Flag Verbosity,
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
281 statusOverlayPath :: Flag FilePath,
282 statusPortdirPath :: Flag FilePath,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
283 statusToPortage :: Flag Bool
284 }
285
286 instance Monoid StatusFlags where
287 mempty = StatusFlags {
72143ba @kolmodin Enable --verbose for 'hackport status'
kolmodin authored
288 statusVerbosity = mempty,
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
289 statusOverlayPath = mempty,
290 statusPortdirPath = mempty,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
291 statusToPortage = mempty
292 }
293 mappend a b = StatusFlags {
72143ba @kolmodin Enable --verbose for 'hackport status'
kolmodin authored
294 statusVerbosity = combine statusVerbosity,
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
295 statusOverlayPath = combine statusOverlayPath,
296 statusPortdirPath = combine statusPortdirPath,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
297 statusToPortage = combine statusToPortage
298 }
299 where combine field = field a `mappend` field b
300
301 defaultStatusFlags :: StatusFlags
302 defaultStatusFlags = StatusFlags {
72143ba @kolmodin Enable --verbose for 'hackport status'
kolmodin authored
303 statusVerbosity = Flag normal,
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
304 statusOverlayPath = NoFlag,
305 statusPortdirPath = NoFlag,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
306 statusToPortage = Flag False
307 }
308
309 statusCommand :: CommandUI StatusFlags
310 statusCommand = CommandUI {
311 commandName = "status",
312 commandSynopsis = "Show status(??)",
313 commandDescription = Just $ \pname ->
314 "TODO: this is the commandDescription for statusCommand\n",
315 commandUsage = usagePackages "status",
316 commandDefaultFlags = defaultStatusFlags,
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
317 commandOptions = \_ ->
72143ba @kolmodin Enable --verbose for 'hackport status'
kolmodin authored
318 [ optionVerbosity statusVerbosity (\v flags -> flags { statusVerbosity = v })
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
319 , option [] ["overlay"]
320 "Compare using the specified overlay"
321 statusOverlayPath (\v flags -> flags { statusOverlayPath = v })
322 (reqArgFlag "PATH")
323
324 , option [] ["portdir"]
325 "Compare using the specified portdir"
326 statusPortdirPath (\v flags -> flags { statusPortdirPath = v })
327 (reqArgFlag "PATH")
72143ba @kolmodin Enable --verbose for 'hackport status'
kolmodin authored
328
329 , option [] ["to-portage"]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
330 "Print only packages likely to be interesting to move to the portage tree."
331 statusToPortage (\v flags -> flags { statusToPortage = v })
332 falseArg
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
333 ]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
334 }
335
336 statusAction :: StatusFlags -> [String] -> GlobalFlags -> IO ()
337 statusAction flags args globalFlags = do
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
338 let verbosity = fromFlag (statusVerbosity flags)
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
339 overlayPathM = flagToMaybe (statusOverlayPath flags)
340 portdirM = flagToMaybe (statusPortdirPath flags)
9b8eb4b @kolmodin Fix broken flag handling for 'hackport status'
kolmodin authored
341 toPortdir = fromFlag (statusToPortage flags)
342 portdir <- maybe getSystemPortdir return portdirM
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
343 overlayPath <- maybe (getOverlayPath verbosity) return overlayPathM
fe415df @kolmodin Allow to 'hackport status' by package name
kolmodin authored
344 runStatus verbosity portdir overlayPath toPortdir args
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
345
346 -----------------------------------------------------------------------
347 -- Merge
348 -----------------------------------------------------------------------
349
dab787f @kolmodin Fix more flags
kolmodin authored
350 data MergeFlags = MergeFlags {
351 mergeVerbosity :: Flag Verbosity,
352 mergeServerURI :: Flag String
353 }
354
355 instance Monoid MergeFlags where
356 mempty = MergeFlags {
357 mergeVerbosity = mempty,
358 mergeServerURI = mempty
359 }
360 mappend a b = MergeFlags {
361 mergeVerbosity = combine mergeVerbosity,
362 mergeServerURI = combine mergeServerURI
363 }
364 where combine field = field a `mappend` field b
365
366 defaultMergeFlags :: MergeFlags
367 defaultMergeFlags = MergeFlags {
368 mergeVerbosity = Flag normal,
369 mergeServerURI = Flag defaultHackageServerURI
370 }
371
372 mergeCommand :: CommandUI MergeFlags
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
373 mergeCommand = CommandUI {
374 commandName = "merge",
375 commandSynopsis = "Make an ebuild out of hackage package",
376 commandDescription = Just $ \pname ->
377 "TODO: this is the commandDescription for mergeCommand\n",
378 commandUsage = usagePackages "merge",
dab787f @kolmodin Fix more flags
kolmodin authored
379 commandDefaultFlags = defaultMergeFlags,
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
380 commandOptions = \showOrParseArgs ->
dab787f @kolmodin Fix more flags
kolmodin authored
381 [ optionVerbosity mergeVerbosity (\v flags -> flags { mergeVerbosity = v })
382
383 , option [] ["server"]
384 "Set the server you'd like to update the cache from"
385 mergeServerURI (\v flags -> flags { mergeServerURI = v} )
386 (reqArgFlag "SERVER")
387 ]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
388 }
389
dab787f @kolmodin Fix more flags
kolmodin authored
390 mergeAction :: MergeFlags -> [String] -> GlobalFlags -> IO ()
391 mergeAction flags [pkg] globalFlags = do
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
392 let verbosity = fromFlag (mergeVerbosity flags)
dab787f @kolmodin Fix more flags
kolmodin authored
393 server = fromFlag (mergeServerURI flags)
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
394 case parseURI server of
b7d874e @kolmodin Rename verbose -> verbosity
kolmodin authored
395 Just uri -> merge verbosity uri pkg
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
396 Nothing -> throwEx (InvalidServer server)
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
397
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
398 mergeAction _ _ _ =
399 throwEx (ArgumentError "'merge' needs exactly one parameter")
400
401 -----------------------------------------------------------------------
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
402 -- Utils
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
403 -----------------------------------------------------------------------
404
405 defaultHackageServerURI :: String
406 defaultHackageServerURI = "http://hackage.haskell.org/packages/archive/"
407
225135f @kolmodin Switch to using Portage.{PackageId,Version}
kolmodin authored
408 getServerURI :: String -> IO URI
409 getServerURI str =
410 case parseURI str of
411 Just uri -> return uri
412 Nothing -> throwEx (InvalidServer str)
413
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
414 reqArgFlag :: ArgPlaceHolder -> SFlags -> LFlags -> Description ->
415 (b -> Flag String) -> (Flag String -> b -> b) -> OptDescr b
416 reqArgFlag ad = reqArg ad (succeedReadE Flag) flagToList
417
418 usagePackages :: String -> String -> String
419 usagePackages name pname =
420 "Usage: " ++ pname ++ " " ++ name ++ " [FLAGS] [PACKAGE]\n\n"
421 ++ "Flags for " ++ name ++ ":"
422
423 usageFlags :: String -> String -> String
424 usageFlags name pname =
425 "Usage: " ++ pname ++ " " ++ name ++ " [FLAGS]\n\n"
426 ++ "Flags for " ++ name ++ ":"
427
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
428 -----------------------------------------------------------------------
429 -- Main
430 -----------------------------------------------------------------------
431
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
432 data GlobalFlags = GlobalFlags {
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
433 globalVersion :: Flag Bool
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
434 }
435
436 defaultGlobalFlags :: GlobalFlags
437 defaultGlobalFlags = GlobalFlags {
7b50682 @kolmodin Move portdir and overlay flags to respective command
kolmodin authored
438 globalVersion = Flag False
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
439 }
440
441 globalCommand :: CommandUI GlobalFlags
442 globalCommand = CommandUI {
443 commandName = "",
444 commandSynopsis = "",
445 commandDescription = Just $ \pname ->
446 "TODO: this is the commandDescription for globalCommand\n",
447 commandUsage = \_ -> [],
448 commandDefaultFlags = defaultGlobalFlags,
449 commandOptions = \showOrParseArgs ->
a08b0e7 @kolmodin Enable --verbose for 'hackport diff'
kolmodin authored
450 [ ]
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
451 }
452
453 mainWorker :: [String] -> IO ()
454 mainWorker args =
455 case commandsRun globalCommand commands args of
456 CommandHelp help -> printHelp help
457 CommandList opts -> printOptionsList opts
458 CommandErrors errs -> printErrors errs
459 CommandReadyToGo (globalflags, commandParse) -> do
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
460 case commandParse of
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
461 CommandHelp help -> printHelp help
462 CommandList opts -> printOptionsList opts
463 CommandErrors errs -> printErrors errs
464 CommandReadyToGo action -> catchEx (action globalflags) errorHandler
465 where
466 printHelp help = getProgName >>= putStr . help
467 printOptionsList = putStr . unlines
468 printErrors errs = do
469 putStr (concat (intersperse "\n" errs))
470 exitFailure
471 errorHandler :: HackPortError -> IO ()
472 errorHandler e = do
473 putStrLn (hackPortShowError e)
474 commands =
475 [ listCommand `commandAddAction` listAction
476 , makeEbuildCommand `commandAddAction` makeEbuildAction
477 , statusCommand `commandAddAction` statusAction
478 , diffCommand `commandAddAction` diffAction
479 , updateCommand `commandAddAction` updateAction
480 , mergeCommand `commandAddAction` mergeAction
481 ]
6ec3592 Hackport now uses Cabal-1.6
Ivan.Miljenovic@gmail.com authored
482
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
483 main :: IO ()
a1730ad @kolmodin Switch to using Cabal's CLI API
kolmodin authored
484 main = getArgs >>= mainWorker
Something went wrong with that request. Please try again.