Skip to content
Browse files

Add --portdir flag

  • Loading branch information...
1 parent 0bdf8c3 commit 16c6784eabc9218e1aec69dcc4a411789e735d79 @kolmodin kolmodin committed Aug 22, 2007
Showing with 28 additions and 8 deletions.
  1. +6 −1 Action.hs
  2. +17 −6 Bash.hs
  3. +4 −0 Config.hs
  4. +1 −1 Status.hs
View
7 Action.hs
@@ -59,7 +59,11 @@ getCfg = gets config
setOverlayPath :: Maybe String -> HPAction ()
setOverlayPath mt = modify $ \hps ->
- hps { config = (config hps) { overlayPath = mt } }
+ hps { config = (config hps) { overlayPath = mt } }
+
+setPortagePath :: Maybe String -> HPAction ()
+setPortagePath mt = modify $ \hps ->
+ hps { config = (config hps) { portagePath = mt } }
lessIndent :: HPAction ()
lessIndent = modify $ \s -> s { indention = indention s - 1 }
@@ -101,6 +105,7 @@ loadConfig = do
optionToConfig :: Config -> HackPortOptions -> HPAction Config
optionToConfig cfg opt = case opt of
OverlayPath str -> return cfg { overlayPath = Just str }
+ PortagePath str -> return cfg { portagePath = Just str }
Category str -> return cfg { defaultPortageCategory = str }
Server str -> case parseURI str of
Nothing -> throwError (InvalidServer str)
View
23 Bash.hs
@@ -8,6 +8,7 @@ import System.IO
import System.Exit
import Action
+import Config
import Error
import CacheFile
@@ -39,12 +40,22 @@ getOverlay = do
getOverlays :: HPAction [String]
getOverlays = runBash "source /etc/make.conf;echo -n $PORTDIR_OVERLAY" >>= (return.words)
-getPortDir :: HPAction String
-getPortDir = do
- dir <- runBash "source /etc/make.conf;echo -n $PORTDIR"
- case dir of
- "" -> return "/usr/portage"
- _ -> return dir
+getSystemPortdir :: HPAction String
+getSystemPortdir = do
+ dir <- runBash "source /etc/make.conf;echo -n $PORTDIR"
+ case dir of
+ "" -> return "/usr/portage"
+ _ -> return dir
+
+getPortdir :: HPAction String
+getPortdir = do
+ cfg <- getCfg
+ case portagePath cfg of
+ Just dir -> return dir
+ Nothing -> do
+ sys <- getSystemPortdir
+ setPortagePath (Just sys)
+ return sys
runBash ::
String -> -- ^ The command line
View
4 Config.hs
@@ -11,6 +11,7 @@ import MaybeRead
data HackPortOptions
= OverlayPath String
+ | PortagePath String
| Category String
| Server String
| TempDir String
@@ -36,6 +37,7 @@ data DiffMode
data Config = Config
{ overlayPath ::Maybe String
+ , portagePath ::Maybe String
, defaultPortageCategory::String
, server ::URI
, tmp ::String
@@ -53,6 +55,7 @@ packageRegex = mkRegex "^(.*?)-([0-9].*)$"
defaultConfig :: Config
defaultConfig = Config
{ overlayPath = Nothing
+ , portagePath = Nothing
, defaultPortageCategory = "dev-haskell"
, server = URI "http:" (Just $ URIAuth "" "hackage.haskell.org" "") "/packages/archive/" "" ""
, tmp = "/tmp"
@@ -63,6 +66,7 @@ defaultConfig = Config
hackageOptions :: [OptDescr HackPortOptions]
hackageOptions =
[Option ['o'] ["overlay-path"] (ReqArg OverlayPath "PATH") "The overlay tree to merge to"
+ ,Option ['p'] ["portdir"] (ReqArg PortagePath "PATH") "The portage directory to use"
,Option ['c'] ["portage-category"] (ReqArg Category "CATEGORY") "The cateory the program belongs to"
,Option ['s'] ["server"] (ReqArg Server "URL") "The Hackage server to query"
,Option ['t'] ["temp-dir"] (ReqArg TempDir "PATH") "A temp directory where tarballs can be stored"
View
2 Status.hs
@@ -22,7 +22,7 @@ import qualified Data.Traversable as T
status :: HPAction ()
status = do
- portdir <- getPortDir
+ portdir <- getPortdir
overlayPath <- getOverlayPath
overlay <- liftIO $ readPortageTree overlayPath
portage <- liftIO $ readPortagePackages portdir (Map.keys overlay)

0 comments on commit 16c6784

Please sign in to comment.
Something went wrong with that request. Please try again.