summaryrefslogtreecommitdiff
path: root/Command/Init.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Command/Init.hs')
-rw-r--r--Command/Init.hs43
1 files changed, 31 insertions, 12 deletions
diff --git a/Command/Init.hs b/Command/Init.hs
index d969669f8..94d8168a6 100644
--- a/Command/Init.hs
+++ b/Command/Init.hs
@@ -10,25 +10,44 @@ module Command.Init where
import Common.Annex
import Command
import Annex.Init
+import Annex.Version
import qualified Annex.SpecialRemote
cmd :: Command
cmd = dontCheck repoExists $
command "init" SectionSetup "initialize git-annex"
- paramDesc (withParams seek)
+ paramDesc (seek <$$> optParser)
-seek :: CmdParams -> CommandSeek
-seek = withWords start
+data InitOptions = InitOptions
+ { initDesc :: String
+ , initVersion :: Maybe Version
+ }
-start :: [String] -> CommandStart
-start ws = do
- showStart "init" description
- next $ perform description
- where
- description = unwords ws
+optParser :: CmdParamsDesc -> Parser InitOptions
+optParser desc = InitOptions
+ <$> (unwords <$> cmdParams desc)
+ <*> optional (option (str >>= parseVersion)
+ ( long "version" <> metavar paramValue
+ <> help "Override default annex.version"
+ ))
-perform :: String -> CommandPerform
-perform description = do
- initialize $ if null description then Nothing else Just description
+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" (initDesc os)
+ next $ perform os
+
+perform :: InitOptions -> CommandPerform
+perform os = do
+ initialize
+ (if null (initDesc os) then Nothing else Just (initDesc os))
+ (initVersion os)
Annex.SpecialRemote.autoEnable
next $ return True