Skip to content

Commit 428aa10

Browse files
committed
Add options parser
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent 4c49393 commit 428aa10

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

hydra-node/exe/visualize-logs/Main.hs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import Hydra.HeadLogic (Effect (..), Input (..), Outcome (..), StateChanged (..)
1717
import Hydra.Logging (Envelope (..))
1818
import Hydra.Logging.Messages (HydraLog (..))
1919
import Hydra.Node (HydraNodeLog (..))
20+
import Options.Applicative
2021

2122
data InfoLine = InfoLine {toplabel :: LogType, details :: Text} deriving (Eq, Show)
2223

2324
data Decoded tx
24-
= DecodedHydraLog {t :: UTCTime, n :: Text, info :: InfoLine}
25+
= DecodedHydraLog {t :: UTCTime, n :: Text, infoLine :: InfoLine}
2526
| DropLog
2627
deriving (Eq, Show)
2728

@@ -73,8 +74,34 @@ colorLog = \case
7374
LogicError _ -> red
7475
Other _ -> green
7576

77+
newtype Options = Options
78+
{ paths :: [FilePath]
79+
}
80+
deriving (Show)
81+
82+
options :: Parser Options
83+
options =
84+
Options
85+
<$> many
86+
( strArgument
87+
( metavar "FILES"
88+
<> help "One or more log file paths."
89+
)
90+
)
91+
92+
opts :: ParserInfo Options
93+
opts =
94+
info
95+
(options <**> helper)
96+
( fullDesc
97+
<> progDesc "Group logs by the timestamp and display using colors and separators for easy inspection."
98+
<> header "Visualize hydra-node logs"
99+
)
100+
76101
main :: IO ()
77-
main = visualize ["../devnet/alice-logs.txt", "../devnet/bob-logs.txt"]
102+
main = do
103+
args <- execParser opts
104+
visualize $ paths args
78105

79106
visualize :: [FilePath] -> IO ()
80107
visualize paths = do
@@ -182,7 +209,7 @@ processLogs decoded =
182209

183210
render :: Decoded tx -> IO ()
184211
render = \case
185-
DecodedHydraLog{t, n, info = InfoLine{toplabel, details}} -> do
212+
DecodedHydraLog{t, n, infoLine = InfoLine{toplabel, details}} -> do
186213
putTextLn $
187214
unlines
188215
[ "-----------------------------------"

hydra-node/hydra-node.cabal

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,13 @@ executable visualize-logs
255255
, aeson
256256
, base
257257
, conduit
258-
, bytestring
259-
, containers
260258
, hydra-cardano-api
261259
, hydra-node
262260
, hydra-prelude
263261
, lens
264262
, lens-aeson
263+
, optparse-applicative
265264
, text
266-
, unix
267265

268266
ghc-options: -threaded -rtsopts -with-rtsopts=-N4
269267

0 commit comments

Comments
 (0)