more generic showStart'

This commit is contained in:
Joey Hess 2016-07-20 14:03:54 -04:00
parent 4236dc83a8
commit 847944e6b1
Failed to extract signature
3 changed files with 26 additions and 6 deletions

View file

@ -42,7 +42,7 @@ seek o = do
start :: Key -> CommandStart start :: Key -> CommandStart
start key = do start key = do
showStart' "dropkey" key Nothing showStart' "dropkey" key key
next $ perform key next $ perform key
perform :: Key -> CommandPerform perform :: Key -> CommandPerform

View file

@ -23,7 +23,7 @@ seek = withWords start
start :: [String] -> CommandStart start :: [String] -> CommandStart
start (ks:us:vs:[]) = do start (ks:us:vs:[]) = do
showStart' "setpresentkey" k Nothing showStart' "setpresentkey" k k
next $ perform k (toUUID us) s next $ perform k (toUUID us) s
where where
k = fromMaybe (error "bad key") (file2key ks) k = fromMaybe (error "bad key") (file2key ks)

View file

@ -1,10 +1,12 @@
{- git-annex output messages {- git-annex output messages
- -
- Copyright 2010-2014 Joey Hess <id@joeyh.name> - Copyright 2010-2016 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module Messages ( module Messages (
showStart, showStart,
showStart', showStart',
@ -57,9 +59,27 @@ showStart :: String -> FilePath -> Annex ()
showStart command file = outputMessage (JSON.start command (Just file) Nothing) $ showStart command file = outputMessage (JSON.start command (Just file) Nothing) $
command ++ " " ++ file ++ " " command ++ " " ++ file ++ " "
showStart' :: String -> Key -> Maybe FilePath -> Annex () class ActionItem i where
showStart' command key afile = outputMessage (JSON.start command afile (Just key)) $ actionItemDesc :: i -> Key -> String
command ++ " " ++ fromMaybe (key2file key) afile ++ " " actionItemWorkTreeFile :: i -> Maybe FilePath
instance ActionItem FilePath where
actionItemDesc f _ = f
actionItemWorkTreeFile = Just
instance ActionItem AssociatedFile where
actionItemDesc (Just f) _ = f
actionItemDesc Nothing k = key2file k
actionItemWorkTreeFile = id
instance ActionItem Key where
actionItemDesc k _ = key2file k
actionItemWorkTreeFile _ = Nothing
showStart' :: ActionItem i => String -> Key -> i -> Annex ()
showStart' command key i =
outputMessage (JSON.start command (actionItemWorkTreeFile i) (Just key)) $
command ++ " " ++ actionItemDesc i key ++ " "
showNote :: String -> Annex () showNote :: String -> Annex ()
showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") " showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") "