2011-03-29 03:22:31 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2011,2013 Joey Hess <id@joeyh.name>
|
2011-03-29 03:22:31 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.InitRemote where
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
|
|
|
import Command
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.SpecialRemote
|
2011-03-29 03:22:31 +00:00
|
|
|
import qualified Remote
|
2011-10-15 20:21:08 +00:00
|
|
|
import qualified Logs.Remote
|
2011-06-02 01:56:04 +00:00
|
|
|
import qualified Types.Remote as R
|
2012-06-07 15:16:48 +00:00
|
|
|
import Logs.UUID
|
2017-08-17 16:26:14 +00:00
|
|
|
import Types.GitConfig
|
2011-03-29 03:22:31 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd = command "initremote" SectionSetup
|
|
|
|
"creates a special (non-git) remote"
|
2011-10-29 19:19:05 +00:00
|
|
|
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue)
|
2015-07-08 19:08:02 +00:00
|
|
|
(withParams seek)
|
2011-03-29 03:22:31 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withWords (commandAction . start)
|
2011-03-29 03:22:31 +00:00
|
|
|
|
2011-09-15 20:50:49 +00:00
|
|
|
start :: [String] -> CommandStart
|
2016-11-16 01:29:54 +00:00
|
|
|
start [] = giveup "Specify a name for the remote."
|
2013-04-26 22:22:44 +00:00
|
|
|
start (name:ws) = ifM (isJust <$> findExisting name)
|
2016-11-16 01:29:54 +00:00
|
|
|
( giveup $ "There is already a special remote named \"" ++ name ++
|
2013-04-26 22:22:44 +00:00
|
|
|
"\". (Use enableremote to enable an existing special remote.)"
|
|
|
|
, do
|
2014-10-15 19:47:49 +00:00
|
|
|
ifM (isJust <$> Remote.byNameOnly name)
|
2016-11-16 01:29:54 +00:00
|
|
|
( giveup $ "There is already a remote named \"" ++ name ++ "\""
|
2014-10-15 19:47:49 +00:00
|
|
|
, do
|
|
|
|
let c = newConfig name
|
2016-11-16 01:29:54 +00:00
|
|
|
t <- either giveup return (findType config)
|
2013-04-26 22:22:44 +00:00
|
|
|
|
2017-11-28 18:40:26 +00:00
|
|
|
showStart' "initremote" (Just name)
|
2014-10-15 19:47:49 +00:00
|
|
|
next $ perform t name $ M.union config c
|
|
|
|
)
|
2013-04-26 22:22:44 +00:00
|
|
|
)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
config = Logs.Remote.keyValToConfig ws
|
2011-03-29 03:22:31 +00:00
|
|
|
|
2013-09-07 22:38:00 +00:00
|
|
|
perform :: RemoteType -> String -> R.RemoteConfig -> CommandPerform
|
|
|
|
perform t name c = do
|
2017-08-17 16:26:14 +00:00
|
|
|
dummycfg <- liftIO dummyRemoteGitConfig
|
|
|
|
(c', u) <- R.setup t R.Init cu Nothing c dummycfg
|
2012-07-28 01:05:27 +00:00
|
|
|
next $ cleanup u name c'
|
2017-02-07 19:10:41 +00:00
|
|
|
where
|
|
|
|
cu = case M.lookup "uuid" c of
|
|
|
|
Just s
|
|
|
|
| isUUID s -> Just (toUUID s)
|
|
|
|
| otherwise -> giveup "invalid uuid"
|
|
|
|
Nothing -> Nothing
|
2011-03-29 18:55:59 +00:00
|
|
|
|
2012-07-28 01:05:27 +00:00
|
|
|
cleanup :: UUID -> String -> R.RemoteConfig -> CommandCleanup
|
|
|
|
cleanup u name c = do
|
|
|
|
describeUUID u name
|
2011-10-15 20:21:08 +00:00
|
|
|
Logs.Remote.configSet u c
|
2012-12-13 04:45:27 +00:00
|
|
|
return True
|