cab 0.1.7 → 0.1.8
raw patch · 6 files changed
+120/−6 lines, 6 files
Files
- CmdDB.hs +17/−1
- Commands.hs +8/−1
- GenPaths.hs +84/−0
- Program.hs +6/−3
- Types.hs +2/−0
- cab.cabal +3/−1
CmdDB.hs view
@@ -108,6 +108,14 @@ , manual = Nothing } , CommandSpec {+ command = Upload+ , commandNames = ["upload", "up"]+ , document = "Uploading tar.gz to HackageDB"+ , routing = RouteCabal ["upload"]+ , switches = [(SwNoharm, Just "-c")]+ , manual = Nothing+ }+ , CommandSpec { command = Unpack , commandNames = ["unpack"] , document = "Untar a package in the current directory"@@ -148,6 +156,14 @@ , manual = Nothing } , CommandSpec {+ command = GenPaths+ , commandNames = ["genpaths", "genpath"]+ , document = "Generate Paths_<pkg>.hs"+ , routing = RouteFunc genpaths+ , switches = []+ , manual = Nothing+ }+ , CommandSpec { command = Search , commandNames = ["search"] , document = "Search available packages by package name"@@ -302,7 +318,7 @@ helpAndExit = do putStrLn $ programName ++ " " ++ " -- " ++ description putStrLn ""- putStrLn $ "Version: " ++ version+ putStrLn $ "Version: " ++ showVersion version putStrLn "Usage:" putStrLn $ "\t" ++ programName putStrLn $ "\t" ++ programName ++ " <command> [args...]"
Commands.hs view
@@ -1,5 +1,6 @@ module Commands (- deps, revdeps, installed, outdated, uninstall, search, env, check, add+ deps, revdeps, installed, outdated, uninstall, search, env+ , genpaths, check, add ) where import Control.Applicative hiding (many)@@ -7,6 +8,7 @@ import Data.Char import Data.List import Data.Maybe+import GenPaths import PkgDB import System.Exit import System.IO@@ -96,6 +98,11 @@ Just path -> do pkgConf <- getPackageConf path return $ "--package-conf=" ++ pkgConf ++ " "++----------------------------------------------------------------++genpaths :: FunctionCommand+genpaths _ _ _ = genPaths ----------------------------------------------------------------
+ GenPaths.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE OverloadedStrings, DoAndIfThenElse #-}++module GenPaths (genPaths) where++import Control.Applicative+import Control.Monad+import Data.Attoparsec.ByteString.Char8+import Data.Attoparsec.Enumerator+import Data.Enumerator (run, ($$))+import Data.Enumerator.Binary (enumFile)+import Data.List+import System.Directory+import System.IO++genPaths :: IO ()+genPaths = do+ mnv <- getNameVersion+ case mnv of+ Nothing -> hPutStrLn stderr "cabal file does not exist"+ Just (nm,ver) -> do+ let file = "Paths_" ++ nm ++ ".hs"+ exist <- doesFileExist file+ if exist then+ hPutStrLn stderr $ file ++ " already exists"+ else do+ putStrLn $ "Writing " ++ file ++ "..."+ writeFile file $+ "module Paths_" ++ nm ++ " where\n"+ ++ "import Data.Version\n"+ ++ "\n"+ ++ "version :: Version\n"+ ++ "version = Version [" ++ ver' ++ "] []\n"+ where+ ver' = map trans ver+ trans c+ | c == '.' = ','+ | otherwise = c++getNameVersion :: IO (Maybe (String,String))+getNameVersion = do+ mcfile <- getCabalFile+ case mcfile of+ Nothing -> return Nothing+ Just cfile -> do+ mn <- parseCabalFile cfile name+ mv <- parseCabalFile cfile version+ return $ do+ n <- mn+ v <- mv+ return (n,v)++getCabalFile :: IO (Maybe FilePath)+getCabalFile = do+ cnts <- (filter isCabal <$> getDirectoryContents ".")+ >>= filterM (\file -> doesFileExist file)+ case cnts of+ [] -> return Nothing+ cfile:_ -> return (Just cfile)+ where+ isCabal nm = ".cabal" `isSuffixOf` nm && length nm > 6++parseCabalFile :: FilePath -> Parser a -> IO (Maybe a)+parseCabalFile file parser = do+ res <- run (enumFile file $$ iterParser (findTarget parser))+ case res of+ Right x -> return x+ Left _ -> return Nothing++findTarget :: Parser a -> Parser (Maybe a)+findTarget parser = (Just <$> parser)+ <|> (anyChar >> findTarget parser)+ <|> (Nothing <$ endOfInput)++name :: Parser String+name = do+ stringCI "name:"+ many (char ' ')+ many1 (satisfy $ notInClass " ,\t\n")++version :: Parser String+version = do+ stringCI "version:"+ many (char ' ')+ many1 (satisfy $ inClass "0-9.")
Program.hs view
@@ -1,7 +1,10 @@-module Program where+module Program (+ version, showVersion+ , programName, description+ ) where -version :: String-version = "0.1.6"+import Paths_cab+import Data.Version programName :: String programName = "cab"
Types.hs view
@@ -67,11 +67,13 @@ | Clean | Outdated | Sdist+ | Upload | Unpack | Info | Deps | RevDeps | Check+ | GenPaths | Search | Env | Add
cab.cabal view
@@ -1,5 +1,5 @@ Name: cab-Version: 0.1.7+Version: 0.1.8 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3@@ -33,12 +33,14 @@ Other-Modules: CmdDB Commands Env+ GenPaths PkgDB Process Program Types Utils VerDB+ Paths_cab Source-Repository head Type: git Location: git://github.com/kazu-yamamoto/cab.git