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

Regularise era based command structure #279

Merged
merged 12 commits into from
Sep 24, 2023

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Sep 14, 2023

Changelog

- description: |
    Regularise era based command structure
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

The main change in this PR is to change command parsers to return Maybe (Parser a) instead of Parser a.

This is based on the principle that commands themselves should determined whether they exist in a given era. This principle is used in the new Conway commands and will see more use in the future.

Requiring that all command groups accept Maybe (Parser a) will mean that any new or existing commands can become era-sensitive without inducing refactoring. As it is at the moment if a command needs to become era-sensitive, the parent command group will need to be refactored to accomodate it if it doesn't already which is the case for a number top-level commands groups.

The PR also contains a small number of help text fixes.

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
    • round trip tests
    • integration tests
      See Running 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

@newhoggy newhoggy force-pushed the newhoggy/regularise-era-based-command-structure branch 6 times, most recently from 475f2c7 to 67a8c96 Compare September 15, 2023 01:05
@newhoggy newhoggy marked this pull request as ready for review September 15, 2023 06:35
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt

pAddressCmds :: CardanoEra era -> EnvCli -> Parser (AddressCmds era)
pAddressCmds _ envCli =
asum
[ subParser "key-gen"
asum $ catMaybes
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 think this is necessary as these commands will be available in every era unless e.g the crypto changes.

@@ -27,50 +27,61 @@ import qualified Options.Applicative as Opt

pGenesisCmds :: EnvCli -> Parser (GenesisCmds era)
pGenesisCmds envCli =
asum
[ subParser "key-gen-genesis"
asum $ catMaybes
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 not sure I understand the reason for this change.

[ "Genesis block commands."
]
)
[ Just
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change from asum?

Copy link
Contributor Author

@newhoggy newhoggy Sep 22, 2023

Choose a reason for hiding this comment

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

asum is in the implementation of subInfoParser so we are still calling asum indirectly:

subInfoParser :: String -> InfoMod a -> [Maybe (Parser a)] -> Maybe (Parser a)
subInfoParser name i mps = case catMaybes mps of
  [] -> Nothing
  parsers -> Just $ subParser name $ Opt.info (asum parsers) i

subInfoParser is used instead so that commands are self-describing. Previously the implementation of the parent command group provided the description.

-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetConstitutionCmd env era = do
pGovernanceQueryGetConstitutionCmd era env = do
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

pKeyCmds =
asum
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change from Parser (..) -> Maybe (Parser (...))

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 change represents a shift of responsibilities.

Previously it was the parent command group that decides whether the command should appear in an era.

The change shifts the responsibility from the parent to the command in question. ie the command itself determines whether or not it should show up in a given era.

This is already how it is done for the governance commands and some other commands.

The purpose of this PR is to harmonise our code base to consistently use the latter convention.

@Jimbo4350 Jimbo4350 self-requested a review September 15, 2023 11:52
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

Some questions

@newhoggy newhoggy requested a review from Jimbo4350 September 16, 2023 07:57
@newhoggy newhoggy force-pushed the newhoggy/regularise-era-based-command-structure branch 3 times, most recently from 6f26556 to a3aafd8 Compare September 22, 2023 08:54
@newhoggy newhoggy dismissed Jimbo4350’s stale review September 22, 2023 09:03

Respond to question

@newhoggy newhoggy force-pushed the newhoggy/regularise-era-based-command-structure branch from a3aafd8 to c51ec79 Compare September 24, 2023 02:04
@newhoggy newhoggy enabled auto-merge September 24, 2023 02:06
@newhoggy newhoggy added this pull request to the merge queue Sep 24, 2023
Merged via the queue into main with commit 48aae22 Sep 24, 2023
19 checks passed
@newhoggy newhoggy deleted the newhoggy/regularise-era-based-command-structure branch September 24, 2023 02:32
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.

3 participants