Commits

Arjen Dijkstra committed 65848d0

working clone

  • Participants
  • Parent commits e5b8671
  • Branches rewrite

Comments (0)

Files changed (1)

 import System.Process (createProcess, waitForProcess, shell)
 import System.Exit (ExitCode(..))
 import System.IO (hPutStrLn, stderr, stdout)
-import System.Directory (doesDirectoryExist) --, getHomeDirectory)
+import System.Directory (doesDirectoryExist, getCurrentDirectory, setCurrentDirectory) --, getHomeDirectory)
 
 
 git :: String -> IO ()
     print ("git " ++ s)
     exit <- waitForProcess ph
     case exit of
-        ExitSuccess -> do hPutStrLn stdout $ "cloned " ++ s
+        ExitSuccess -> do hPutStrLn stdout $ s
         ExitFailure code -> do hPutStrLn stderr $ "git " ++ s ++ " script failed with exitcode: " ++ show code
 
 
             then (git . (++) "clone ") s
             else putStrLn "Directory exists"
 
-pull :: String -> IO ()
-pull = git . (++) "pull "
+pull :: String -> String -> IO ()
+pull link target = do
+        cwd <- getCurrentDirectory
+        setCurrentDirectory target
+        git "pull"
+        setCurrentDirectory cwd
+
+actions :: String -> String -> String -> IO ()
+actions "clone" = clone
+actions "update" = pull
 
 main ::  IO ()
 main = do
-    (link:path:_) <- getArgs
-    clone link path
+    (link:action:path:_) <- getArgs
+    actions action link path