aboutsummaryrefslogtreecommitdiff
path: root/Command/Init.hs
blob: e12c6700cf3ba1faeeb73ac5384a0ac861887303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{- git-annex command
 -
 - Copyright 2010 Joey Hess <id@joeyh.name>
 - Copyright 2022 Benjamin Barenblat <bbarenblat@gmail.com>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.Init where

import Command
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
	}

optParser :: CmdParamsDesc -> Parser InitOptions
optParser desc = InitOptions
	<$> (unwords <$> cmdParams desc)
	<*> optional (option (str >>= parseVersion)
		( long "version" <> metavar paramValue
		<> help "Override default annex.version"
		))

parseVersion :: MonadFail 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