aboutsummaryrefslogtreecommitdiff
path: root/Messages.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-07-20 15:22:55 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-07-20 15:23:43 -0400
commit258a3356e6461e0164441bb3a3e202cb9ef889e6 (patch)
treef198f34aaedeffb1af624f918a214527b066175a /Messages.hs
parente97cd57e1ac72d5a240852704ebaf92716fcad94 (diff)
--branch, stage 2
Show branch:file that is being operated on. I had to make ActionItem a type and not a type class because withKeyOptions' passed two different types of values when using the type class, and I could not get the type checker to accept that.
Diffstat (limited to 'Messages.hs')
-rw-r--r--Messages.hs52
1 files changed, 34 insertions, 18 deletions
diff --git a/Messages.hs b/Messages.hs
index 6851729ae..050dff950 100644
--- a/Messages.hs
+++ b/Messages.hs
@@ -9,6 +9,8 @@
module Messages (
showStart,
+ ActionItem,
+ mkActionItem,
showStart',
showNote,
showAction,
@@ -50,36 +52,50 @@ import System.Log.Handler.Simple
import Common
import Types
import Types.Messages
+import Git.FilePath
import Messages.Internal
import qualified Messages.JSON as JSON
import Types.Key
import qualified Annex
showStart :: String -> FilePath -> Annex ()
-showStart command file = outputMessage (JSON.start command (Just file) Nothing) $
+showStart command file = outputMessage json $
command ++ " " ++ file ++ " "
+ where
+ json = JSON.start command (Just file) Nothing
+
+data ActionItem
+ = ActionItemAssociatedFile AssociatedFile
+ | ActionItemKey
+ | ActionItemBranchFilePath BranchFilePath
+
+class MkActionItem t where
+ mkActionItem :: t -> ActionItem
-class ActionItem i where
- actionItemDesc :: i -> Key -> String
- actionItemWorkTreeFile :: i -> Maybe FilePath
+instance MkActionItem AssociatedFile where
+ mkActionItem = ActionItemAssociatedFile
-instance ActionItem FilePath where
- actionItemDesc f _ = f
- actionItemWorkTreeFile = Just
+instance MkActionItem Key where
+ mkActionItem _ = ActionItemKey
-instance ActionItem AssociatedFile where
- actionItemDesc (Just f) _ = f
- actionItemDesc Nothing k = key2file k
- actionItemWorkTreeFile = id
+instance MkActionItem BranchFilePath where
+ mkActionItem = ActionItemBranchFilePath
-instance ActionItem Key where
- actionItemDesc k _ = key2file k
- actionItemWorkTreeFile _ = Nothing
+actionItemDesc :: ActionItem -> Key -> String
+actionItemDesc (ActionItemAssociatedFile (Just f)) _ = f
+actionItemDesc (ActionItemAssociatedFile Nothing) k = key2file k
+actionItemDesc ActionItemKey k = key2file k
+actionItemDesc (ActionItemBranchFilePath bfp) _ = descBranchFilePath bfp
-showStart' :: ActionItem i => String -> Key -> i -> Annex ()
-showStart' command key i =
- outputMessage (JSON.start command (actionItemWorkTreeFile i) (Just key)) $
- command ++ " " ++ actionItemDesc i key ++ " "
+actionItemWorkTreeFile :: ActionItem -> Maybe FilePath
+actionItemWorkTreeFile (ActionItemAssociatedFile af) = af
+actionItemWorkTreeFile _ = Nothing
+
+showStart' :: String -> Key -> ActionItem -> Annex ()
+showStart' command key i = outputMessage json $
+ command ++ " " ++ actionItemDesc i key ++ " "
+ where
+ json = JSON.start command (actionItemWorkTreeFile i) (Just key)
showNote :: String -> Annex ()
showNote s = outputMessage (JSON.note s) $ "(" ++ s ++ ") "