Skip to content

Commit

Permalink
The node commands are era agnostic therefore their type should be Parser
Browse files Browse the repository at this point in the history
(NodeCmds era) and not Maybe (Parser (NodeCmds era))

Remove era parameter from NodeCmds data type
  • Loading branch information
Jimbo4350 committed Oct 7, 2024
1 parent 685c5fd commit bda0cb3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pCmds sbe' envCli = do
, fmap KeyCmds <$> pKeyCmds
, fmap GenesisCmds <$> pGenesisCmds cEra envCli
, fmap GovernanceCmds <$> pGovernanceCmds cEra
, fmap NodeCmds <$> pNodeCmds
, Just (NodeCmds <$> pNodeCmds)
, fmap QueryCmds <$> pQueryCmds cEra envCli
, fmap StakeAddressCmds <$> pStakeAddressCmds cEra envCli
, fmap StakePoolCmds <$> pStakePoolCmds cEra envCli
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Cardano.CLI.Types.Key

import Data.Text (Text)

data NodeCmds era
data NodeCmds
= NodeKeyGenColdCmd !NodeKeyGenColdCmdArgs
| NodeKeyGenKESCmd !NodeKeyGenKESCmdArgs
| NodeKeyGenVRFCmd !NodeKeyGenVRFCmdArgs
Expand Down Expand Up @@ -84,7 +84,7 @@ data NodeIssueOpCertCmdArgs
}
deriving Show

renderNodeCmds :: NodeCmds era -> Text
renderNodeCmds :: NodeCmds -> Text
renderNodeCmds = \case
NodeKeyGenColdCmd{} -> "node key-gen"
NodeKeyGenKESCmd{} -> "node key-gen-KES"
Expand Down
106 changes: 52 additions & 54 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,58 @@ import qualified Options.Applicative as Opt
{- HLINT ignore "Use <$>" -}
{- HLINT ignore "Move brackets to avoid $" -}

pNodeCmds :: Maybe (Parser (NodeCmds era))
pNodeCmds :: Parser NodeCmds
pNodeCmds =
subInfoParser
"node"
( Opt.progDesc $
mconcat
[ "Node operation commands."
let nodeCmdParsers =
asum
[ subParser "key-gen" $
Opt.info pKeyGenOperator $
Opt.progDesc $
mconcat
[ "Create a key pair for a node operator's offline "
, "key and a new certificate issue counter"
]
, subParser "key-gen-KES" $
Opt.info pKeyGenKES $
Opt.progDesc $
mconcat
[ "Create a key pair for a node KES operational key"
]
, subParser "key-gen-VRF" $
Opt.info pKeyGenVRF $
Opt.progDesc $
mconcat
[ "Create a key pair for a node VRF operational key"
]
, subParser "key-hash-VRF" . Opt.info pKeyHashVRF $
Opt.progDesc $
mconcat
[ "Print hash of a node's operational VRF key."
]
, subParser "new-counter" $
Opt.info pNewCounter $
Opt.progDesc $
mconcat
[ "Create a new certificate issue counter"
]
, subParser "issue-op-cert" $
Opt.info pIssueOpCert $
Opt.progDesc $
mconcat
[ "Issue a node operational certificate"
]
]
)
[ Just $
subParser "key-gen" $
Opt.info pKeyGenOperator $
Opt.progDesc $
in subParser
"node"
$ Opt.info
nodeCmdParsers
( Opt.progDesc $
mconcat
[ "Create a key pair for a node operator's offline "
, "key and a new certificate issue counter"
[ "Node operation commands."
]
, Just $
subParser "key-gen-KES" $
Opt.info pKeyGenKES $
Opt.progDesc $
mconcat
[ "Create a key pair for a node KES operational key"
]
, Just $
subParser "key-gen-VRF" $
Opt.info pKeyGenVRF $
Opt.progDesc $
mconcat
[ "Create a key pair for a node VRF operational key"
]
, Just $
subParser "key-hash-VRF" . Opt.info pKeyHashVRF $
Opt.progDesc $
mconcat
[ "Print hash of a node's operational VRF key."
]
, Just $
subParser "new-counter" $
Opt.info pNewCounter $
Opt.progDesc $
mconcat
[ "Create a new certificate issue counter"
]
, Just $
subParser "issue-op-cert" $
Opt.info pIssueOpCert $
Opt.progDesc $
mconcat
[ "Issue a node operational certificate"
]
]
)

pKeyGenOperator :: Parser (NodeCmds era)
pKeyGenOperator :: Parser NodeCmds
pKeyGenOperator =
fmap Cmd.NodeKeyGenColdCmd $
Cmd.NodeKeyGenColdCmdArgs
Expand All @@ -82,30 +80,30 @@ pKeyGenOperator =
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile

pKeyGenKES :: Parser (NodeCmds era)
pKeyGenKES :: Parser NodeCmds
pKeyGenKES =
fmap Cmd.NodeKeyGenKESCmd $
Cmd.NodeKeyGenKESCmdArgs
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pKeyGenVRF :: Parser (NodeCmds era)
pKeyGenVRF :: Parser NodeCmds
pKeyGenVRF =
fmap Cmd.NodeKeyGenVRFCmd $
Cmd.NodeKeyGenVRFCmdArgs
<$> pKeyOutputFormat
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pKeyHashVRF :: Parser (NodeCmds era)
pKeyHashVRF :: Parser NodeCmds
pKeyHashVRF =
fmap Cmd.NodeKeyHashVRFCmd $
Cmd.NodeKeyHashVRFCmdArgs
<$> pVerificationKeyOrFileIn AsVrfKey
<*> pMaybeOutputFile

pNewCounter :: Parser (NodeCmds era)
pNewCounter :: Parser NodeCmds
pNewCounter =
fmap Cmd.NodeNewCounterCmd $
Cmd.NodeNewCounterCmdArgs
Expand All @@ -122,7 +120,7 @@ pCounterValue =
, Opt.help "The next certificate issue counter value to use."
]

pIssueOpCert :: Parser (NodeCmds era)
pIssueOpCert :: Parser NodeCmds
pIssueOpCert =
fmap Cmd.NodeIssueOpCertCmd $
Cmd.NodeIssueOpCertCmdArgs
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Data.Word (Word64)

runNodeCmds
:: ()
=> Cmd.NodeCmds era
=> Cmd.NodeCmds
-> ExceptT NodeCmdError IO ()
runNodeCmds = \case
Cmd.NodeKeyGenColdCmd args -> runNodeKeyGenColdCmd args
Expand Down

0 comments on commit bda0cb3

Please sign in to comment.