Skip to content

Commit

Permalink
Merge branch 'main' into cl/conway-user-stories
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLopezDeLara authored Dec 19, 2023
2 parents 5d642c6 + 32fa6b2 commit eaa9e44
Show file tree
Hide file tree
Showing 30 changed files with 129 additions and 136 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ See the [Contributing guide](CONTRIBUTING.md) for how to contribute to this proj

Development documentation can be found in [Cardano Node Wiki](https://github.com/input-output-hk/cardano-node-wiki/wiki).

Haddock documentation is available at: https://input-output-hk.github.io/cardano-cli/
Haddock documentation is available at: https://cardano-cli.cardano.intersectmbo.org/
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Custom repository for cardano haskell packages, see CONTRIBUTING for more
repository cardano-haskell-packages
url: https://input-output-hk.github.io/cardano-haskell-packages
url: https://chap.intersectmbo.org/
secure: True
root-keys:
3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ data GovernanceActionViewCmdArgs era
= GovernanceActionViewCmdArgs
{ eon :: !(ConwayEraOnwards era)
, actionFile :: !(ProposalFile In)
, outFormat :: !GovernanceActionViewOutputFormat
, outFormat :: !ViewOutputFormat
, mOutFile :: !(Maybe (File () Out))
} deriving Show

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data GovernanceVoteCreateCmdArgs era
data GovernanceVoteViewCmdArgs era
= GovernanceVoteViewCmdArgs
{ eon :: ConwayEraOnwards era
, yamlOutput :: Bool
, outFormat :: !ViewOutputFormat
, voteFile :: VoteFile In
, mOutFile :: Maybe (File () Out)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ newtype TransactionTxIdCmdArgs = TransactionTxIdCmdArgs
} deriving Show

data TransactionViewCmdArgs = TransactionViewCmdArgs
{ outputFormat :: !TxViewOutputFormat
{ outputFormat :: !ViewOutputFormat
, mOutFile :: !(Maybe (File () Out))
, inputTxBodyOrTxFile :: !InputTxBodyOrTxFile
} deriving Show
Expand Down
43 changes: 22 additions & 21 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,29 +1566,30 @@ pPoolIdOutputFormat =
, Opt.value IdOutputFormatBech32
]

pTxViewOutputFormat :: Parser TxViewOutputFormat
pTxViewOutputFormat =
Opt.option readTxViewOutputFormat $ mconcat
[ Opt.long "output-format"
, Opt.metavar "STRING"
, Opt.help $ mconcat
[ "Optional transaction view output format. Accepted output formats are \"json\" "
, "and \"yaml\" (default is \"json\")."
]
, Opt.value TxViewOutputFormatJson
]
pTxViewOutputFormat :: Parser ViewOutputFormat
pTxViewOutputFormat = pViewOutputFormat "transaction"

pGovernanceActionViewOutputFormat :: Parser GovernanceActionViewOutputFormat
pGovernanceActionViewOutputFormat =
Opt.option readGovernanceActionViewOutputFormat $ mconcat
[ Opt.long "output-format"
, Opt.metavar "STRING"
, Opt.help $ mconcat
[ "Optional governance action view output format. Accepted output formats are \"json\" "
, "and \"yaml\" (default is \"json\")."
]
, Opt.value GovernanceActionViewOutputFormatJson
pGovernanceActionViewOutputFormat :: Parser ViewOutputFormat
pGovernanceActionViewOutputFormat = pViewOutputFormat "governance action"

pGovernanceVoteViewOutputFormat :: Parser ViewOutputFormat
pGovernanceVoteViewOutputFormat = pViewOutputFormat "governance vote"

-- | @pViewOutputFormat kind@ is a parser to specify in which format
-- to view some data (json or yaml). @what@ is the kind of data considered.
pViewOutputFormat :: String -> Parser ViewOutputFormat
pViewOutputFormat kind =
asum
[ make ViewOutputFormatJson "JSON" "json" Nothing
, make ViewOutputFormatYaml "YAML" "yaml" (Just " Defaults to JSON if unspecified.")
]
where
make format desc flag_ extraHelp =
Opt.flag ViewOutputFormatJson format $ mconcat
[ Opt.help $
"Format " <> kind <> " view output to " <> desc <> "."
<> fromMaybe "" extraHelp
, Opt.long ("output-" <> flag_)]

pMaybeOutputFile :: Parser (Maybe (File content Out))
pMaybeOutputFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ pGovernanceVoteViewCmd era = do
pGovernanceVoteViewCmdArgs :: ConwayEraOnwards era -> Parser (GovernanceVoteViewCmdArgs era)
pGovernanceVoteViewCmdArgs cOnwards =
GovernanceVoteViewCmdArgs cOnwards
<$> pYamlOutput
<$> pGovernanceVoteViewOutputFormat
<*> pFileInDirection "vote-file" "Input filepath of the vote."
<*> pMaybeOutputFile
where
pYamlOutput :: Parser Bool
pYamlOutput =
Opt.switch
( Opt.long "yaml"
<> Opt.help "Output vote in YAML format (and not JSON)."
)
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ runGovernanceActionViewCmd
firstExceptT GovernanceActionsCmdWriteFileError . newExceptT $
friendlyProposal
(case outFormat of
GovernanceActionViewOutputFormatJson -> FriendlyJson
GovernanceActionViewOutputFormatYaml -> FriendlyYaml)
ViewOutputFormatJson -> FriendlyJson
ViewOutputFormatYaml -> FriendlyYaml)
mOutFile
eon
proposal
Expand Down
14 changes: 9 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ runGovernanceVoteViewCmd :: ()
runGovernanceVoteViewCmd
Cmd.GovernanceVoteViewCmdArgs
{ eon
, yamlOutput
, outFormat
, voteFile
, mOutFile
} = do
Expand All @@ -96,8 +96,12 @@ runGovernanceVoteViewCmd
readVotingProceduresFile eon voteFile
firstExceptT GovernanceVoteCmdWriteError .
newExceptT .
(if yamlOutput
then writeByteStringOutput mOutFile . Yaml.encodePretty (Yaml.setConfCompare compare Yaml.defConfig)
else writeLazyByteStringOutput mOutFile . encodePretty' (defConfig {confCompare = compare})) .
(case outFormat of
ViewOutputFormatYaml ->
writeByteStringOutput mOutFile . Yaml.encodePretty
(Yaml.setConfCompare compare Yaml.defConfig)
ViewOutputFormatJson ->
writeLazyByteStringOutput mOutFile . encodePretty'
(defConfig {confCompare = compare})) .
unVotingProcedures $
voteProcedures
voteProcedures
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,15 +1189,15 @@ runTransactionViewCmd
-- is arguably not part of the transaction body.
firstExceptT TxCmdWriteFileError . newExceptT $
case outputFormat of
TxViewOutputFormatYaml -> friendlyTxBody FriendlyYaml mOutFile (toCardanoEra era) txbody
TxViewOutputFormatJson -> friendlyTxBody FriendlyJson mOutFile (toCardanoEra era) txbody
ViewOutputFormatYaml -> friendlyTxBody FriendlyYaml mOutFile (toCardanoEra era) txbody
ViewOutputFormatJson -> friendlyTxBody FriendlyJson mOutFile (toCardanoEra era) txbody
InputTxFile (File txFilePath) -> do
txFile <- liftIO $ fileOrPipe txFilePath
InAnyShelleyBasedEra era tx <- lift (readFileTx txFile) & onLeft (left . TxCmdCddlError)
firstExceptT TxCmdWriteFileError . newExceptT $
case outputFormat of
TxViewOutputFormatYaml -> friendlyTx FriendlyYaml mOutFile (toCardanoEra era) tx
TxViewOutputFormatJson -> friendlyTx FriendlyJson mOutFile (toCardanoEra era) tx
ViewOutputFormatYaml -> friendlyTx FriendlyYaml mOutFile (toCardanoEra era) tx
ViewOutputFormatJson -> friendlyTx FriendlyJson mOutFile (toCardanoEra era) tx

-- ----------------------------------------------------------------------------
-- Witness commands
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Commands/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ data LegacyTransactionCmds
| TransactionTxIdCmd
InputTxBodyOrTxFile
| TransactionViewCmd
TxViewOutputFormat
ViewOutputFormat
(Maybe (File () Out))
InputTxBodyOrTxFile

Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ runLegacyTransactionTxIdCmd txfile =
txfile
)

runLegacyTransactionViewCmd :: TxViewOutputFormat -> Maybe (File () Out) -> InputTxBodyOrTxFile -> ExceptT TxCmdError IO ()
runLegacyTransactionViewCmd :: ViewOutputFormat -> Maybe (File () Out) -> InputTxBodyOrTxFile -> ExceptT TxCmdError IO ()
runLegacyTransactionViewCmd
yamlOrJson
mOutFile
Expand Down
29 changes: 12 additions & 17 deletions cardano-cli/src/Cardano/CLI/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
module Cardano.CLI.Parser
( readerFromAttoParser
, readFractionAsRational
, readGovernanceActionViewOutputFormat
, readKeyOutputFormat
, readIdOutputFormat
, readTxViewOutputFormat
, readRational
, readRationalUnitInterval
, readStringOfMaxLength
, readViewOutputFormat
, readURIOfMaxLength
, eDNSName
, readGovernanceActionViewOutputFormat
) where

import Cardano.CLI.Types.Common
Expand Down Expand Up @@ -51,30 +52,24 @@ readKeyOutputFormat = do
, ". Accepted output formats are \"text-envelope\" and \"bech32\"."
]

