Skip to content

Commit

Permalink
Merge pull request #934 from IntersectMBO/jordan/move-address-command…
Browse files Browse the repository at this point in the history
…s-to-top-level

      Move address commands to top level
  • Loading branch information
Jimbo4350 authored Oct 11, 2024
2 parents a3f93bc + 1464112 commit 746a580
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 97 deletions.
8 changes: 4 additions & 4 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ library
Cardano.CLI.Byron.UpdateProposal
Cardano.CLI.Byron.Vote
Cardano.CLI.Commands
Cardano.CLI.Commands.Address
Cardano.CLI.Commands.Debug
Cardano.CLI.Commands.Debug.LogEpochState
Cardano.CLI.Commands.Debug.TransactionView
Expand All @@ -67,7 +68,6 @@ library
Cardano.CLI.Commands.Ping
Cardano.CLI.Environment
Cardano.CLI.EraBased.Commands
Cardano.CLI.EraBased.Commands.Address
Cardano.CLI.EraBased.Commands.Genesis
Cardano.CLI.EraBased.Commands.Governance
Cardano.CLI.EraBased.Commands.Governance.Actions
Expand All @@ -80,7 +80,6 @@ library
Cardano.CLI.EraBased.Commands.StakePool
Cardano.CLI.EraBased.Commands.TextView
Cardano.CLI.EraBased.Commands.Transaction
Cardano.CLI.EraBased.Options.Address
Cardano.CLI.EraBased.Options.Common
Cardano.CLI.EraBased.Options.Genesis
Cardano.CLI.EraBased.Options.Governance
Expand All @@ -95,8 +94,6 @@ library
Cardano.CLI.EraBased.Options.TextView
Cardano.CLI.EraBased.Options.Transaction
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Address
Cardano.CLI.EraBased.Run.Address.Info
Cardano.CLI.EraBased.Run.Genesis
Cardano.CLI.EraBased.Run.Genesis.Common
Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData
Expand Down Expand Up @@ -125,6 +122,7 @@ library
Cardano.CLI.Legacy.Run.Governance
Cardano.CLI.OS.Posix
Cardano.CLI.Options
Cardano.CLI.Options.Address
Cardano.CLI.Options.Debug
Cardano.CLI.Options.Hash
Cardano.CLI.Options.Key
Expand All @@ -136,6 +134,8 @@ library
Cardano.CLI.Read
Cardano.CLI.Render
Cardano.CLI.Run
Cardano.CLI.Run.Address
Cardano.CLI.Run.Address.Info
Cardano.CLI.Run.Debug
Cardano.CLI.Run.Debug.LogEpochState
Cardano.CLI.Run.Debug.TransactionView
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Cardano.CLI.Commands
where

import Cardano.CLI.Byron.Commands (ByronCommand)
import Cardano.CLI.Commands.Address
import Cardano.CLI.Commands.Debug
import Cardano.CLI.Commands.Hash (HashCmds)
import Cardano.CLI.Commands.Key
Expand All @@ -19,6 +20,7 @@ import Options.Applicative.Types (ParserInfo (..), ParserPrefs (..))
-- | Sub-commands of 'cardano-cli'.
data ClientCommand
= AnyEraCommand AnyEraCommand
| AddressCommand AddressCmds
| -- | Byron Related Commands
ByronCommand ByronCommand
| -- | Era agnostic hashing commands
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.Address
module Cardano.CLI.Commands.Address
( AddressCmds (..)
, renderAddressCmds
)
Expand All @@ -16,7 +16,7 @@ import Prelude

import Data.Text (Text)

data AddressCmds era
data AddressCmds
= AddressKeyGen
KeyOutputFormat
AddressKeyType
Expand All @@ -35,7 +35,7 @@ data AddressCmds era
(Maybe (File () Out))
deriving Show

renderAddressCmds :: AddressCmds era -> Text
renderAddressCmds :: AddressCmds -> Text
renderAddressCmds = \case
AddressKeyGen{} -> "address key-gen"
AddressKeyHash{} -> "address key-hash"
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ where

import Cardano.Api (ShelleyBasedEra (..), toCardanoEra)

