summaryrefslogtreecommitdiff
path: root/Messages.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-07-20 14:03:54 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-07-20 14:03:54 -0400
commite97cd57e1ac72d5a240852704ebaf92716fcad94 (patch)
tree35bd79976c25a06ba731a6da13de5db3315d73ff /Messages.hs
parent3b35227c3b739488c7093ab4856d23358bea3f9d (diff)
more generic showStart'
Diffstat (limited to 'Messages.hs')
-rw-r--r--Messages.hs28
1 files changed, 24 insertions, 4 deletions
diff --git a/Messages.hs b/Messages.hs
index 57541cfc0..6851729ae 100644
--- a/Messages.hs
+++ b/Messages.hs
@@ -1,10 +1,12 @@
{- 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.
-}
+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
+
module Messages (
showStart,
showStart',
@@ -57,9 +59,27 @@ showStart :: String -> FilePath -> Annex ()
showStart command file = outputMessage (JSON.start command (Just file) Nothing) $
command ++ " " ++ file ++ " "
-showStart' :: String -> Key -> Maybe FilePath -> Annex ()
-showStart' command key afile = outputMessage (JSON.start command afile (Just key)) $
- command ++ " " ++ fromMaybe (key2file key) afile ++ " "
+class ActionItem i where
+ actionItemDesc :: i -> Key -> String
+ 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 s = outputMessage (JSON.note s) $ "(" ++ s ++ ") "