Skip to content

Commit

Permalink
Rename QueryOutputFormat to OuputFormatJsonOrText
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jul 15, 2024
1 parent 13ad36d commit 49cb236
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
, vrkSkeyFp :: !(SigningKeyFile In)
, whichSchedule :: !EpochLeadershipSchedule
, target :: !(Consensus.Target ChainPoint)
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand Down Expand Up @@ -105,7 +105,7 @@ data QueryStakePoolsCmdArgs = QueryStakePoolsCmdArgs
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, target :: !(Consensus.Target ChainPoint)
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand All @@ -114,7 +114,7 @@ data QueryStakeDistributionCmdArgs = QueryStakeDistributionCmdArgs
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, target :: !(Consensus.Target ChainPoint)
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand All @@ -133,7 +133,7 @@ data QueryUTxOCmdArgs = QueryUTxOCmdArgs
, queryFilter :: !QueryUTxOFilter
, networkId :: !NetworkId
, target :: !(Consensus.Target ChainPoint)
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand Down Expand Up @@ -203,7 +203,7 @@ data QueryRefScriptSizeCmdArgs = QueryRefScriptSizeCmdArgs
, transactionInputs :: !(Set TxIn)
, networkId :: !NetworkId
, target :: !(Consensus.Target ChainPoint)
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,13 +1642,13 @@ pPoolIdOutputFormat =
, Opt.value IdOutputFormatBech32
]

