Skip to content

Commit

Permalink
Merge pull request #279 from input-output-hk/newhoggy/regularise-era-…
Browse files Browse the repository at this point in the history
…based-command-structure

Regularise era based command structure
  • Loading branch information
newhoggy authored Sep 24, 2023
2 parents d9dddc5 + c51ec79 commit 48aae22
Show file tree
Hide file tree
Showing 77 changed files with 523 additions and 371 deletions.
63 changes: 18 additions & 45 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,67 +88,40 @@ pAnyEraCommand envCli =
[ -- Note, byron is ommitted because there is already a legacy command group for it.

subParser "shelley"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraShelley <$> pCmds envCli ShelleyEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraShelley <$> pCmds ShelleyEra envCli)
$ Opt.progDesc "Shelley era commands"
, subParser "allegra"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraAllegra <$> pCmds envCli AllegraEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraAllegra <$> pCmds AllegraEra envCli)
$ Opt.progDesc "Allegra era commands"
, subParser "mary"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraMary <$> pCmds envCli MaryEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraMary <$> pCmds MaryEra envCli)
$ Opt.progDesc "Mary era commands"
, subParser "alonzo"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraAlonzo <$> pCmds envCli AlonzoEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraAlonzo <$> pCmds AlonzoEra envCli)
$ Opt.progDesc "Alonzo era commands"
, subParser "babbage"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraBabbage <$> pCmds envCli BabbageEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraBabbage <$> pCmds BabbageEra envCli)
$ Opt.progDesc "Babbage era commands"
, subParser "conway"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraConway <$> pCmds envCli ConwayEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraConway <$> pCmds ConwayEra envCli)
$ Opt.progDesc "Conway era commands"

, subParser "latest"
$ Opt.info (AnyEraCommandOf ShelleyBasedEraBabbage <$> pCmds envCli BabbageEra)
$ Opt.info (AnyEraCommandOf ShelleyBasedEraBabbage <$> pCmds BabbageEra envCli)
$ Opt.progDesc "Latest era commands (Babbage)"
]