import Cardano.CLI.Commands.Address
import Cardano.CLI.Commands.Key
import Cardano.CLI.Commands.Node
import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.Address
import Cardano.CLI.EraBased.Commands.Genesis
import Cardano.CLI.EraBased.Commands.Query
import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.EraBased.Commands.StakePool hiding (sbe)
import Cardano.CLI.EraBased.Commands.TextView
import Cardano.CLI.EraBased.Commands.Transaction
import Cardano.CLI.EraBased.Options.Address
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Genesis
import Cardano.CLI.EraBased.Options.Governance
Expand All @@ -32,6 +31,7 @@ import Cardano.CLI.EraBased.Options.StakeAddress
import Cardano.CLI.EraBased.Options.StakePool
import Cardano.CLI.EraBased.Options.TextView
import Cardano.CLI.EraBased.Options.Transaction
import Cardano.CLI.Options.Address
import Cardano.CLI.Options.Key
import Cardano.CLI.Options.Node

Expand All @@ -50,7 +50,7 @@ renderAnyEraCommand = \case
AnyEraCommandOf _ cmd -> renderCmds cmd

data Cmds era
= AddressCmds (AddressCmds era)
= AddressCmds AddressCmds
| KeyCmds KeyCmds
| GenesisCmds (GenesisCmds era)
| GovernanceCmds (GovernanceCmds era)
Expand Down Expand Up @@ -117,7 +117,7 @@ pCmds sbe' envCli = do
let cEra = toCardanoEra sbe'
asum $
catMaybes
[ fmap AddressCmds <$> pAddressCmds cEra envCli
[ Just (AddressCmds <$> pAddressCmds envCli)
, Just (KeyCmds <$> pKeyCmds)
, fmap GenesisCmds <$> pGenesisCmds cEra envCli
, fmap GovernanceCmds <$> pGovernanceCmds cEra
Expand Down
77 changes: 0 additions & 77 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Address.hs

This file was deleted.

2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ where
import Cardano.Api

import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Run.Address
import Cardano.CLI.EraBased.Run.Genesis
import Cardano.CLI.EraBased.Run.Governance
import Cardano.CLI.EraBased.Run.Query
Expand All @@ -20,6 +19,7 @@ import Cardano.CLI.EraBased.Run.StakePool
import Cardano.CLI.EraBased.Run.TextView
import Cardano.CLI.EraBased.Run.Transaction
import Cardano.CLI.Helpers (printEraDeprecationWarning)
import Cardano.CLI.Run.Address
import Cardano.CLI.Run.Key
import Cardano.CLI.Run.Node
import Cardano.CLI.Types.Errors.CmdError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import Cardano.Api.Shelley
import qualified Cardano.CLI.Commands.Node as Cmd
import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
import Cardano.CLI.EraBased.Run.Address (generateAndWriteKeyFiles)
import Cardano.CLI.EraBased.Run.Genesis.Common
import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep
import Cardano.CLI.EraBased.Run.StakeAddress (runStakeAddressKeyGenCmd)
import qualified Cardano.CLI.IO.Lazy as Lazy
import Cardano.CLI.Run.Address (generateAndWriteKeyFiles)
import qualified Cardano.CLI.Run.Key as Key
import Cardano.CLI.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd,
runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd)
Expand Down
7 changes: 6 additions & 1 deletion cardano-cli/src/Cardano/CLI/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Cardano.CLI.Environment (EnvCli)
import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Legacy.Options (parseLegacyCmds)
import Cardano.CLI.Options.Address
import Cardano.CLI.Options.Debug
import Cardano.CLI.Options.Hash
import Cardano.CLI.Options.Key
Expand Down Expand Up @@ -49,6 +50,9 @@ pref =
, helpRenderHelp customRenderHelp
]

addressCmdsTopLevel :: EnvCli -> Parser ClientCommand
addressCmdsTopLevel envCli = AddressCommand <$> pAddressCmds envCli

