Skip to content

Commit ddedf9a

Browse files
committed
Rollout --output-json-pretty and --output-yaml to these commands:
* `compatible conway governance action view` * `compatible conway governance vote view` * `conway governance action view` * `conway governance vote view` * `conway query leadership-schedule` * `debug transaction view` * `latest governance action view` * `latest governance vote view` * `latest query leadership-schedule` * `query leadership-schedule`
1 parent 10448ef commit ddedf9a

25 files changed

+140
-99
lines changed

cardano-cli/src/Cardano/CLI/EraBased/Governance/Actions/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ data GovernanceActionViewCmdArgs era
158158
= GovernanceActionViewCmdArgs
159159
{ eon :: !(ConwayEraOnwards era)
160160
, actionFile :: !(ProposalFile In)
161-
, outFormat :: !(Vary [FormatJson, FormatYaml])
161+
, outFormat :: !(Vary [FormatJson, FormatJsonPretty, FormatYaml])
162162
, mOutFile :: !(Maybe (File () Out))
163163
}
164164
deriving Show

cardano-cli/src/Cardano/CLI/EraBased/Governance/Actions/Option.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pGovernanceActionViewCmd era = do
6060
<*> pFormatFlags
6161
"governance action view output"
6262
[ flagFormatJson & setDefault
63+
, flagFormatJsonPretty
6364
, flagFormatYaml
6465
]
6566
<*> pMaybeOutputFile

cardano-cli/src/Cardano/CLI/EraBased/Governance/Vote/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ data GovernanceVoteCreateCmdArgs era
4545
data GovernanceVoteViewCmdArgs era
4646
= GovernanceVoteViewCmdArgs
4747
{ eon :: ConwayEraOnwards era
48-
, outFormat :: !(Vary [FormatJson, FormatYaml])
48+
, outFormat :: !(Vary [FormatJson, FormatJsonPretty, FormatYaml])
4949
, voteFile :: VoteFile In
5050
, mOutFile :: Maybe (File () Out)
5151
}

cardano-cli/src/Cardano/CLI/EraBased/Governance/Vote/Option.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pGovernanceVoteViewCmdArgs cOnwards =
9494
<$> pFormatFlags
9595
"governance vote view output"
9696
[ flagFormatJson & setDefault
97+
, flagFormatJsonPretty
9798
, flagFormatYaml
9899
]
99100
<*> pFileInDirection "vote-file" "Input filepath of the vote."

cardano-cli/src/Cardano/CLI/EraBased/Governance/Vote/Run.hs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ import Cardano.Api.Shelley
2121
import Cardano.CLI.EraBased.Governance.Vote.Command qualified as Cmd
2222
import Cardano.CLI.EraBased.Script.Vote.Read
2323
import Cardano.CLI.EraIndependent.Hash.Internal.Common (carryHashChecks)
24+
import Cardano.CLI.Json.Encode qualified as Json
2425
import Cardano.CLI.Read (getHashFromStakePoolKeyHashSource)
2526
import Cardano.CLI.Type.Common
2627
import Cardano.CLI.Type.Error.CmdError
2728
import Cardano.CLI.Type.Error.GovernanceVoteCmdError
2829
import Cardano.CLI.Type.Governance
2930
import Cardano.CLI.Type.Key
3031

31-
import Data.Aeson.Encode.Pretty
3232
import Data.Function
33-
import Data.Yaml.Pretty qualified as Yaml
3433
import Vary qualified
3534

3635
runGovernanceVoteCmds
@@ -115,26 +114,15 @@ runGovernanceVoteViewCmd
115114
fmap fst $
116115
firstExceptT GovernanceVoteCmdReadVoteFileError $
117116
readVoteScriptWitness eon (voteFile, Nothing)
118-
firstExceptT GovernanceVoteCmdWriteError
119-
. newExceptT
120-
. ( outFormat
117+
118+
let output =
119+
outFormat
121120
& ( id
122-
. Vary.on (\FormatJson -> writeJson)
123-
. Vary.on (\FormatYaml -> writeYaml)
121+
. Vary.on (\FormatJson -> Json.encodeJson)
122+
. Vary.on (\FormatJsonPretty -> Json.encodeJsonPretty)
123+
. Vary.on (\FormatYaml -> Json.encodeYaml)
124124
$ Vary.exhaustiveCase
125125
)
126-
)
127-
. unVotingProcedures
128-
$ voteProcedures
129-
where
130-
writeJson :: ToJSON a => a -> IO (Either (FileError ()) ())
131-
writeJson =
132-
writeLazyByteStringOutput mOutFile
133-
. encodePretty'
134-
(defConfig{confCompare = compare})
126+
$ unVotingProcedures voteProcedures
135127