-- | @pQueryOutputFormat kind@ is a parser to specify in which format
-- | @pOutputFormatJsonOrText kind@ is a parser to specify in which format
-- to view some data (json or text). @kind@ is the kind of data considered.
pQueryOutputFormat :: String -> Parser QueryOutputFormat
pQueryOutputFormat kind =
pOutputFormatJsonOrText :: String -> Parser OutputFormatJsonOrText
pOutputFormatJsonOrText kind =
asum
[ make QueryOutputFormatJson "JSON" "json" (Just " Default format when writing to a file")
, make QueryOutputFormatText "TEXT" "text" (Just " Default format when writing to stdout")
[ make OutputFormatJson "JSON" "json" (Just " Default format when writing to a file")
, make OutputFormatText "TEXT" "text" (Just " Default format when writing to stdout")
]
where
make format desc flag_ extraHelp =
Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pQueryUTxOCmd era envCli =
<*> pQueryUTxOFilter
<*> pNetworkId envCli
<*> pTarget era
<*> (optional $ pQueryOutputFormat "utxo")
<*> (optional $ pOutputFormatJsonOrText "utxo")
<*> pMaybeOutputFile

pQueryStakePoolsCmd :: CardanoEra era -> EnvCli -> Parser (QueryCmds era)
Expand All @@ -160,7 +160,7 @@ pQueryStakePoolsCmd era envCli =
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> pTarget era
<*> (optional $ pQueryOutputFormat "stake-pools")
<*> (optional $ pOutputFormatJsonOrText "stake-pools")
<*> pMaybeOutputFile

pQueryStakeDistributionCmd :: CardanoEra era -> EnvCli -> Parser (QueryCmds era)
Expand All @@ -171,7 +171,7 @@ pQueryStakeDistributionCmd era envCli =
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> pTarget era
<*> (optional $ pQueryOutputFormat "stake-distribution")
<*> (optional $ pOutputFormatJsonOrText "stake-distribution")
<*> pMaybeOutputFile

pQueryStakeAddressInfoCmd :: CardanoEra era -> EnvCli -> Parser (QueryCmds era)
Expand Down Expand Up @@ -271,7 +271,7 @@ pLeadershipScheduleCmd era envCli =
<*> pVrfSigningKeyFile
<*> pWhichLeadershipSchedule
<*> pTarget era
<*> (optional $ pQueryOutputFormat "leadership-schedule")
<*> (optional $ pOutputFormatJsonOrText "leadership-schedule")
<*> pMaybeOutputFile

pKesPeriodInfoCmd :: CardanoEra era -> EnvCli -> Parser (QueryCmds era)
Expand Down Expand Up @@ -310,7 +310,7 @@ pQueryRefScriptSizeCmd era envCli =
<*> (fromList <$> some pByTxIn)
<*> pNetworkId envCli
<*> pTarget era
<*> (optional $ pQueryOutputFormat "reference inputs")
<*> (optional $ pOutputFormatJsonOrText "reference inputs")
<*> pMaybeOutputFile
where
pByTxIn :: Parser TxIn
Expand Down
34 changes: 17 additions & 17 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ writeProtocolState sbe mOutFile ps@(ProtocolState pstate) =
Right chainDepstate -> liftIO . LBS.putStrLn $ encodePretty chainDepstate

writeFilteredUTxOs :: Api.ShelleyBasedEra era
-> Maybe QueryOutputFormat
-> Maybe OutputFormatJsonOrText
-> Maybe (File () Out)
-> UTxO era
-> ExceptT QueryCmdError IO ()
Expand All @@ -1053,8 +1053,8 @@ writeFilteredUTxOs sbe format mOutFile utxo =
firstExceptT QueryCmdWriteFileError . newExceptT .
writeLazyByteStringOutput mOutFile $
case newOutputFormat format mOutFile of
QueryOutputFormatJson -> encodePretty utxo
QueryOutputFormatText -> strictTextToLazyBytestring $ filteredUTxOsToText sbe utxo
OutputFormatJson -> encodePretty utxo
OutputFormatText -> strictTextToLazyBytestring $ filteredUTxOsToText sbe utxo

filteredUTxOsToText :: Api.ShelleyBasedEra era -> UTxO era -> Text
filteredUTxOsToText sbe (UTxO utxo) = do
Expand Down Expand Up @@ -1172,7 +1172,7 @@ runQueryStakePoolsCmd

-- TODO: replace with writeFormattedOutput
writeStakePools
:: QueryOutputFormat
:: OutputFormatJsonOrText
-> Maybe (File () Out)
-> Set PoolId
-> ExceptT QueryCmdError IO ()
Expand All @@ -1182,18 +1182,18 @@ writeStakePools format mOutFile stakePools =
where
toWrite :: LBS.ByteString =
case format of
QueryOutputFormatText ->
OutputFormatText ->
LBS.unlines
$ map (strictTextToLazyBytestring . serialiseToBech32)
$ Set.toList stakePools
QueryOutputFormatJson ->
OutputFormatJson ->
encodePretty stakePools

writeFormattedOutput
:: MonadIOTransError QueryCmdError t m
=> ToJSON a
=> Pretty a
=> Maybe QueryOutputFormat
=> Maybe OutputFormatJsonOrText
-> Maybe (File b Out)
-> a
-> t m ()
Expand All @@ -1203,8 +1203,8 @@ writeFormattedOutput mFormat mOutFile value =
where
toWrite :: LBS.ByteString =
case newOutputFormat mFormat mOutFile of
QueryOutputFormatText -> fromString . docToString $ pretty value
QueryOutputFormatJson -> encodePretty value
OutputFormatText -> fromString . docToString $ pretty value
OutputFormatJson -> encodePretty value

runQueryStakeDistributionCmd :: ()
=> Cmd.QueryStakeDistributionCmdArgs
Expand Down Expand Up @@ -1239,7 +1239,7 @@ runQueryStakeDistributionCmd
& onLeft left

writeStakeDistribution
:: QueryOutputFormat
:: OutputFormatJsonOrText
-> Maybe (File () Out)
-> Map PoolId Rational
-> ExceptT QueryCmdError IO ()
Expand All @@ -1249,8 +1249,8 @@ writeStakeDistribution format mOutFile stakeDistrib =
where
toWrite :: LBS.ByteString =
case format of
QueryOutputFormatJson -> encodePretty stakeDistrib
QueryOutputFormatText -> strictTextToLazyBytestring stakeDistributionText
OutputFormatJson -> encodePretty stakeDistrib
OutputFormatText -> strictTextToLazyBytestring stakeDistributionText
stakeDistributionText =
Text.unlines $
[ title
Expand Down Expand Up @@ -1371,9 +1371,9 @@ runQueryLeadershipScheduleCmd
start = SystemStart $ sgSystemStart shelleyGenesis
toWrite =
case newOutputFormat format mOutFile' of
QueryOutputFormatJson ->
OutputFormatJson ->
encodePretty $ leadershipScheduleToJson schedule eInfo start
QueryOutputFormatText ->
OutputFormatText ->
strictTextToLazyBytestring $ leadershipScheduleToText schedule eInfo start

leadershipScheduleToText
Expand Down Expand Up @@ -1660,12 +1660,12 @@ requireEon minEra era =
-- | The output format to use, for commands with a recently introduced --output-[json,text] flag
-- and that used to have the following default: --out-file implies JSON,
-- output to stdout implied text.
newOutputFormat :: Maybe QueryOutputFormat -> Maybe a -> QueryOutputFormat
newOutputFormat :: Maybe OutputFormatJsonOrText -> Maybe a -> OutputFormatJsonOrText
newOutputFormat format mOutFile =
case (format, mOutFile) of
(Just f, _) -> f -- Take flag from CLI if specified
(Nothing, Nothing) -> QueryOutputFormatText -- No CLI flag, writing to stdout: write text
(Nothing, Just _) -> QueryOutputFormatJson -- No CLI flag, writing to a file: write JSON
(Nothing, Nothing) -> OutputFormatText -- No CLI flag, writing to stdout: write text
(Nothing, Just _) -> OutputFormatJson -- No CLI flag, writing to a file: write JSON

strictTextToLazyBytestring :: Text -> LBS.ByteString
strictTextToLazyBytestring t = BS.fromChunks [Text.encodeUtf8 t]
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Legacy/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ data LegacyQueryLeadershipScheduleCmdArgs = LegacyQueryLeadershipScheduleCmdArgs
, poolColdVerKeyFile :: !(VerificationKeyOrHashOrFile StakePoolKey)
, vrkSkeyFp :: !(SigningKeyFile In)
, whichSchedule :: !EpochLeadershipSchedule
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand Down Expand Up @@ -86,15 +86,15 @@ data LegacyQueryStakePoolsCmdArgs = LegacyQueryStakePoolsCmdArgs
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

data LegacyQueryStakeDistributionCmdArgs = LegacyQueryStakeDistributionCmdArgs
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand All @@ -111,7 +111,7 @@ data LegacyQueryUTxOCmdArgs = LegacyQueryUTxOCmdArgs
, consensusModeParams :: !ConsensusModeParams
, queryFilter :: !QueryUTxOFilter
, networkId :: !NetworkId
, format :: Maybe QueryOutputFormat
, format :: Maybe OutputFormatJsonOrText
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Legacy/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ pQueryCmds envCli =
<*> pConsensusModeParams
<*> pQueryUTxOFilter
<*> pNetworkId envCli
<*> (optional $ pQueryOutputFormat "utxo")
<*> (optional $ pOutputFormatJsonOrText "utxo")
<*> pMaybeOutputFile

pQueryStakePools :: Parser LegacyQueryCmds
Expand All @@ -662,7 +662,7 @@ pQueryCmds envCli =
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> (optional $ pQueryOutputFormat "stake-pools")
<*> (optional $ pOutputFormatJsonOrText "stake-pools")
<*> pMaybeOutputFile

pQueryStakeDistribution :: Parser LegacyQueryCmds
Expand All @@ -672,7 +672,7 @@ pQueryCmds envCli =
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> (optional $ pQueryOutputFormat "stake-distribution")
<*> (optional $ pOutputFormatJsonOrText "stake-distribution")
<*> pMaybeOutputFile

pQueryStakeAddressInfo :: Parser LegacyQueryCmds
Expand Down Expand Up @@ -766,7 +766,7 @@ pQueryCmds envCli =
<*> pStakePoolVerificationKeyOrHashOrFile Nothing
<*> pVrfSigningKeyFile
<*> pWhichLeadershipSchedule
<*> (optional $ pQueryOutputFormat "leadership-schedule")
<*> (optional $ pOutputFormatJsonOrText "leadership-schedule")
<*> pMaybeOutputFile

pKesPeriodInfo :: Parser LegacyQueryCmds
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module Cardano.CLI.Types.Common
, ProposalText
, ProposalUrl(..)
, ProtocolParamsFile(..)
, QueryOutputFormat(..)
, OutputFormatJsonOrText(..)
, ReferenceScriptAnyEra (..)
, ReferenceScriptSize (..)
, RequiredSigner (..)
Expand Down Expand Up @@ -478,9 +478,9 @@ data TxMempoolQuery =
| TxMempoolQueryInfo
deriving Show

data QueryOutputFormat
= QueryOutputFormatJson
| QueryOutputFormatText
data OutputFormatJsonOrText
= OutputFormatJson
| OutputFormatText
deriving Show

data ViewOutputFormat
Expand Down

0 comments on commit 49cb236

Please sign in to comment.