Commit 7216fb76 authored by bjorn@bringert.net's avatar bjorn@bringert.net
Browse files

Parse command line arguments as either Dependency or PackageIDentifier, to...

Parse command line arguments as either Dependency or PackageIDentifier, to allow e.g. 'cabal install binary-0.3'.
parent 9e90e150
......@@ -17,7 +17,6 @@ module Hackage.Setup
) where
import Control.Monad (when)
import Distribution.ParseUtils (parseDependency)
import Distribution.Compiler (CompilerFlavor(..))
import Distribution.Simple.InstallDirs (InstallDirTemplates(..), toPathTemplate)
import Distribution.Verbosity
......@@ -28,7 +27,7 @@ import System.Environment (getProgName)
import Hackage.Types (Action (..), Option(..), ConfigFlags(..)
, UnresolvedDependency (..))
import Hackage.Utils (readPToMaybe)
import Hackage.Utils (readPToMaybe, parseDependencyOrPackageId)
globalOptions :: [OptDescr Option]
......@@ -192,7 +191,7 @@ parsePackageArgs _ args
= return (globalArgs,parsePkgArgs pkgs)
where (globalArgs,pkgs) = break (not.(==)'-'.head) args
parseDep dep
= case readPToMaybe parseDependency dep of
= case readPToMaybe parseDependencyOrPackageId dep of
Nothing -> error ("Failed to parse package dependency: " ++ show dep)
Just x -> x
parsePkgArgs [] = []
......
module Hackage.Utils where
import Distribution.Compat.ReadP (ReadP, readP_to_S, pfail, get, look, choice)
import Distribution.Compat.ReadP (ReadP, readP_to_S, pfail, get, look, choice, (+++))
import Distribution.Package (PackageIdentifier(..), parsePackageId)
import Distribution.ParseUtils
import Distribution.Version
import Control.Exception
import Control.Monad (foldM, guard)
import Control.Monad (foldM, liftM, guard)
import Data.Char (isSpace, toLower)
import Data.List (intersperse)
import Data.Maybe (listToMaybe)
......@@ -85,3 +86,7 @@ stringNoCase this = look >>= scan this
showDependencies :: [Dependency] -> String
showDependencies = concat . intersperse ", " . map (show . showDependency)
parseDependencyOrPackageId :: ReadP r Dependency
parseDependencyOrPackageId = parseDependency +++ liftM pkgToDep parsePackageId
where pkgToDep p = Dependency (pkgName p) (ThisVersion (pkgVersion p))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment