summaryrefslogtreecommitdiff
path: root/Command/CheckPresentKey.hs
blob: e8dabe18f4c72b93ee1c75f6b160ea05ee838e6f (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
{- git-annex command
 -
 - Copyright 2015 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.CheckPresentKey where

import Command
import qualified Remote
import Annex
import Types.Messages

cmd :: Command
cmd = noCommit $ 
	command "checkpresentkey" SectionPlumbing
		"check if key is present in remote"
		(paramPair paramKey paramRemote)
		(withParams seek)

seek :: CmdParams -> CommandSeek
seek = withWords start

start :: [String] -> CommandStart
start (ks:rn:[]) = do
	setOutput QuietOutput
	maybe (error "Unknown remote") (go <=< flip Remote.hasKey k)
		=<< Remote.byNameWithUUID (Just rn)
  where
	k = fromMaybe (error "bad key") (file2key ks)
	go (Right True) = liftIO exitSuccess
	go (Right False) = liftIO exitFailure
	go (Left e) = liftIO $ do
		hPutStrLn stderr e
		exitWith $ ExitFailure 100
start _ = error "Wrong number of parameters"