Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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