git-annex/Command/Init.hs

53 lines
1.3 KiB
Haskell
Raw Normal View History

{- git-annex command
-
- Copyright 2010 Joey Hess <id@joeyh.name>
-
- 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
import Annex.Version
import qualified Annex.SpecialRemote
cmd :: Command
cmd = dontCheck repoExists $
command "init" SectionSetup "initialize git-annex"
paramDesc (seek <$$> optParser)
data InitOptions = InitOptions
{ initDesc :: String
, initVersion :: Maybe Version
}
2010-11-11 22:54:52 +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"
))
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
showStart' "init" (Just $ initDesc os)
next $ perform os
perform :: InitOptions -> CommandPerform
perform os = do
initialize (AutoInit False)
(if null (initDesc os) then Nothing else Just (initDesc os))
(initVersion os)
Annex.SpecialRemote.autoEnable
next $ return True