-
Notifications
You must be signed in to change notification settings - Fork 15
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
Regularise era based command structure #279
Conversation
475f2c7
to
67a8c96
Compare
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 |
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 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 |
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'm not sure I understand the reason for this change.
[ "Genesis block commands." | ||
] | ||
) | ||
[ Just |
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.
Why the change from asum
?
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.
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 |
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.
👍
pKeyCmds = | ||
asum |
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.
Why the change from Parser (..)
-> Maybe (Parser (...))
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.
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.
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.
Some questions
6f26556
to
a3aafd8
Compare
a3aafd8
to
c51ec79
Compare
Changelog
Context
The main change in this PR is to change command parsers to return
Maybe (Parser a)
instead ofParser 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
See Running tests for more details
.cabal
files are updatedhlint
. See.github/workflows/check-hlint.yml
to get thehlint
versionstylish-haskell
. See.github/workflows/stylish-haskell.yml
to get thestylish-haskell
versionghc-8.10.7
andghc-9.2.7