136-
writeYaml :: ToJSON a => a -> IO (Either (FileError ()) ())
137-
writeYaml =
138-
writeByteStringOutput mOutFile
139-
. Yaml.encodePretty
140-
(Yaml.setConfCompare compare Yaml.defConfig)
128+
firstExceptT GovernanceVoteCmdWriteError $ newExceptT $ writeLazyByteStringOutput mOutFile output

cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
9494
, poolColdVerKeyFile :: !StakePoolKeyHashSource
9595
, vrkSkeyFp :: !(SigningKeyFile In)
9696
, whichSchedule :: !EpochLeadershipSchedule
97-
, format :: !(Vary [FormatJson, FormatText])
97+
, format :: !(Vary [FormatJson, FormatJsonPretty, FormatText, FormatYaml])
9898
, mOutFile :: !(Maybe (File () Out))
9999
}
100100
deriving (Generic, Show)

cardano-cli/src/Cardano/CLI/EraBased/Query/Option.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,9 @@ pLeadershipScheduleCmd era envCli =
512512
<*> pFormatFlags
513513
"leadership-schedule query output"
514514
[ flagFormatJson & setDefault
515+
, flagFormatJsonPretty
515516
, flagFormatText
517+
, flagFormatYaml
516518
]
517519
<*> pMaybeOutputFile
518520

cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Cardano.Binary qualified as CBOR
5252
import Cardano.CLI.EraBased.Genesis.Internal.Common
5353
import Cardano.CLI.EraBased.Query.Command qualified as Cmd
5454
import Cardano.CLI.Helper
55+
import Cardano.CLI.Json.Encode qualified as Json
5556
import Cardano.CLI.Read
5657
( getHashFromStakePoolKeyHashSource
5758
)
@@ -69,7 +70,7 @@ import Cardano.Slotting.Time (RelativeTime (..), toRelativeTime)
6970
import Control.Monad (forM, forM_, join)
7071
import Data.Aeson as Aeson
7172
import Data.Aeson qualified as A
72-
import Data.Aeson.Encode.Pretty (encodePretty)
73+
import Data.Aeson.Encode.Pretty qualified as Aeson
7374
import Data.Bifunctor (Bifunctor (..))
7475
import Data.ByteString.Base16.Lazy qualified as Base16
7576
import Data.ByteString.Char8 qualified as C8
@@ -92,7 +93,6 @@ import Data.Text.Encoding qualified as Text
9293
import Data.Text.IO qualified as T
9394
import Data.Text.Lazy.IO qualified as LT
9495
import Data.Time.Clock
95-
import Data.Yaml qualified as Yaml
9696
import GHC.Exts (IsList (..))
9797
import GHC.Generics
9898
import Lens.Micro ((^.))
@@ -160,7 +160,7 @@ runQueryProtocolParametersCmd
160160
firstExceptT QueryCmdWriteFileError . newExceptT $
161161
writeLazyByteStringOutput mOutFile' $
162162
shelleyBasedEraConstraints sbe $
163-
encodePretty pparams
163+
Aeson.encodePretty pparams
164164

165165
-- | Calculate the percentage sync rendered as text: @min 1 (tipTime/nowTime)@
166166
percentage
@@ -290,7 +290,7 @@ runQueryTipCmd
290290

291291
firstExceptT QueryCmdWriteFileError . newExceptT $
292292
writeLazyByteStringOutput mOutFile $
293-
encodePretty localStateOutput
293+
Aeson.encodePretty localStateOutput
294294

295295
-- | Query the UTxO, filtered by a given set of addresses, from a Shelley node
296296
-- via the local state query protocol.
@@ -387,7 +387,7 @@ runQueryKesPeriodInfoCmd
387387
renderOpCertNodeAndOnDiskCounterInformation (unFile nodeOpCertFp) counterInformation
388388

389389
let qKesInfoOutput = createQueryKesPeriodInfoOutput opCertIntervalInformation counterInformation eInfo gParams
390-
kesPeriodInfoJSON = encodePretty qKesInfoOutput
390+
kesPeriodInfoJSON = Aeson.encodePretty qKesInfoOutput
391391

