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