Skip to content

Commit

Permalink
Use some instead of one plus many
Browse files Browse the repository at this point in the history
  • Loading branch information
carlhammann committed Jan 8, 2024
1 parent 3bf8e62 commit 4823900
Show file tree
Hide file tree
Showing 33 changed files with 66 additions and 124 deletions.
18 changes: 7 additions & 11 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ pStakePoolVerificationKeyOrHashOrFile
pStakePoolVerificationKeyOrHashOrFile prefix =
asum
[ VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile prefix
, VerificationKeyHash <$> pStakePoolVerificationKeyHash prefix True
, VerificationKeyHash <$> pStakePoolVerificationKeyHash prefix
]

pCombinedStakePoolVerificationKeyOrHashOrFile
Expand Down Expand Up @@ -2288,18 +2288,14 @@ pAddress =
, Opt.help "A Cardano address"
]

-- | First argument is the prefix to use, second argument is whether we show the long help text
pStakePoolVerificationKeyHash :: Maybe String -> Bool -> Parser (Hash StakePoolKey)
pStakePoolVerificationKeyHash prefix showHelp =
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey) $ mconcat $
(if showHelp
then (Opt.help
"Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded)."
:)
else id
)
-- | First argument is the prefix to use
pStakePoolVerificationKeyHash :: Maybe String -> Parser (Hash StakePoolKey)
pStakePoolVerificationKeyHash prefix =
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey) $ mconcat
[ Opt.long $ prefixFlag prefix "stake-pool-id"
, Opt.metavar "STAKE_POOL_ID"
, Opt.help
"Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded)."
]

pVrfVerificationKeyFile :: Parser (VerificationKeyFile In)
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pAllStakePoolsOrSome = pAll <|> pOnly
, Opt.help "Query for all stake pools"
]
pOnly :: Parser (AllOrOnly (Hash StakePoolKey))
pOnly = Some <$> pStakePoolVerificationKeyHash Nothing True <*> many (pStakePoolVerificationKeyHash Nothing False)
pOnly = Only <$> some (pStakePoolVerificationKeyHash Nothing)

pQueryStakeSnapshotCmd :: EnvCli -> Parser (QueryCmds era)
pQueryStakeSnapshotCmd envCli =
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ runQueryPoolStateCmd

let poolFilter = case allOrOnlyPoolIds of
All -> Nothing
Some poolId poolIds -> Just $ Set.fromList (poolId : poolIds)
Only poolIds -> Just $ Set.fromList poolIds

result <- lift (queryPoolState beo poolFilter)
& onLeft (left . QueryCmdUnsupportedNtcVersion)
Expand Down Expand Up @@ -715,7 +715,7 @@ runQueryStakeSnapshotCmd

let poolFilter = case allOrOnlyPoolIds of
All -> Nothing
Some poolId poolIds -> Just $ Set.fromList (poolId : poolIds)
Only poolIds -> Just $ Set.fromList poolIds

beo <- requireEon BabbageEra era

Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ pQueryCmds envCli =
, Opt.help "Query for all stake pools"
]
pOnly :: Parser (AllOrOnly (Hash StakePoolKey))
pOnly = Some <$> pStakePoolVerificationKeyHash Nothing True <*> many (pStakePoolVerificationKeyHash Nothing False)
pOnly = Only <$> some (pStakePoolVerificationKeyHash Nothing)

pQueryStakeSnapshot :: Parser LegacyQueryCmds
pQueryStakeSnapshot =
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ data KeyOutputFormat
| KeyOutputFormatBech32
deriving (Eq, Show)

data AllOrOnly a = All | Some a [a] deriving (Eq, Show)
data AllOrOnly a = All | Only [a] deriving (Eq, Show)

-- | This data structure is used to allow nicely formatted output in the query pool-params command.
-- params are the current pool parameter settings, futureparams are new parameters, retiringEpoch is the
Expand Down
81 changes: 27 additions & 54 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli allegra query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli allegra query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli allegra query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli alonzo query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli alonzo query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli alonzo query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli babbage query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli babbage query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli babbage query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli conway query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli conway query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli conway query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli latest query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli latest query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli latest query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli legacy query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli legacy query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli legacy query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli mary query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Usage: cardano-cli mary query pool-state --socket-path SOCKET_PATH
[--epoch-slots SLOTS]]
(--mainnet | --testnet-magic NATURAL)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli mary query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Usage: cardano-cli query pool-params --socket-path SOCKET_PATH
[--cardano-mode [--epoch-slots SLOTS]]
(--mainnet | --testnet-magic NATURAL)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Usage: cardano-cli query pool-state --socket-path SOCKET_PATH
[--cardano-mode [--epoch-slots SLOTS]]
(--mainnet | --testnet-magic NATURAL)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Usage: cardano-cli query stake-snapshot --socket-path SOCKET_PATH
[--cardano-mode [--epoch-slots SLOTS]]
(--mainnet | --testnet-magic NATURAL)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli shelley query pool-params --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

DEPRECATED. Use query pool-state instead. Dump the pool parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli shelley query pool-state --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)

Dump the pool state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Usage: cardano-cli shelley query stake-snapshot --socket-path SOCKET_PATH
| --testnet-magic NATURAL
)
( --all-stake-pools
| --stake-pool-id STAKE_POOL_ID
[--stake-pool-id STAKE_POOL_ID]
| (--stake-pool-id STAKE_POOL_ID)
)
[--out-file FILE]

Expand Down

0 comments on commit 4823900

Please sign in to comment.