From 847944e6b13515582d3d55cd0b394f008da2b3b7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Jul 2016 14:03:54 -0400 Subject: [PATCH] more generic showStart' --- Command/DropKey.hs | 2 +- Command/SetPresentKey.hs | 2 +- Messages.hs | 28 ++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Command/DropKey.hs b/Command/DropKey.hs index 15d5403a8f..9a9d513543 100644 --- a/Command/DropKey.hs +++ b/Command/DropKey.hs @@ -42,7 +42,7 @@ seek o = do start :: Key -> CommandStart start key = do - showStart' "dropkey" key Nothing + showStart' "dropkey" key key next $ perform key perform :: Key -> CommandPerform diff --git a/Command/SetPresentKey.hs b/Command/SetPresentKey.hs index 35ede9553a..73847792da 100644 --- a/Command/SetPresentKey.hs +++ b/Command/SetPresentKey.hs @@ -23,7 +23,7 @@ seek = withWords start start :: [String] -> CommandStart start (ks:us:vs:[]) = do - showStart' "setpresentkey" k Nothing + showStart' "setpresentkey" k k next $ perform k (toUUID us) s where k = fromMaybe (error "bad key") (file2key ks) diff --git a/Messages.hs b/Messages.hs index 57541cfc05..6851729aec 100644 --- a/Messages.hs +++ b/Messages.hs @@ -1,10 +1,12 @@ {- git-annex output messages - - - Copyright 2010-2014 Joey Hess + - Copyright 2010-2016 Joey Hess - - 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 ++ ") "