1 % Copyright (C) 2008 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 \subsection{darcs changes}
20 {-# OPTIONS_GHC -cpp -fglasgow-exts #-}
21 {-# LANGUAGE CPP, PatternGuards #-}
23 -- The pragma above is only for pattern guards.
24 module Darcs.Commands.TransferMode ( transfer_mode ) where
26 import Prelude hiding ( catch )
27 import Control.Exception ( catch )
28 import System.IO ( stdout, hFlush )
30 import Darcs.Utils ( withCurrentDirectory, prettyException )
31 import Darcs.Commands ( DarcsCommand(..), nodefaults )
32 import Darcs.Arguments ( DarcsFlag, working_repo_dir )
33 import Darcs.Repository ( amInRepository )
34 import Darcs.Progress ( setProgressMode )
35 import Darcs.Global ( darcsdir )
37 import qualified Data.ByteString as B (hPut, readFile, length, ByteString)
40 \options{transfer_mode}
42 transfer_mode_description :: String
43 transfer_mode_description = "Allow access to files in repository."
45 \haskell{transfer_mode_help}
47 transfer_mode_help :: String
49 "Transfer-mode is used internally to grab file contents.\n"
51 transfer_mode :: DarcsCommand
52 transfer_mode = DarcsCommand {command_name = "transfer-mode",
53 command_help = transfer_mode_help,
54 command_description = transfer_mode_description,
55 command_extra_args = 0,
56 command_extra_arg_help = [],
57 command_get_arg_possibilities = return [],
58 command_command = transfer_mode_cmd,
59 command_prereq = amInRepository,
60 command_argdefaults = nodefaults,
61 command_advanced_options = [],
62 command_basic_options = [working_repo_dir]}
67 transfer_mode_cmd :: [DarcsFlag] -> [String] -> IO ()
68 transfer_mode_cmd _ _ = do setProgressMode False
69 putStrLn "Hello user, I am darcs transfer mode"
71 withCurrentDirectory darcsdir $ transfer
74 transfer = do 'g':'e':'t':' ':fn <- getLine
77 Right c -> do putStrLn $ "got " ++ fn
78 putStrLn $ show $ B.length c
81 Left e -> do putStrLn $ "error " ++ fn
86 readfile :: String -> IO (Either String B.ByteString)
87 readfile fn = (Right `fmap` B.readFile fn) `catch` (\e -> return $ Left (prettyException e))