summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-21 22:35:57 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-21 22:35:57 -0400
commit94a94c36cf0eba38b85b8fb6c360c14abae7031f (patch)
tree0e13740582f22f19aa5bd3c24fa53f3cc7c7ca47
parent75c8b6b9745ea8e64383e28d3f18b1609be00fa3 (diff)
downloaddebug-me-94a94c36cf0eba38b85b8fb6c360c14abae7031f.tar.gz
added debug-me --watch mode
This commit was sponsored by Ewen McNeill.
-rw-r--r--CmdLine.hs14
-rw-r--r--Log.hs3
-rw-r--r--Role/Watcher.hs25
-rw-r--r--debug-me.13
-rw-r--r--debug-me.cabal1
-rw-r--r--debug-me.hs8
6 files changed, 50 insertions, 4 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index 9d30eb3..663c63e 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -12,6 +12,7 @@ data Mode
= UserMode UserOpts
| DeveloperMode DeveloperOpts
| DownloadMode DownloadOpts
+ | WatchMode WatchOpts
| GraphvizMode GraphvizOpts
| ReplayMode ReplayOpts
| ServerMode ServerOpts
@@ -28,6 +29,10 @@ data DownloadOpts = DownloadOpts
{ downloadUrl :: String
}
+data WatchOpts = WatchOpts
+ { watchUrl :: String
+ }
+
data GraphvizOpts = GraphvizOpts
{ graphvizLogFile :: FilePath
, graphvizShowHashes :: Bool
@@ -50,6 +55,7 @@ parseMode = (UserMode <$> parseuser)
<|> (DeveloperMode <$> parsedeveloper)
<|> (ReplayMode <$> parsereplay)
<|> (DownloadMode <$> parsedownload)
+ <|> (WatchMode <$> parsewatch)
<|> (GraphvizMode <$> parsegraphviz)
<|> (ServerMode <$> parseserver)
where
@@ -76,9 +82,15 @@ parseMode = (UserMode <$> parseuser)
parsedownload = DownloadOpts
<$> option str
( long "download"
- <> metavar "logfile"
+ <> metavar "url"
<> help "download log file from server"
)
+ parsewatch = WatchOpts
+ <$> option str
+ ( long "watch"
+ <> metavar "url"
+ <> help "display a debug-me session non-interactively"
+ )
parseserver = ServerOpts
<$> option str
( long "server"
diff --git a/Log.hs b/Log.hs
index ec7078e..50c506d 100644
--- a/Log.hs
+++ b/Log.hs
@@ -68,6 +68,9 @@ type Logger = LogMessage -> IO ()
withLogger :: FilePath -> (Logger -> IO a) -> IO a
withLogger logfile a = withFile logfile WriteMode (a . mkLogger)
+nullLogger :: Logger
+nullLogger _ = return ()
+
mkLogger :: Handle -> Logger
mkLogger h a = do
l <- mkLog a <$> getPOSIXTime
diff --git a/Role/Watcher.hs b/Role/Watcher.hs
new file mode 100644
index 0000000..110c1ef
--- /dev/null
+++ b/Role/Watcher.hs
@@ -0,0 +1,25 @@
+module Role.Watcher where
+
+import Types
+import Log
+import Pty
+import CmdLine
+import WebSockets
+import SessionID
+
+import Control.Concurrent.STM
+import qualified Data.Text as T
+import Role.Developer (processSessionStart, getUserMessage, Output(..), emitOutput)
+
+run :: WatchOpts -> IO ()
+run os = runClientApp $ clientApp (ConnectMode (T.pack (watchUrl os))) watcher
+
+watcher :: TChan (Message Entered) -> TChan (Message Seen) -> SessionID -> IO ()
+watcher _ichan ochan sid = inRawMode $ do
+ st <- processSessionStart ochan nullLogger
+ go st
+ where
+ go st = do
+ (o, _msg) <- atomically $ getUserMessage ochan st
+ emitOutput o
+ go st
diff --git a/debug-me.1 b/debug-me.1
index 6f879a2..3c190e6 100644
--- a/debug-me.1
+++ b/debug-me.1
@@ -33,6 +33,9 @@ Replay a debug-me logfile.
Download a debug-me log file from the specified url. Note that if the
debug-me session is still in progress, this will continue downloading
until the session ends.
+.IP "--watch url"
+Connect to a debug-me session on the specified url and display what
+happens in the session. Keystrokes will not be sent to the session.
.IP "--graphviz logfile"
Uses graphviz to generate a visualization of a debug-me log file.
.IP "--show-hashes"
diff --git a/debug-me.cabal b/debug-me.cabal
index 9e1e108..cbec817 100644
--- a/debug-me.cabal
+++ b/debug-me.cabal
@@ -63,6 +63,7 @@ Executable debug-me
Role.Developer
Role.Downloader
Role.User
+ Role.Watcher
Session
Serialization
Server
diff --git a/debug-me.hs b/debug-me.hs
index ea2d6af..9319483 100644
--- a/debug-me.hs
+++ b/debug-me.hs
@@ -1,12 +1,13 @@
module Main where
import CmdLine
-import qualified Role.User
-import qualified Role.Developer
-import qualified Role.Downloader
import Graphviz
import Replay
import Server
+import qualified Role.User
+import qualified Role.Developer
+import qualified Role.Downloader
+import qualified Role.Watcher
import Network.Socket
import System.Exit
@@ -18,6 +19,7 @@ main = withSocketsDo $ do
UserMode o -> Role.User.run o >>= exitWith
DeveloperMode o -> Role.Developer.run o
DownloadMode o -> Role.Downloader.run o
+ WatchMode o -> Role.Watcher.run o
GraphvizMode o -> graphviz o
ReplayMode o -> replay o
ServerMode o -> server o