392392
liftIO $ LBS.putStrLn kesPeriodInfoJSON
393393
forM_
@@ -681,7 +681,7 @@ runQueryTxMempoolCmd
681681
result <- liftIO $ queryTxMonitoringLocal nodeConnInfo localQuery
682682
firstExceptT QueryCmdWriteFileError . newExceptT $
683683
writeLazyByteStringOutput mOutFile $
684-
encodePretty result
684+
Aeson.encodePretty result
685685

686686
runQuerySlotNumberCmd
687687
:: ()
@@ -883,14 +883,15 @@ runQueryLedgerPeerSnapshot
883883
Left (bs :: LBS.ByteString) -> do
884884
firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
885885
Right (snapshot :: LedgerPeerSnapshot) -> do
886-
outputContents <-
887-
outputFormat
888-
& ( id
889-
. Vary.on (\FormatJson -> pure $ Aeson.encode snapshot)
890-
. Vary.on (\FormatJsonPretty -> pure $ encodePretty snapshot)
891-
. Vary.on (\FormatYaml -> pure $ LBS.fromStrict $ Yaml.encode snapshot)
892-
$ Vary.exhaustiveCase
893-
)
886+
let outputContents =
887+
outputFormat
888+
& ( id
889+
. Vary.on (\FormatJson -> Json.encodeJson)
890+
. Vary.on (\FormatJsonPretty -> Json.encodeJsonPretty)
891+
. Vary.on (\FormatYaml -> Json.encodeYaml)
892+
$ Vary.exhaustiveCase
893+
)
894+
$ snapshot
894895

895896
let writeOutputContents =
896897
case mOutFile of
@@ -1048,7 +1049,7 @@ writeStakeAddressInfo
10481049
)
10491050
mOutFile =
10501051
firstExceptT QueryCmdWriteFileError . newExceptT $
1051-
writeLazyByteStringOutput mOutFile (encodePretty $ jsonInfo sbe)
1052+
writeLazyByteStringOutput mOutFile (Aeson.encodePretty $ jsonInfo sbe)
10521053
where
10531054
jsonInfo :: ShelleyBasedEra era -> [Aeson.Value]
10541055
jsonInfo =
@@ -1115,7 +1116,7 @@ writeStakeSnapshots mOutFile qState = do
11151116
& onLeft (left . QueryCmdStakeSnapshotDecodeError)
11161117

11171118
-- Calculate the three pool and active stake values for the given pool
1118-
liftIO . maybe LBS.putStrLn (LBS.writeFile . unFile) mOutFile $ encodePretty snapshot
1119+
liftIO . maybe LBS.putStrLn (LBS.writeFile . unFile) mOutFile $ Aeson.encodePretty snapshot
11191120

11201121
-- | This function obtains the pool parameters, equivalent to the following jq query on the output of query ledger-state
11211122
-- .nesEs.esLState.lsDPState.dpsPState.psStakePoolParams.<pool_id>
@@ -1155,7 +1156,7 @@ writePoolState mOutFile serialisedCurrentEpochState = do
11551156

11561157
firstExceptT QueryCmdWriteFileError . newExceptT $
11571158
writeLazyByteStringOutput mOutFile $
1158-
encodePretty poolStates
1159+
Aeson.encodePretty poolStates
11591160

11601161
writeProtocolState
11611162
:: ShelleyBasedEra era
@@ -1196,7 +1197,7 @@ writeProtocolState sbe mOutFile ps@(ProtocolState pstate) =
11961197
decodePState ps' =
11971198
case decodeProtocolState ps' of
11981199
Left (bs, _) -> firstExceptT QueryCmdHelpersError $ pPrintCBOR bs
1199-
Right chainDepstate -> liftIO . LBS.putStrLn $ encodePretty chainDepstate
1200+
Right chainDepstate -> liftIO . LBS.putStrLn $ Aeson.encodePretty chainDepstate
12001201

