1. Stefan Saasen
  2. spy

Commits

Stefan Saasen  committed 0bb2d18

Re introduce the 'flag' field to the JSON output

  • Participants
  • Parent commits 52bebd7
  • Branches master

Comments (0)

Files changed (2)

File README.md

View file
  • Ignore whitespace
 The default format is the full path to the modified file followed by a newline. To make it easier to parse the output, the `--format=json` changes the output to be printed formatted as a JSON object (again followed by a newline).
 
     $> spy watch --format=json .
-    {"path":"/path/to/modified.file","time":"2012-12-20 11:16:03.363614 UTC"}
+    {"path":"/path/to/modified.file","flag":"Added","time":"2012-12-20 11:26:56.859456 UTC"}
+
+Flag is one of "Added", "Modified", "Removed".
+
 
 For directories the following options apply:
 

File src/Spy/Watcher.hs

View file
  • Ignore whitespace
 outputHandler :: Format -> Printer
 outputHandler Json  = \event -> encode $ makeObj [
     ("path", showJSON $ eventPath event),
+    ("flag", showJSON $ eventType event),
     ("time", showJSON . show $ eventTime event)]
 outputHandler Plain = eventPath
 
 eventPath (Modified fp _) = encodeString fp
 eventPath (Removed fp _) = encodeString fp
 
+eventType :: Event -> FilePath
+eventType (Added _ _) = "Added"
+eventType (Modified _ _) = "Modified"
+eventType (Removed _ _) = "Removed"
+
 matchesFile :: FilePath -> GlobPattern -> Bool
 matchesFile path glob' = takeFileName path ~~ glob'