Skip to content

Commit

Permalink
[skip ci] hadmin-store: fix formatting and handling of logReplicateAc…
Browse files Browse the repository at this point in the history
…ross attribute display (#1622)
  • Loading branch information
4eUeP authored Sep 25, 2023
1 parent 4999329 commit 7900f1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
${{ env.CABAL }} install hadmin-store
- name: run hadmin-store
run: ${{ env.CABAL }} exec hadmin-store --help
run: ${{ env.CABAL }} exec -- hadmin-store --help

build-and-test:
needs: pre-build
Expand Down
22 changes: 13 additions & 9 deletions hstream-admin/store/HStream/Admin/Store/Command/Logs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,26 @@ printLogDirectory' client level maxDepth verbose logDirectory = do

printLogAttributes :: Int -> LogAttributes -> IO ()
printLogAttributes level LogAttributes{..} = do
let cast = Casting.toKebab . Casting.dropPrefix . Casting.fromAny
emit s = putStrLn $ replicate ((level + 1) * shift) ' ' <> "- " <> s
#define _SHOW_ATTR(x) cast #x <> ": " <> showAttributeVal x
let formatAttrKey = Casting.toKebab . Casting.dropPrefix . Casting.fromAny
emit (Just s) = putStrLn $ replicate ((level + 1) * shift) ' ' <> "- " <> s
emit Nothing = pure ()
#define _SHOW_ATTR(x) showAttributeVal x (formatAttrKey #x <> ": ")
emit $ _SHOW_ATTR(logReplicationFactor)
emit $ _SHOW_ATTR(logSyncedCopies)
emit $ _SHOW_ATTR(logBacklogDuration)
emit $ _SHOW_ATTR(logReplicateAcross)
forM_ (Map.toList logAttrsExtras) $ \(k, v) ->
emit $ unpack k <> ": " <> unpack v
emit $ Just $ unpack k <> ": " <> unpack v
#undef _SHOW_ATTR

showAttributeVal :: Show a => S.Attribute a -> String
showAttributeVal S.Attribute{..} =
-- TODO
let overridden = if not attrInherited then " (Overridden)" else ""
in (show . fromJust $ attrValue) <> overridden
showAttributeVal :: Show a => S.Attribute a -> String -> Maybe String
showAttributeVal S.Attribute{..} label =
case attrValue of
Nothing -> Nothing
Just vl ->
-- TODO
let overridden = if not attrInherited then " (Overridden)" else ""
in Just $ label <> (show vl) <> overridden

runLogsSetRange :: HeaderConfig AdminAPI -> SetRangeOpts -> IO ()
runLogsSetRange conf SetRangeOpts{..} = do
Expand Down

0 comments on commit 7900f1b

Please sign in to comment.