12011202
writeFilteredUTxOs
12021203
:: Api.ShelleyBasedEra era
@@ -1212,7 +1213,7 @@ writeFilteredUTxOs sbe format mOutFile utxo =
12121213
$ format
12131214
& ( id
12141215
. Vary.on (\FormatCbor -> Base16.encode . CBOR.serialize $ toLedgerUTxO sbe utxo)
1215-
. Vary.on (\FormatJson -> encodePretty utxo)
1216+
. Vary.on (\FormatJson -> Aeson.encodePretty utxo)
12161217
. Vary.on (\FormatText -> strictTextToLazyBytestring $ filteredUTxOsToText sbe utxo)
12171218
$ Vary.exhaustiveCase
12181219
)
@@ -1348,7 +1349,7 @@ writeStakePools format mOutFile stakePools =
13481349
$ Vary.exhaustiveCase
13491350
)
13501351
writeJson =
1351-
encodePretty stakePools
1352+
Aeson.encodePretty stakePools
13521353
writeText =
13531354
LBS.unlines $
13541355
map (strictTextToLazyBytestring . serialiseToBech32) $
@@ -1369,7 +1370,7 @@ writeFormattedOutput format mOutFile value =
13691370
toWrite :: LBS.ByteString =
13701371
format
13711372
& ( id
1372-
. Vary.on (\FormatJson -> encodePretty value)
1373+
. Vary.on (\FormatJson -> Aeson.encodePretty value)
13731374
. Vary.on (\FormatText -> fromString . docToString $ pretty value)
13741375
$ Vary.exhaustiveCase
13751376
)
@@ -1417,7 +1418,7 @@ writeStakeDistribution format mOutFile stakeDistrib =
14171418
toWrite :: LBS.ByteString =
14181419
format
14191420
& ( id
1420-
. Vary.on (\FormatJson -> encodePretty stakeDistrib)
1421+
. Vary.on (\FormatJson -> Aeson.encodePretty stakeDistrib)
14211422
. Vary.on (\FormatText -> strictTextToLazyBytestring stakeDistributionText)
14221423
$ Vary.exhaustiveCase
14231424
)
@@ -1541,8 +1542,10 @@ runQueryLeadershipScheduleCmd
15411542
toWrite =
15421543
format
15431544
& ( id
1544-
. Vary.on (\FormatJson -> encodePretty $ leadershipScheduleToJson schedule eInfo start)
1545+
. Vary.on (\FormatJson -> Json.encodeJson $ leadershipScheduleToJson schedule eInfo start)
1546+
. Vary.on (\FormatJsonPretty -> Json.encodeJsonPretty $ leadershipScheduleToJson schedule eInfo start)
15451547
. Vary.on (\FormatText -> strictTextToLazyBytestring $ leadershipScheduleToText schedule eInfo start)
1548+
. Vary.on (\FormatYaml -> Json.encodeYaml $ leadershipScheduleToJson schedule eInfo start)
15461549
$ Vary.exhaustiveCase
15471550
)
15481551

@@ -1974,10 +1977,10 @@ writeOutput
19741977
-> b
19751978
-> ExceptT QueryCmdError IO ()
19761979
writeOutput mOutFile content = case mOutFile of
1977-
Nothing -> liftIO . LBS.putStrLn . encodePretty $ content
1980+
Nothing -> liftIO . LBS.putStrLn . Aeson.encodePretty $ content
19781981
Just (File f) ->
19791982
handleIOExceptT (QueryCmdWriteFileError . FileIOError f) $
1980-
LBS.writeFile f (encodePretty content)
1983+
LBS.writeFile f (Aeson.encodePretty content)
19811984

19821985
-- Helpers
19831986

cardano-cli/src/Cardano/CLI/EraIndependent/Debug/Option.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pDebugCmds envCli =
8989
<$> pFormatFlags
9090
"transaction view output"
9191
[ flagFormatJson & setDefault
92+
, flagFormatJsonPretty
9293
, flagFormatYaml
9394
]
9495
<*> pMaybeOutputFile

cardano-cli/src/Cardano/CLI/EraIndependent/Debug/TransactionView/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Cardano.CLI.Type.Common
77
import Vary (Vary)
88

99
data TransactionViewCmdArgs = TransactionViewCmdArgs
10-
{ outputFormat :: !(Vary [FormatJson, FormatYaml])
10+
{ outputFormat :: !(Vary [FormatJson, FormatJsonPretty, FormatYaml])
1111
, mOutFile :: !(Maybe (File () Out))
1212
, inputTxBodyOrTxFile :: !InputTxBodyOrTxFile
1313
}

0 commit comments

Comments
 (0)