pCmds :: EnvCli -> CardanoEra era -> Parser (Cmds era)
pCmds envCli era =
pCmds :: CardanoEra era -> EnvCli -> Parser (Cmds era)
pCmds era envCli =
asum $ catMaybes
[ Just
$ subParser "address"
$ Opt.info (AddressCmds <$> pAddressCmds era envCli)
$ Opt.progDesc "Era-based address commands"
, Just
$ subParser "key"
$ Opt.info (KeyCmds <$> pKeyCmds)
$ Opt.progDesc "Era-based key commands"
, Just
$ subParser "genesis"
$ Opt.info (GenesisCmds <$> pGenesisCmds envCli)
$ Opt.progDesc "Era-based genesis commands"
, Just
$ subParser "governance"
$ Opt.info (GovernanceCmds <$> pGovernanceCmds envCli era)
$ Opt.progDesc "Era-based governance commands"
, Just
$ subParser "node"
$ Opt.info (NodeCmds <$> pNodeCmds)
$ Opt.progDesc "Era-based node commands"
, Just
$ subParser "query"
$ Opt.info (QueryCmds <$> pQueryCmds envCli)
$ Opt.progDesc "Era-based query commands"
[ fmap AddressCmds <$> pAddressCmds era envCli
, fmap KeyCmds <$> pKeyCmds
, fmap GenesisCmds <$> pGenesisCmds envCli
, fmap GovernanceCmds <$> pGovernanceCmds era envCli
, fmap NodeCmds <$> pNodeCmds
, fmap QueryCmds <$> pQueryCmds envCli
, fmap StakeAddressCmds <$> pStakeAddressCmds era envCli
, Just
$ subParser "stake-pool"
$ Opt.info (StakePoolCmds <$> pStakePoolCmds era envCli)
$ Opt.progDesc "Era-based stake pool commands"
, Just
$ subParser "text-view"
$ Opt.info (TextViewCmds <$> pTextViewCmds)
$ Opt.progDesc "Era-based text view commands"
, Just
$ subParser "transaction"
$ Opt.info (TransactionCmds <$> pTransactionCmds envCli era)
$ Opt.progDesc "Era-based transaction commands"
, fmap StakePoolCmds <$> pStakePoolCmds era envCli
, fmap TextViewCmds <$> pTextViewCmds
, fmap TransactionCmds <$> pTransactionCmds era envCli
]
25 changes: 18 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@ import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.EraBased.Commands.Address
import Cardano.CLI.EraBased.Options.Common

import Data.Foldable
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt

pAddressCmds :: CardanoEra era -> EnvCli -> Parser (AddressCmds era)
pAddressCmds :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (AddressCmds era))
pAddressCmds _ envCli =
asum
[ subParser "key-gen"
subInfoParser "address"
( Opt.progDesc
$ mconcat
[ "Payment address commands."
]
)
[ Just
$ subParser "key-gen"
$ Opt.info pAddressKeyGen
$ Opt.progDesc "Create an address key pair."
, subParser "key-hash"
, Just
$ subParser "key-hash"
$ Opt.info pAddressKeyHash
$ Opt.progDesc "Print the hash of an address key."
, subParser "build"
, Just
$ subParser "build"
$ Opt.info (pAddressBuild envCli)
$ Opt.progDesc "Build a Shelley payment address, with optional delegation to a stake address."
, subParser "info"
, Just
$ subParser "info"
$ Opt.info pAddressInfo
$ Opt.progDesc "Print information about an address."
]
Expand Down
47 changes: 32 additions & 15 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,78 @@ import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Parser
import Cardano.CLI.Types.Common

import Data.Foldable
import Data.Maybe (fromMaybe)
import Data.Maybe
import Data.Word (Word64)
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt

{- HLINT ignore "Use <$>" -}
{- HLINT ignore "Move brackets to avoid $" -}

pGenesisCmds :: EnvCli -> Parser (GenesisCmds era)
pGenesisCmds :: ()
=> EnvCli
-> Maybe (Parser (GenesisCmds era))
pGenesisCmds envCli =
asum
[ subParser "key-gen-genesis"
subInfoParser "genesis"
( Opt.progDesc
$ mconcat
[ "Genesis block commands."
]
)
[ Just
$ subParser "key-gen-genesis"
$ Opt.info pGenesisKeyGen
$ Opt.progDesc "Create a Shelley genesis key pair"
, subParser "key-gen-delegate"
, Just
$ subParser "key-gen-delegate"
$ Opt.info pGenesisDelegateKeyGen
$ Opt.progDesc "Create a Shelley genesis delegate key pair"
, subParser "key-gen-utxo"
, Just
$ subParser "key-gen-utxo"
$ Opt.info pGenesisUTxOKeyGen
$ Opt.progDesc "Create a Shelley genesis UTxO key pair"
, subParser "key-hash"
, Just
$ subParser "key-hash"
$ Opt.info pGenesisKeyHash
$ Opt.progDesc "Print the identifier (hash) of a public key"
, subParser "get-ver-key"
, Just
$ subParser "get-ver-key"
$ Opt.info pGenesisVerKey
$ Opt.progDesc "Derive the verification key from a signing key"
, subParser "initial-addr"
, Just
$ subParser "initial-addr"
$ Opt.info (pGenesisAddr envCli)
$ Opt.progDesc "Get the address for an initial UTxO based on the verification key"
, subParser "initial-txin"
, Just
$ subParser "initial-txin"
$ Opt.info (pGenesisTxIn envCli)
$ Opt.progDesc "Get the TxIn for an initial UTxO based on the verification key"
, subParser "create-cardano"
, Just
$ subParser "create-cardano"
$ Opt.info (pGenesisCreateCardano envCli)
$ Opt.progDesc
$ mconcat
[ "Create a Byron and Shelley genesis file from a genesis "
, "template and genesis/delegation/spending keys."
]
, subParser "create"
, Just
$ subParser "create"
$ Opt.info (pGenesisCreate envCli)
$ Opt.progDesc
$ mconcat
[ "Create a Shelley genesis file from a genesis "
, "template and genesis/delegation/spending keys."
]
, subParser "create-staked"
, Just
$ subParser "create-staked"
$ Opt.info (pGenesisCreateStaked envCli)
$ Opt.progDesc
$ mconcat
[ "Create a staked Shelley genesis file from a genesis "
, "template and genesis/delegation/spending keys."
]
, subParser "hash"
, Just
$ subParser "hash"
$ Opt.info pGenesisHash
$ Opt.progDesc "Compute the hash of a genesis file"
]
Expand Down
19 changes: 13 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ import Cardano.CLI.EraBased.Options.Governance.Vote
import Cardano.CLI.Types.Common

import Data.Foldable
import Data.Maybe
import Options.Applicative
import qualified Options.Applicative as Opt

pGovernanceCmds :: EnvCli -> CardanoEra era -> Parser (GovernanceCmds era)
pGovernanceCmds envCli era =
asum $ catMaybes
pGovernanceCmds :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceCmds era))
pGovernanceCmds era envCli =
subInfoParser "governance"
( Opt.progDesc
$ mconcat
[ "Governance commands."
]
)
[ pCreateMirCertificatesCmds era
, fmap GovernanceQueryCmds <$> pGovernanceQueryCmds envCli era
, fmap GovernanceQueryCmds <$> pGovernanceQueryCmds era envCli
, fmap GovernanceActionCmds <$> pGovernanceActionCmds era
, fmap GovernanceCommitteeCmds <$> pGovernanceCommitteeCmds era
, fmap GovernanceDRepCmds <$> pGovernanceDRepCmds envCli era
, fmap GovernanceDRepCmds <$> pGovernanceDRepCmds era envCli
, fmap GovernanceVoteCmds <$> pGovernanceVoteCmds era
]

