From b8b7cab2e44d12a6c3d9082dbdf51a0607dc9171 Mon Sep 17 00:00:00 2001 From: mu <59917266+4eUeP@users.noreply.github.com> Date: Mon, 25 Sep 2023 18:30:08 +0800 Subject: [PATCH] hadmin-store: fix formatting and handling of logReplicateAcross attribute display --- .github/workflows/ci.yml | 2 +- .../store/HStream/Admin/Store/Command/Logs.hs | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d729fd7c1..b6b8a168e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/hstream-admin/store/HStream/Admin/Store/Command/Logs.hs b/hstream-admin/store/HStream/Admin/Store/Command/Logs.hs index a99810dde..7ea2698c5 100644 --- a/hstream-admin/store/HStream/Admin/Store/Command/Logs.hs +++ b/hstream-admin/store/HStream/Admin/Store/Command/Logs.hs @@ -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