-- The node related commands are shelley era agnostic for the time being.
-- There is no need to guard them by the era argument.
nodeCmdsTopLevel :: Parser ClientCommand
Expand All @@ -63,7 +67,8 @@ parseClientCommand envCli =
-- There are name clashes between Shelley commands and the Byron backwards
-- compat commands (e.g. "genesis"), and we need to prefer the Shelley ones
-- so we list it first.
[ keyCmdsTopLevel
[ addressCmdsTopLevel envCli
, keyCmdsTopLevel
, nodeCmdsTopLevel
, parseLegacy envCli
, parseByron envCli
Expand Down
75 changes: 75 additions & 0 deletions cardano-cli/src/Cardano/CLI/Options/Address.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.Options.Address
( pAddressCmds
)
where

import Cardano.CLI.Commands.Address
import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.EraBased.Options.Common

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

pAddressCmds
:: ()
=> EnvCli
-> Parser AddressCmds
pAddressCmds envCli =
let addressParsers =
asum
[ subParser "key-gen" $
Opt.info pAddressKeyGen $
Opt.progDesc "Create an address key pair."
, subParser "key-hash" $
Opt.info pAddressKeyHash $
Opt.progDesc "Print the hash of an address key."
, subParser "build" $
Opt.info (pAddressBuild envCli) $
Opt.progDesc "Build a Shelley payment address, with optional delegation to a stake address."
, subParser "info" $
Opt.info pAddressInfo $
Opt.progDesc "Print information about an address."
]
in subParser
"address"
$ Opt.info
addressParsers
( Opt.progDesc $
mconcat
[ "Payment address commands."
]
)

pAddressKeyGen :: Parser AddressCmds
pAddressKeyGen =
AddressKeyGen
<$> pKeyOutputFormat
<*> pAddressKeyType
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut

pAddressKeyHash :: Parser AddressCmds
pAddressKeyHash =
AddressKeyHash
<$> pPaymentVerificationKeyTextOrFile
<*> pMaybeOutputFile

pAddressBuild :: EnvCli -> Parser AddressCmds
pAddressBuild envCli =
AddressBuild
<$> pPaymentVerifier
<*> Opt.optional (pStakeIdentifier Nothing)
<*> pNetworkId envCli
<*> pMaybeOutputFile

pAddressInfo :: Parser AddressCmds
pAddressInfo =
AddressInfo
<$> pAddress
<*> pMaybeOutputFile
7 changes: 7 additions & 0 deletions cardano-cli/src/Cardano/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import Cardano.CLI.EraBased.Run
import Cardano.CLI.Legacy.Commands
import Cardano.CLI.Legacy.Run (runLegacyCmds)
import Cardano.CLI.Render (customRenderHelp)
import Cardano.CLI.Run.Address
import Cardano.CLI.Run.Debug
import Cardano.CLI.Run.Hash (runHashCmds)
import Cardano.CLI.Run.Key
import Cardano.CLI.Run.Node
import Cardano.CLI.Run.Ping (PingClientCmdError (..), renderPingClientCmdError,
runPingCmd)
import Cardano.CLI.Types.Errors.AddressCmdError
import Cardano.CLI.Types.Errors.CmdError
import Cardano.CLI.Types.Errors.HashCmdError
import Cardano.CLI.Types.Errors.KeyCmdError
Expand All @@ -50,6 +52,7 @@ import Paths_cardano_cli (version)

data ClientCommandErrors
= ByronClientError ByronClientCmdError
| AddressCmdError AddressCmdError
| CmdError Text CmdError
| HashCmdError HashCmdError
| KeyCmdError KeyCmdError
Expand All @@ -61,6 +64,8 @@ runClientCommand :: ClientCommand -> ExceptT ClientCommandErrors IO ()
runClientCommand = \case
AnyEraCommand cmds ->
firstExceptT (CmdError (renderAnyEraCommand cmds)) $ runAnyEraCommand cmds
AddressCommand cmds ->
firstExceptT AddressCmdError $ runAddressCmds cmds
NodeCommands cmds ->
runNodeCmds cmds
& firstExceptT NodeCmdError
Expand All @@ -87,6 +92,8 @@ renderClientCommandError = \case
renderCmdError cmdText err
ByronClientError err ->
renderByronClientCmdError err
AddressCmdError err ->
renderAddressCmdError err
HashCmdError err ->
prettyError err
NodeCmdError err ->
Expand Down
Loading

0 comments on commit 746a580

Please sign in to comment.