File: InitCluster.hs

package info (click to toggle)
git-annex 10.20251029-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 75,300 kB
  • sloc: haskell: 91,492; javascript: 9,103; sh: 1,593; makefile: 216; perl: 137; ansic: 44
file content (50 lines) | stat: -rw-r--r-- 1,469 bytes parent folder | download | duplicates (3)
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
{- git-annex command
 -
 - Copyright 2024 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

{-# LANGUAGE OverloadedStrings #-}

module Command.InitCluster where

import Command
import qualified Annex
import Types.Cluster
import Logs.UUID
import Config
import Annex.UUID
import Git.Types
import Git.Remote (isLegalName)

import qualified Data.Map as M

cmd :: Command
cmd = command "initcluster" SectionSetup "initialize a new cluster"
	(paramPair paramName paramDesc) (withParams seek)

seek :: CmdParams -> CommandSeek
seek (clustername:desc:[]) = commandAction $
	start clustername (toUUIDDesc desc)
seek (clustername:[]) = commandAction $
	start clustername $ toUUIDDesc ("cluster " ++ clustername)
seek _ = giveup "Expected two parameters, name and description."

start :: RemoteName -> UUIDDesc -> CommandStart
start clustername desc = starting "initcluster" ai si $ do
	unless (isLegalName clustername) $
		giveup "That cluster name is not a valid git remote name."

	myclusters <- annexClusters <$> Annex.getGitConfig
	unless (M.member clustername myclusters) $ do
		cu <- fromMaybe (giveup "unable to generate a cluster UUID") 
			<$> genClusterUUID <$> liftIO genUUID
		setConfig (annexConfig ("cluster." <> encodeBS clustername))
			(fromUUID (fromClusterUUID cu))
		describeUUID (fromClusterUUID cu) desc

	next $ return True
  where
	ai = ActionItemOther (Just (UnquotedString clustername))
	si = SeekInput [clustername]