packages feed

cabalg (empty) → 0.1.0

raw patch · 6 files changed

+107/−0 lines, 6 filesdep +basedep +directorydep +filepathsetup-changed

Dependencies added: base, directory, filepath, optparse-applicative, process, temporary

Files

+ LICENSE view
@@ -0,0 +1,7 @@+Copyright (C) 2013 Dmitry Malikov++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabalg.cabal view
@@ -0,0 +1,23 @@+name:                cabalg+version:             0.1.0+synopsis:            alias for cabal install from given git repo+license:             MIT+license-file:        LICENSE+author:              Dmitry Malikov+maintainer:          malikov.d.y@gmail.com+build-type:          Simple+cabal-version:       >=1.10++executable cabalg+  main-is:             Main.hs+  hs-source-dirs:      src+  other-modules:       Git, Sandbox++  build-depends:       base                 >= 4.6 && < 5,+                       process              >= 1.2,+                       directory            >= 1.2,+                       filepath             >= 1.3,+                       optparse-applicative >= 0.7.0.2,+                       temporary            >= 1.1.2.4++  default-language:    Haskell2010
+ src/Git.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE ScopedTypeVariables #-}+module Git where++import           Data.Maybe      (fromMaybe)+import           System.Process  (callProcess)++-- | git clone+clone :: String       -- | url+      -> Maybe String -- | branch name+      -> FilePath     -- | directory where repository will be clone to+      -> IO ()+clone url maybe_branch dir =+  callProcess "git" ["clone"+    , "--branch", fromMaybe "master" maybe_branch+    , "--single-branch"+    , "--depth=1"+    , "--quiet"+    , url+    , dir]
+ src/Main.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE NoOverloadedStrings #-}+import           Options.Applicative+import           System.Directory    (getCurrentDirectory, getTemporaryDirectory, setCurrentDirectory)+import           System.IO.Temp      (withTempDirectory)+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"+++data Configuration = Configuration { _git_url :: String, _branch :: Maybe String }++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++opt_parser :: Parser Configuration+opt_parser = Configuration+  <$> argument str (metavar "URL")+  <*> optional (strOption (long "branch" <> short 'b'))
+ src/Sandbox.hs view
@@ -0,0 +1,20 @@+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]