2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010 Joey Hess <id@joeyh.name>
|
2010-11-02 23:04:24 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Init where
|
|
|
|
|
|
|
|
import Command
|
2014-01-26 20:36:31 +00:00
|
|
|
import Annex.Init
|
2015-12-15 21:17:13 +00:00
|
|
|
import Annex.Version
|
2015-09-14 18:49:48 +00:00
|
|
|
import qualified Annex.SpecialRemote
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = dontCheck repoExists $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "init" SectionSetup "initialize git-annex"
|
2015-12-15 21:17:13 +00:00
|
|
|
paramDesc (seek <$$> optParser)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2015-12-15 21:17:13 +00:00
|
|
|
data InitOptions = InitOptions
|
|
|
|
{ initDesc :: String
|
|
|
|
, initVersion :: Maybe Version
|
|
|
|
}
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2015-12-15 21:17:13 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser InitOptions
|
|
|
|
optParser desc = InitOptions
|
|
|
|
<$> (unwords <$> cmdParams desc)
|
|
|
|
<*> optional (option (str >>= parseVersion)
|
|
|
|
( long "version" <> metavar paramValue
|
|
|
|
<> help "Override default annex.version"
|
|
|
|
))
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2015-12-15 21:17:13 +00:00
|
|
|
parseVersion :: Monad m => String -> m Version
|
|
|
|
parseVersion v
|
|
|
|
| v `elem` supportedVersions = return v
|
|
|
|
| otherwise = fail $ v ++ " is not a currently supported repository version"
|
|
|
|
|
|
|
|
seek :: InitOptions -> CommandSeek
|
|
|
|
seek = commandAction . start
|
|
|
|
|
|
|
|
start :: InitOptions -> CommandStart
|
|
|
|
start os = do
|
2017-11-28 18:40:26 +00:00
|
|
|
showStart' "init" (Just $ initDesc os)
|
2015-12-15 21:17:13 +00:00
|
|
|
next $ perform os
|
|
|
|
|
|
|
|
perform :: InitOptions -> CommandPerform
|
|
|
|
perform os = do
|
2017-12-13 18:34:32 +00:00
|
|
|
initialize (AutoInit False)
|
2015-12-15 21:17:13 +00:00
|
|
|
(if null (initDesc os) then Nothing else Just (initDesc os))
|
|
|
|
(initVersion os)
|
2015-09-14 18:49:48 +00:00
|
|
|
Annex.SpecialRemote.autoEnable
|
2011-06-22 20:03:26 +00:00
|
|
|
next $ return True
|