Skip to content

Commit

Permalink
Merge pull request #25 from RyanGlScott/master
Browse files Browse the repository at this point in the history
cab get and cab outdated --future
  • Loading branch information
kazu-yamamoto committed Jul 25, 2014
2 parents 4091426 + f7a1ab6 commit d9fbf05
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
12 changes: 11 additions & 1 deletion .gitignore
@@ -1 +1,11 @@
dist/
dist
cabal-dev
*.o
*.hi
*.chi
*.chs.h
.virtualenv
.hsenv
.cabal-sandbox/
cabal.sandbox.config
cabal.config
14 changes: 12 additions & 2 deletions Distribution/Cab/Commands.hs
Expand Up @@ -40,6 +40,7 @@ data Option = OptNoharm
| OptJobs String
| OptImport String
| OptStatic
| OptFuture
deriving (Eq,Show)

----------------------------------------------------------------
Expand Down Expand Up @@ -77,8 +78,17 @@ outdated _ opts _ = do
verDB <- toMap <$> getVerDB InstalledOnly
forM_ pkgs $ \p -> case M.lookup (nameOfPkgInfo p) verDB of
Nothing -> return ()
Just ver -> when (verOfPkgInfo p /= ver) $
putStrLn $ fullNameOfPkgInfo p ++ " /= " ++ verToString ver
Just ver -> do
let comp = verOfPkgInfo p `compare` ver
when (dated comp) $
putStrLn $ fullNameOfPkgInfo p ++ (showIneq comp) ++ verToString ver
where
dated LT = True
dated GT = OptFuture `elem` opts
dated EQ = False
showIneq LT = " < "
showIneq GT = " > "
showIneq EQ = error "Packages have equal versions"

getDB :: [Option] -> IO PkgDB
getDB opts
Expand Down
2 changes: 1 addition & 1 deletion Distribution/Cab/Version.hs
Expand Up @@ -10,7 +10,7 @@ import Distribution.Cab.Utils
import Distribution.Version (Version(..))

-- | Package version.
newtype Ver = Ver [Int] deriving (Eq,Show)
newtype Ver = Ver [Int] deriving (Eq,Ord,Read,Show)

-- | Creating 'Ver'.
--
Expand Down
4 changes: 3 additions & 1 deletion cab.cabal
Expand Up @@ -45,6 +45,8 @@ Executable cab
Default-Language: Haskell2010
Main-Is: Main.hs
GHC-Options: -Wall
if os(windows)
GHC-Options: -threaded
HS-Source-Dirs: src
Build-Depends: base >= 4.0 && < 5
, cab
Expand All @@ -56,7 +58,7 @@ Executable cab
, containers
, directory
, filepath
, process
, process >= 1.2.0.0
Other-Modules: Commands
Doc
Help
Expand Down
8 changes: 5 additions & 3 deletions src/Commands.hs
Expand Up @@ -89,7 +89,9 @@ commandDB help = [
, commandNames = ["outdated"]
, document = "Display outdated packages"
, routing = RouteFunc outdated
, switches = [(SwAll, None)]
, switches = [(SwAll, None)
,(SwFuture, Solo "--future")
]
, manual = Nothing
}
, CommandSpec {
Expand Down Expand Up @@ -118,9 +120,9 @@ commandDB help = [
}
, CommandSpec {
command = Unpack
, commandNames = ["unpack"]
, commandNames = ["get", "unpack"]
, document = "Untar a package in the current directory"
, routing = RouteCabal ["unpack"]
, routing = RouteCabal ["get"]
, switches = []
, manual = Just "<package> [<ver>]"
}
Expand Down
5 changes: 4 additions & 1 deletion src/Options.hs
Expand Up @@ -48,10 +48,13 @@ getOptDB = [
, Option ['s'] ["static"]
(NoArg OptStatic)
"Create static libraries only"
, Option ['u'] ["future"]
(NoArg OptFuture)
"Show packages with versions ahead of Hackage"
, Option ['h'] ["help"]
(NoArg OptHelp)
"Show help message"
]

optionDB :: OptionDB
optionDB = zip [SwNoharm,SwRecursive,SwAll,SwInfo,SwFlag,SwTest,SwBench,SwDepsOnly,SwLibProfile,SwExecProfile,SwJobs,SwImport,SwStatic] getOptDB
optionDB = zip [SwNoharm,SwRecursive,SwAll,SwInfo,SwFlag,SwTest,SwBench,SwDepsOnly,SwLibProfile,SwExecProfile,SwJobs,SwImport,SwStatic,SwFuture] getOptDB
6 changes: 3 additions & 3 deletions src/Run.hs
@@ -1,9 +1,8 @@
module Run (run, toSwitch) where

import Control.Monad (void)
import Data.List (intercalate)
import Distribution.Cab
import System.Cmd (system)
import System.Process (callCommand)

import Types

Expand All @@ -23,6 +22,7 @@ toSwitch OptExecProfile = SwExecProfile
toSwitch (OptJobs _) = SwJobs
toSwitch (OptImport _) = SwImport
toSwitch OptStatic = SwStatic
toSwitch OptFuture = SwFuture
toSwitch _ = error "toSwitch"

----------------------------------------------------------------
Expand Down Expand Up @@ -55,7 +55,7 @@ run cmdspec params opts = case routing cmdspec of
options = optionsToString opts sws

callProcess :: String -> [String] -> [Arg] -> [String] -> IO ()
callProcess pro args0 args1 options = void . system $ script
callProcess pro args0 args1 options = callCommand script
where
script = intercalate " " $ pro : args0 ++ cat args1 ++ options
cat [pkg,ver] = [pkg ++ "-" ++ ver]
Expand Down
1 change: 1 addition & 0 deletions src/Types.hs
Expand Up @@ -22,6 +22,7 @@ data Switch = SwNoharm
| SwJobs
| SwImport
| SwStatic
| SwFuture
deriving (Eq,Show)

----------------------------------------------------------------
Expand Down

0 comments on commit d9fbf05

Please sign in to comment.