Skip to content
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

Fix CLI help formatting #2945

Merged
merged 1 commit into from
Aug 4, 2021
Merged

Fix CLI help formatting #2945

merged 1 commit into from
Aug 4, 2021

Conversation

newhoggy
Copy link
Contributor

No description provided.

@newhoggy newhoggy force-pushed the fix-cli-3 branch 9 times, most recently from 856d4e2 to 1b3ab31 Compare July 21, 2021 09:13
@newhoggy newhoggy marked this pull request as ready for review July 21, 2021 09:18
@newhoggy newhoggy changed the title Fix cli 3 Fix CLI help formatting Jul 21, 2021
@newhoggy
Copy link
Contributor Author

Before:

Usage: cardano-cli transaction build-raw [--byron-era | --shelley-era |
                                           --allegra-era | --mary-era |
                                           --alonzo-era] (--tx-in TX-IN
                                         [--tx-in-script-file FILE
                                           [
                                             (--tx-in-datum-file FILE |
                                               --tx-in-datum-value JSON VALUE)
                                             (--tx-in-redeemer-file FILE |
                                               --tx-in-redeemer-value JSON VALUE)
                                             --tx-in-execution-units (INT, INT)]])
                                         [--tx-in-collateral TX-IN]
                                         [--tx-out ADDRESS VALUE
                                           [--tx-out-datum-hash HASH]]
                                         [--mint VALUE (--mint-script-file FILE
                                           [
                                             (--mint-redeemer-file FILE |
                                               --mint-redeemer-value JSON VALUE)
                                             --mint-execution-units (INT, INT)])]
                                         [--invalid-before SLOT]
                                         [--invalid-hereafter SLOT]
                                         [--fee LOVELACE]
                                         [--certificate-file CERTIFICATEFILE
                                           [--certificate-script-file FILE
                                             [
                                               (--certificate-redeemer-file FILE |

                                                 --certificate-redeemer-value JSON VALUE)
                                               --certificate-execution-units (INT, INT)]]]
                                         [--withdrawal WITHDRAWAL
                                           [--withdrawal-script-file FILE
                                             [
                                               (--withdrawal-redeemer-file FILE |

                                                 --withdrawal-redeemer-value JSON VALUE)
                                               --withdrawal-execution-units (INT, INT)]]]
                                         [--json-metadata-no-schema |
                                           --json-metadata-detailed-schema]
                                         [--auxiliary-script-file FILE]
                                         [--metadata-json-file FILE |
                                           --metadata-cbor-file FILE]
                                         [--genesis FILE |
                                           --protocol-params-file FILE]
                                         [--update-proposal-file FILE]
                                         --out-file FILE

After:

Usage: cardano-cli transaction build-raw  
            [ --byron-era
            | --shelley-era
            | --allegra-era
            | --mary-era
            | --alonzo-era
            ]
            ( --tx-in TX-IN
              [ --tx-in-script-file FILE
                [ (--tx-in-datum-file FILE | --tx-in-datum-value JSON VALUE)
                  ( --tx-in-redeemer-file FILE
                  | --tx-in-redeemer-value JSON VALUE
                  )
                  --tx-in-execution-units (INT, INT)
                ]
              ]
            )
            [--tx-in-collateral TX-IN]
            [--tx-out ADDRESS VALUE [--tx-out-datum-hash HASH]]
            [ --mint VALUE
              ( --mint-script-file FILE
                [ (--mint-redeemer-file FILE | --mint-redeemer-value JSON VALUE)
                  --mint-execution-units (INT, INT)
                ]
              )
            ]
            [--invalid-before SLOT]
            [--invalid-hereafter SLOT]
            [--fee LOVELACE]
            [ --certificate-file CERTIFICATEFILE
              [ --certificate-script-file FILE
                [ ( --certificate-redeemer-file FILE
                  | --certificate-redeemer-value JSON VALUE
                  )
                  --certificate-execution-units (INT, INT)
                ]
              ]
            ]
            [ --withdrawal WITHDRAWAL
              [ --withdrawal-script-file FILE
                [ ( --withdrawal-redeemer-file FILE
                  | --withdrawal-redeemer-value JSON VALUE
                  )
                  --withdrawal-execution-units (INT, INT)
                ]
              ]
            ]
            [--json-metadata-no-schema | --json-metadata-detailed-schema]
            [--auxiliary-script-file FILE]
            [--metadata-json-file FILE | --metadata-cbor-file FILE]
            [--genesis FILE | --protocol-params-file FILE]
            [--update-proposal-file FILE]
            --out-file FILE

