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

Era-sensitive command structure #98

Merged
merged 1 commit into from
Jul 21, 2023
Merged

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Jul 20, 2023

Changelog

- description: |
    Era-sensitive command structure
  compatibility: breaking
  type: feature

Context

Adding top-level era command groups avoids some of the problems posed by era flags. That is optparse-applicative does not allow for any dependencies between two command line options, so it is not possible for the era flag to control the validity of other flags. To allow for the chosen era to control the validity (and presence) of flags so that flags that are not relevant for the era don't appear and are invalid, the eras are promoted to top-level command groups.

This is what the help looks like now:

cardano-cli
cardano-cli - General purpose command-line utility to interact with
cardano-node. Provides specific commands to manage keys, addresses, build &
submit transactions, certificates, etc.

Usage: cardano-cli
                     ( shelley
                     | allegra
                     | mary
                     | alonzo
                     | babbage
                     | conway
                     | latest
                     | experimental
                     | Legacy commands
                     | byron
                     | ping
                     | version
                     )

Available options:
  --version                Show the cardano-cli version
  -h,--help                Show this help text

Available commands:
  shelley                  Shelley era commands
  allegra                  Allegra era commands
  mary                     Mary era commands
  alonzo                   Alonzo era commands
  babbage                  Babbage era commands
  conway                   Conway era commands
  latest                   Latest era commands (Babbage)
  experimental             Experimental era commands (Conway)

Legacy commands
  address                  Payment address commands
  stake-address            Stake address commands
  key                      Key utility commands
...

And inside governance sub-command for babbage:

$ cardano-cli babbage governance
Usage: cardano-cli babbage governance pre-conway

  Era-based governance commands

Available options:
  -h,--help                Show this help text

Available commands:
  pre-conway               Pre conway era governance command

And inside governance sub-command for conway:


$ cardano-cli conway governance
Usage: cardano-cli conway governance post-conway

  Era-based governance commands

Available options:
  -h,--help                Show this help text

Available commands:
  post-conway              Post conway era governance command

The latter two examples show how command availability can switch on era.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • The change log section in the PR description has been filled in
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • roundtrip tests
    • integration tests
      See Runnings tests for more details
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • The changelog section in the PR is updated to describe the change
  • Self-reviewed the diff

Note on CI

If your PR is from a fork, the necessary CI jobs won't trigger automatically for security reasons.
You will need to get someone with write privileges. Please contact IOG node developers to do this
for you.

@newhoggy newhoggy force-pushed the newhoggy/era-commands-groups branch from fbd2250 to 73af3e4 Compare July 20, 2023 11:38
@newhoggy newhoggy marked this pull request as ready for review July 20, 2023 11:38
@newhoggy newhoggy force-pushed the newhoggy/era-commands-groups branch from 73af3e4 to eef24cf Compare July 20, 2023 11:47
| babbage
| conway
| latest
| experimental
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the new command groups.

Note that byron is intentionally missing because there already is a legacy byron command group.

latest currently set to byron and experimental set to conway.

runEraBasedGovernancePostConwayCmd
:: ConwayEraOnwards era
-> ExceptT () IO ()
runEraBasedGovernancePostConwayCmd _w = pure ()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pre and post conway run functions receive a witness which constrains which era the run function applies to.


pPostConwayCmd :: EnvCli -> CardanoEra era -> Maybe (Parser (EraBasedGovernanceCmd era))
pPostConwayCmd envCli =
featureInEra Nothing $ \feature ->
Copy link
Contributor Author

@newhoggy newhoggy Jul 20, 2023

Choose a reason for hiding this comment

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

Era witnesses are summoned from the era like this. feature is the witness.

@@ -69,8 +69,8 @@ import Text.Read (readEither, readMaybe)
parseLegacyCommands :: EnvCli -> Parser LegacyCommand
parseLegacyCommands envCli =
Opt.hsubparser $ mconcat
[ Opt.metavar "Era based commands"
, Opt.commandGroup "Era based commands"
[ Opt.metavar "Legacy commands"
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps instead of "Legacy commands" something like "Common commands"

@newhoggy newhoggy force-pushed the newhoggy/era-commands-groups branch from 36f33bb to 1fbf7be Compare July 20, 2023 14:39
pPostConwayCmd envCli =
featureInEra Nothing $ \feature ->
Just
$ subParser "post-conway"
Copy link
Contributor

Choose a reason for hiding this comment

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

So rather than all encompassing "pre/post-conway" commands we should pattern match on the relevant ShelleyToBabbage era/ ConwayOnwards era values and render the appropriate command name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, post-conway is a place holder example. It should be replaced with a command.

, subParser "latest"
$ Opt.info (AnyEraCommandOf BabbageEra <$> pEraBasedCommand envCli BabbageEra)
$ Opt.progDesc "Latest era commands (Babbage)"
, subParser "experimental"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm skeptical of having an experimental set of commands, it will add more churn for not that much benefit. We should just print something to stdout if a command or group of commands is experimental.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

experimental isn't strictly necessary because users wanting to test Conway can still use conway. The cost of having experimental isn't that high though since it is effectively equivalent to conway.

@newhoggy newhoggy force-pushed the newhoggy/era-commands-groups branch from 1fbf7be to 7281f4d Compare July 21, 2023 10:25
@newhoggy newhoggy added this pull request to the merge queue Jul 21, 2023
Merged via the queue into main with commit c1259aa Jul 21, 2023
18 of 22 checks passed
@newhoggy newhoggy deleted the newhoggy/era-commands-groups branch July 21, 2023 11:15
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.

None yet

3 participants