-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transaction id: add --output-[json,text] flag to control format of the output #1005
base: master
Are you sure you want to change the base?
Conversation
cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_txid.cli
Outdated
Show resolved
Hide resolved
384cec0
to
97a7728
Compare
6ea2dfd
to
406ddfe
Compare
17c25e3
to
f7b4604
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I just have two suggestions.
[ make OutputFormatJson "JSON" "json" False | ||
, make OutputFormatText "TEXT" "text" True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best to have the default be a separate variable and compare to it, since we cannot ensure that there are no several True
values in this list. Also the parser could already return the default instead of a Maybe
, cause that would avoid having coupling with the implementation code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best to have the default be a separate variable and compare to it, since we cannot ensure that there are no several True values in this list
@palas> done:
@@ -1728,14 +1728,15 @@ pOutputFormatJsonOrText kind =
pTxIdOutputFormatJsonOrText :: Parser OutputFormatJsonOrText
pTxIdOutputFormatJsonOrText =
asum
- [ make OutputFormatJson "JSON" "json" False
- , make OutputFormatText "TEXT" "text" True
+ [ make OutputFormatJson "JSON" "json"
+ , make OutputFormatText "TEXT" "text"
]
where
- make format desc flag_ default_ =
+ default_ = OutputFormatText
+ make format desc flag_ =
Opt.flag' format $
mconcat
- [ Opt.help $ "Format output as " <> desc <> (if default_ then " (the default)." else ".")
+ [ Opt.help $ "Format output as " <> desc <> (if format == default_ then " (the default)." else ".")
, Opt.long ("output-" <> flag_)
]
diff --git a/cardano-cli/src/Cardano/CLI/Types/Common.hs b/cardano-cli/src/Cardano/CLI/Types/Common.hs
index 87253b0c7..d23ee97f2 100644
--- a/cardano-cli/src/Cardano/CLI/Types/Common.hs
+++ b/cardano-cli/src/Cardano/CLI/Types/Common.hs
@@ -545,7 +545,7 @@ data TxMempoolQuery
data OutputFormatJsonOrText
= OutputFormatJson
| OutputFormatText
- deriving Show
+ deriving (Eq, Show)
Also the parser could already return the default instead of a Maybe, cause that would avoid having coupling with the implementation code.
@palas> could we? Because we want the flags to be optional, to preserve the existing behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can have a parser that returns the default on absence of a flag. I have done it somewhere, let me check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@palas> this works (for #1010):
pDRepIdOutputFormat :: Parser IdOutputFormat
pDRepIdOutputFormat =
asum [make IdOutputFormatHex "hex", make IdOutputFormatBech32 "bech32"]
<|> pure default_
where
default_ = IdOutputFormatBech32
make format flag_ =
Opt.flag' format $
mconcat
[ Opt.help $
"Format drep id output as "
<> flag_
<> (if format == default_ then " (the default)." else ".")
, Opt.long ("output-" <> flag_)
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is it, I had forgotten the exact details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Was this requested?
@Jimbo4350> no, I witnessed this was a possible improvement to consistency of our CLI interface when using the |
ab49f8f
to
12b76f5
Compare
53a7bc4
to
6efbe9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Changelog
Context
How to trust this PR
HEAD
so the default behavior didn't changeChecklist