Skip to content

HTTPS clone URL

Subversion checkout URL

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