Expand Down
14 changes: 7 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import Options.Applicative (Parser)
import qualified Options.Applicative as Opt

pGovernanceDRepCmds :: ()
=> EnvCli
-> CardanoEra era
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceDRepCmds era))
pGovernanceDRepCmds envCli era =
pGovernanceDRepCmds era envCli =
subInfoParser "drep"
( Opt.progDesc
$ mconcat
Expand All @@ -36,7 +36,7 @@ pGovernanceDRepCmds envCli era =
)
[ pGovernanceDRepKeyGenCmd era
, pGovernanceDRepKeyIdCmd era
, pRegistrationCertificateCmd envCli era
, pRegistrationCertificateCmd era envCli
]

pGovernanceDRepKeyGenCmd :: ()
Expand Down Expand Up @@ -83,10 +83,10 @@ pDRepIdOutputFormat =
-- Registration Certificate related

pRegistrationCertificateCmd :: ()
=> EnvCli
-> CardanoEra era
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceDRepCmds era))
pRegistrationCertificateCmd envCli era = do
pRegistrationCertificateCmd era envCli = do
w <- maybeFeatureInEra era
pure
$ subParser "registration-certificate"
Expand Down
59 changes: 29 additions & 30 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@ import Cardano.CLI.EraBased.Options.Common
import Options.Applicative
import qualified Options.Applicative as Opt

pGovernanceQueryCmds
:: ()
=> EnvCli
-> CardanoEra era
pGovernanceQueryCmds :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryCmds env era =
pGovernanceQueryCmds era env =
subInfoParser "query"
( Opt.progDesc "Query governance-related information" )
[ pGovernanceQueryGetConstitutionCmd env era
, pGovernanceQueryGetGovStateCmd env era
, pGovernanceQueryDRepStateCmd env era
, pGovernanceQueryDRepStakeDistributionCmd env era
, pGovernanceQueryGetCommitteeStateCmd env era
[ pGovernanceQueryGetConstitutionCmd era env
, pGovernanceQueryGetGovStateCmd era env
, pGovernanceQueryDRepStateCmd era env
, pGovernanceQueryDRepStakeDistributionCmd era env
, pGovernanceQueryGetCommitteeStateCmd era env
]

pGovernanceQueryGetConstitutionCmd
:: EnvCli
-> CardanoEra era
pGovernanceQueryGetConstitutionCmd :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetConstitutionCmd env era = do
pGovernanceQueryGetConstitutionCmd era env = do
cOn <- maybeFeatureInEra era
pure
$ subParser "constitution"
$ Opt.info (GovernanceQueryConstitutionCmd cOn <$> pNoArgQueryCmd env)
$ Opt.progDesc "Get the constitution"

pGovernanceQueryGetGovStateCmd
:: EnvCli
-> CardanoEra era
pGovernanceQueryGetGovStateCmd :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetGovStateCmd env era = do
pGovernanceQueryGetGovStateCmd era env = do
cOn <- maybeFeatureInEra era
pure
$ subParser "gov-state"
Expand All @@ -56,11 +55,11 @@ pGovernanceQueryGetGovStateCmd env era = do
-- What about 'DRep c' - this means that only 'KeyHash' constructor is in use here: should also
-- 'DRepAlwaysAbstain' and 'DRepAlwaysNoConfidence' be supported here?

pGovernanceQueryDRepStateCmd
:: EnvCli
-> CardanoEra era
pGovernanceQueryDRepStateCmd :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryDRepStateCmd env era = do
pGovernanceQueryDRepStateCmd era env = do
cOn <- maybeFeatureInEra era
pure
$ subParser "drep-state"
Expand All @@ -75,11 +74,11 @@ pGovernanceQueryDRepStateCmd env era = do
<*> some pDRepVerificationKeyOrHashOrFile
<*> optional pOutputFile

pGovernanceQueryDRepStakeDistributionCmd
:: EnvCli
-> CardanoEra era
pGovernanceQueryDRepStakeDistributionCmd :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryDRepStakeDistributionCmd env era = do
pGovernanceQueryDRepStakeDistributionCmd era env = do
cOn <- maybeFeatureInEra era
pure
$ subParser "drep-stake-distribution"
Expand All @@ -94,11 +93,11 @@ pGovernanceQueryDRepStakeDistributionCmd env era = do
<*> some pDRepVerificationKeyOrHashOrFile
<*> optional pOutputFile

pGovernanceQueryGetCommitteeStateCmd
:: EnvCli
-> CardanoEra era
pGovernanceQueryGetCommitteeStateCmd :: ()
=> CardanoEra era
-> EnvCli
-> Maybe (Parser (GovernanceQueryCmds era))
pGovernanceQueryGetCommitteeStateCmd env era = do
pGovernanceQueryGetCommitteeStateCmd era env = do
cOn <- maybeFeatureInEra era
pure
$ subParser "committee-state"
Expand Down
Loading

0 comments on commit 48aae22

Please sign in to comment.