readTxViewOutputFormat :: Opt.ReadM TxViewOutputFormat
readTxViewOutputFormat = do
s <- Opt.str @String
case s of
"json" -> pure TxViewOutputFormatJson
"yaml" -> pure TxViewOutputFormatYaml
_ ->
fail $ mconcat
[ "Invalid transaction view output format: " <> show s
, ". Accepted output formats are \"json\" and \"yaml\"."
]
readTxViewOutputFormat :: Opt.ReadM ViewOutputFormat
readTxViewOutputFormat = readViewOutputFormat "transaction"

readGovernanceActionViewOutputFormat :: Opt.ReadM GovernanceActionViewOutputFormat
readGovernanceActionViewOutputFormat = do
readViewOutputFormat :: String -> Opt.ReadM ViewOutputFormat
readViewOutputFormat kind = do
s <- Opt.str @String
case s of
"json" -> pure GovernanceActionViewOutputFormatJson
"yaml" -> pure GovernanceActionViewOutputFormatYaml
"json" -> pure ViewOutputFormatJson
"yaml" -> pure ViewOutputFormatYaml
_ ->
fail $ mconcat
[ "Invalid governance action view output format: " <> show s
[ "Invalid ", kind, " output format: " <> show s
, ". Accepted output formats are \"json\" and \"yaml\"."
]

readGovernanceActionViewOutputFormat :: Opt.ReadM ViewOutputFormat
readGovernanceActionViewOutputFormat = readViewOutputFormat "governance action view"

readURIOfMaxLength :: Int -> Opt.ReadM Text
readURIOfMaxLength maxLen =
Text.pack <$> readStringOfMaxLength maxLen
Expand Down
14 changes: 4 additions & 10 deletions cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module Cardano.CLI.Types.Common
, GenesisDir(..)
, GenesisFile (..)
, GenesisKeyFile(..)
, GovernanceActionViewOutputFormat(..)
, InputTxBodyOrTxFile (..)
, KeyOutputFormat(..)
, MetadataFile(..)
Expand Down Expand Up @@ -70,10 +69,10 @@ module Cardano.CLI.Types.Common
, TxOutCount(..)
, TxOutDatumAnyEra (..)
, TxShelleyWitnessCount(..)
, TxViewOutputFormat(..)
, UpdateProposalFile (..)
, VerificationKeyBase64(..)
, VerificationKeyFile
, ViewOutputFormat(..)
, VoteUrl(..)
, VoteText(..)
, VoteHashSource(..)
Expand Down Expand Up @@ -459,14 +458,9 @@ data TxMempoolQuery =
| TxMempoolQueryInfo
deriving Show

data TxViewOutputFormat
= TxViewOutputFormatJson
| TxViewOutputFormatYaml
deriving Show

data GovernanceActionViewOutputFormat
= GovernanceActionViewOutputFormatJson
| GovernanceActionViewOutputFormatYaml
data ViewOutputFormat
= ViewOutputFormatJson
| ViewOutputFormatYaml
deriving Show
--
-- Shelley CLI flag/option data types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ hprop_golden_conway_governance_action_view_update_committee_yaml =
actionView <- execCardanoCLI
[ "conway", "governance", "action", "view"
, "--action-file", actionFile
, "--output-format", "yaml"
, "--output-yaml"
]
H.diffVsGoldenFile actionView goldenActionViewFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ hprop_golden_governance_governance_vote_view_yaml =
voteViewGold <- H.note "test/cardano-cli-golden/files/golden/governance/vote/voteViewYAML"
voteView <- execCardanoCLI
[ "conway", "governance", "vote", "view"
, "--yaml"
, "--output-yaml"
, "--vote-file", voteFile
]

Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/TxView.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ _hprop_golden_view_byron_yaml =
-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-format", "yaml"]
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-yaml"]
H.diffVsGoldenFile result "test/cardano-cli-golden/files/golden/byron/transaction-view.out"

-- TODO: Expose command to view byron tx files
Expand Down Expand Up @@ -147,7 +147,7 @@ hprop_golden_view_shelley_yaml = let
-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-format", "yaml"]
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-yaml"]

H.diffVsGoldenFile result "test/cardano-cli-golden/files/golden/shelley/transaction-view.out"

Expand Down Expand Up @@ -178,7 +178,7 @@ hprop_golden_view_allegra_yaml =
-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-format", "yaml"]
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-yaml"]
H.diffVsGoldenFile result "test/cardano-cli-golden/files/golden/allegra/transaction-view.out"

hprop_golden_view_mary_yaml :: Property
Expand Down Expand Up @@ -245,7 +245,7 @@ hprop_golden_view_mary_yaml =
-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-format", "yaml"]
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-yaml"]
H.diffVsGoldenFile result "test/cardano-cli-golden/files/golden/mary/transaction-view.out"

createAlonzoTxBody :: Maybe FilePath -> FilePath -> Integration ()
Expand Down Expand Up @@ -302,7 +302,7 @@ hprop_golden_view_alonzo_yaml =
-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-format", "yaml"]
["transaction", "view", "--tx-body-file", transactionBodyFile, "--output-yaml"]
H.diffVsGoldenFile result "test/cardano-cli-golden/files/golden/alonzo/transaction-view.out"

hprop_golden_view_alonzo_signed_yaml :: Property
Expand All @@ -328,6 +328,6 @@ hprop_golden_view_alonzo_signed_yaml =
-- View transaction body
result <-
execCardanoCLI
["transaction", "view", "--tx-file", transactionFile, "--output-format", "yaml"]
["transaction", "view", "--tx-file", transactionFile, "--output-yaml"]

H.diffVsGoldenFile result (golden </> "signed-transaction-view.out")
Loading

0 comments on commit eaa9e44

Please sign in to comment.