Skip to content

Commit

Permalink
Parse MemberStatus filter as a flag rather than string argument
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Oct 27, 2023
1 parent 90d611e commit 93e565e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ module Cardano.CLI.EraBased.Options.Query
) where

import Cardano.Api hiding (QueryInShelleyBasedEra (..))
import qualified Cardano.Api as MemberStatus (MemberStatus (..))
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.EraBased.Commands.Query
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Types.Common

import qualified Data.Text as Text (toLower, unpack)
import Data.Foldable
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt
Expand Down Expand Up @@ -364,21 +364,23 @@ pQueryGetCommitteeStateCmd era envCli = do
<*> many pCommitteeHotKeyOrHashOrFile
<*> many pMemberStatus
<*> optional pOutputFile

pMemberStatus :: Parser MemberStatus
pMemberStatus =
Opt.option readerMemberStatus $ mconcat
[ Opt.long "memberstatus"
, Opt.metavar "MEMBER_STATUS"
, Opt.help "Member status filter: active/expired/unrecognized"
]
readerMemberStatus :: ReadM MemberStatus
readerMemberStatus = do
v <- Opt.str
case Text.toLower v of
"active" -> pure Active
"expired" -> pure Expired
"unrecognized" -> pure Unrecognized
_ -> fail ("Unrecognized status: " <> Text.unpack v)
asum
[ Opt.flag' MemberStatus.Active $ mconcat
[ Opt.long "active"
, Opt.help "Active committee members (members whose vote will count during ratification)"
]
, Opt.flag' MemberStatus.Expired $ mconcat
[ Opt.long "expired"
, Opt.help "Expired committee members"
]
, Opt.flag' MemberStatus.Unrecognized $ mconcat
[ Opt.long "unrecognized"
, Opt.help "Unrecognized committe members: a hot credential for an unknown cold credential"
]
]

pQueryNoArgCmdArgs :: ()
=> ConwayEraOnwards era
Expand Down

0 comments on commit 93e565e

Please sign in to comment.