@newhoggy
Copy link
Contributor Author

In order to get the traced version of the output for inspection in a browser, supply CLI_HELP_TRACE=1 in the environment. For example:

CLI_HELP_TRACE=1 cardano-cli transaction build-raw

@catch-21
Copy link
Contributor

catch-21 commented Jul 28, 2021

@newhoggy Much improved overall. There's just a couple of things bugging me and causing misalignment. Neither of these are serious.

  1. Only sometimes is there's a space after ( or [, before the option name. I see both ( --tx-in-redeemer-file FILE (with space) and (--tx-in-datum-file FILE (without space). This occurs throughout for all cmds. I think it'd look cleaner if all had the space.

  2. The nested options for --tx-in-script-file are not aligned. The opening bracket for --tx-in-redeemer-file and --tx-in-redeemer-value etc are 1 space ahead of the opening bracket for --tx-in-datum-file. See:

            (--tx-in TX-IN
              [--tx-in-script-file FILE
                [(--tx-in-datum-file FILE | --tx-in-datum-value JSON VALUE)
                  ( --tx-in-redeemer-file FILE
                  | --tx-in-redeemer-value JSON VALUE
                  )
                  --tx-in-execution-units (INT, INT)]])

@newhoggy
Copy link
Contributor Author

newhoggy commented Jul 28, 2021

Yeah, ideally, I want it to look like this:

           ( --tx-in TX-IN
             [ --tx-in-script-file FILE
               [ (--tx-in-datum-file FILE | --tx-in-datum-value JSON VALUE)
                 ( --tx-in-redeemer-file FILE
                 | --tx-in-redeemer-value JSON VALUE
                 )
                 --tx-in-execution-units (INT, INT)
               ]
             ]
           )

ie. space after the bracket/parens if the group spans more than one line, but no space otherwise. Unfortunately the layout code is fairly complex and I haven't yet worked it out even after spending over a day on it. The whole layout code may need a rewrite to achieve the right effect.

I'm interest in merging this on the basis that it is an improvement.

moo.html Outdated Show resolved Hide resolved
@@ -107,6 +107,18 @@ package cardano-ledger-alonzo-test
-- --------------------------- 8< --------------------------
-- Please do not put any `source-repository-package` clause above this line.

source-repository-package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave a comment that we want to eventually not rely on our own fork after the relevant PR has been merged?

import qualified System.IO.Unsafe as IO

cliHelpTraceEnabled :: Bool
cliHelpTraceEnabled = IO.unsafePerformIO $ do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any experience using unsafePerformIO. Is this ok to use here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this seems to be a safe use of unsafePerformIO .

Copy link
Contributor Author

@newhoggy newhoggy Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. This example of unsafePerformIO is fairly normal. unsafePerformIO is used to perform some IO to initialise a global constant. The danger is if the side effect is executed more than once which can happen if the constant is inlined into the callsite, in which case the constant is not so constant, but this is prevent by the NOINLINE pragma. This forces the value to be a thunk that can only be evaluated once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cliHelpTraceEnabled = IO.unsafePerformIO $ do
mValue <- IO.lookupEnv "CLI_HELP_TRACE"
return $ mValue == Just "1"
{-# NOINLINE cliHelpTraceEnabled #-}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we need that.

@newhoggy
Copy link
Contributor Author

newhoggy commented Aug 3, 2021

bors merge

iohk-bors bot added a commit that referenced this pull request Aug 3, 2021
2945: Fix CLI help formatting r=newhoggy a=newhoggy



Co-authored-by: John Ky <john.ky@iohk.io>
* Switch to prettyprinter library
* Tracing
* Command for printing all help
* Option ordering note on build-raw command
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Aug 3, 2021

Canceled.

Copy link
Contributor

@MarcFontaine MarcFontaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the tests.
Looks good to me

@newhoggy
Copy link
Contributor Author

newhoggy commented Aug 3, 2021

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Aug 4, 2021

@iohk-bors iohk-bors bot merged commit b30845f into master Aug 4, 2021
@iohk-bors iohk-bors bot deleted the fix-cli-3 branch August 4, 2021 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] - Emphasise importance of ordering for Alonzo cli build-raw options
5 participants