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