packages feed

cabalg 0.1.2 → 0.2.0

raw patch · 4 files changed

+70/−68 lines, 4 filesdep +filemanipdep +splitdep −optparse-applicativedep ~base

Dependencies added: filemanip, split

Dependencies removed: optparse-applicative

Dependency ranges changed: base

Files

cabalg.cabal view
@@ -1,5 +1,5 @@ name: cabalg-version: 0.1.2+version: 0.2.0 synopsis: alias for cabal install from given git repo license: MIT license-file: LICENSE@@ -12,36 +12,43 @@   .   I.e.   .-  @$> cabalg git:\/\/github.com\/biegunka\/biegunka.git --branch=develop+  @$> cabalg https:\/\/github.com\/biegunka\/biegunka   @   .   is just a shorthand for   .-  @$> create-dir \/temp\/directory-  $> git clone --branch develop --single-branch --depth=1 --quiet git:\/\/github.com\/biegunka\/biegunka.git \/temp\/directory-  $> change-dir \/temp\/directory-  $> cabal install-  $> change-dir-back-  $> remove-dir \/temp\/directory@+  @$> mktemp+  $> git clone --single-branch --depth=1 --quiet https:\/\/github.com\/biegunka\/biegunka \<tempdirname\>+  $> cabal install <tempdirname>/<cabalfilename>+  @   .-  If current directory is cabal-sandbox\'ed, 'cabalg' will attach the given repo to it.+  It also supports arbitrary git revisions mentioning like   .-  Also notice, that '--single-branch' flag  comes with git-1.7.10 (<https://lkml.org/lkml/2012/3/28/418>) and later, so you probably want to have it.+  @$> cabalg https:\/\/github.com\/biegunka\/biegunka\@beefboa+  @   .-  Hope it is windows-compatible.+  Necessary arguments could be passed to 'cabal install' with '--' delimiter like+  .+  @$> cabalg \<repo1\> ... \<repoN\> [\-\- \<cabal-install args\>]+  @+  .+  Please notice, that '--single-branch' flag  comes with git-1.7.10 (<https://lkml.org/lkml/2012/3/28/418>) and later, so you probably want to have it.+  .+  It's supposed to be Windows-compatible.  executable cabalg   main-is: Main.hs   hs-source-dirs: src-  other-modules: Git, Sandbox+  other-modules: Git    build-depends:-      base >= 4.6 && < 5+      base >= 4 && < 5     , process >= 1.2     , directory >= 1.2     , filepath >= 1.3-    , optparse-applicative >= 0.7.0.2     , temporary >= 1.1.2.4+    , filemanip >= 0.3.5.2+    , split >= 0.2.2    default-language: Haskell2010 
src/Git.hs view
@@ -1,19 +1,28 @@ {-# LANGUAGE ScopedTypeVariables #-} module Git where -import           Data.Maybe      (fromMaybe)+import           System.FilePath import           System.Process  (callProcess) --- | git clone+-- | git clone "master" branch clone :: String       -- | url-      -> Maybe String -- | branch name-      -> FilePath     -- | directory where repository will be clone to+      -> FilePath     -- | directory where repository will be cloned to       -> IO ()-clone url maybe_branch dir =-  callProcess "git" ["clone"-    , "--branch", fromMaybe "master" maybe_branch+clone url dir =+  callProcess "git"+    [ "clone"+    , "--branch", "master"     , "--single-branch"     , "--depth=1"     , "--quiet"     , url     , dir]++-- | git clone and checkout in particular revision (could be much slower than 'clone')+cloneRevision :: String   -- | url+              -> String   -- | revision+              -> FilePath -- | directory where repository will be cloned to+              -> IO ()+cloneRevision url revision dir = do+  callProcess "git" [ "clone", url, dir ]+  callProcess "git" [ "--git-dir", dir </> ".git", "checkout", revision, "--quiet" ]
src/Main.hs view
@@ -1,36 +1,42 @@-{-# LANGUAGE NoOverloadedStrings #-}-import           Options.Applicative-import           System.Directory    (getCurrentDirectory, getTemporaryDirectory, setCurrentDirectory)-import           System.IO.Temp      (withTempDirectory)-import           System.Process      (callProcess)+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}+import           Control.Applicative+import           Control.Arrow        (second)+import           Data.List.Split      (splitOn)+import           Data.Maybe           (catMaybes, fromMaybe, listToMaybe)+import           System.Directory     (getCurrentDirectory)+import           System.Environment+import           System.FilePath.Find+import           System.IO.Temp       (createTempDirectory)+import           System.Process       (callProcess)  import           Git-import           Sandbox   main :: IO ()-main = execParser opts >>= install-  where opts = info (helper <*> opt_parser) $ fullDesc <>-          progDesc "Install cabal package from git to cabal globally or in sandbox if it exists"+main = do+  (repos, args) <- reposAndArgs <$> getArgs+  cabalFiles :: [Maybe FilePath] <- mapM fetch repos+  cabalInstall (catMaybes cabalFiles) args  -data Configuration = Configuration { _git_url :: String, _branch :: Maybe String }+reposAndArgs :: [String] -> ([String], Maybe String)+reposAndArgs = second flags . span (/= "--")+ where+  flags [] = Nothing+  flags ["--"] = Nothing+  flags (_:xs) = Just $ unwords xs -install :: Configuration -> IO ()-install (Configuration { _git_url = url, _branch = branch }) = do-  back <- getCurrentDirectory-  temp_dir <- getTemporaryDirectory-  withTempDirectory temp_dir "cabalg_X" $ \dir -> do-    clone url branch dir-    sandbox_dir <- try_get_sandbox_dir back-    setCurrentDirectory dir-    case sandbox_dir of-      Just dir' -> link_to_sandbox dir'-      Nothing   -> return ()-    callProcess "cabal" ["install"]-  setCurrentDirectory back+fetch :: String -> IO (Maybe FilePath)+fetch urlAndMaybeRevision = do+  current_dir <- getCurrentDirectory+  let maybeRevision = listToMaybe . tail . splitOn "@" $ urlAndMaybeRevision+      url = head $ splitOn "@" urlAndMaybeRevision+  cabal_dir <- createTempDirectory current_dir ("cabalg_" ++ last (splitOn "/" url) ++ "X")+  case maybeRevision of+    Just revision -> cloneRevision url revision cabal_dir+    Nothing -> clone url cabal_dir+  listToMaybe <$> find always (extension ==? ".cabal") cabal_dir -opt_parser :: Parser Configuration-opt_parser = Configuration-  <$> argument str (metavar "URL")-  <*> optional (strOption (long "branch" <> short 'b'))+cabalInstall :: [String] -> Maybe String -> IO ()+cabalInstall cabalFiles args = callProcess "cabal" $ "install" : cabalFiles ++ words (fromMaybe "" args)+
− src/Sandbox.hs
@@ -1,20 +0,0 @@-module Sandbox-  ( try_get_sandbox_dir, link_to_sandbox-  ) where--import           System.Directory      (doesDirectoryExist)-import           System.FilePath.Posix ((</>))-import           System.Process        (callProcess)--try_get_sandbox_dir :: FilePath -> IO (Maybe FilePath)-try_get_sandbox_dir dir = do-  exist <- doesDirectoryExist sandbox_dir-  return $ if exist-    then Just sandbox_dir-    else Nothing- where-  sandbox_dir = dir </> ".cabal-sandbox"---link_to_sandbox :: FilePath -> IO ()-link_to_sandbox sandbox_dir = callProcess "cabal" ["sandbox", "init", "--sandbox", sandbox_dir]