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

Refactor #950

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cardano-cli/app/cardano-cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#define UNIX
#endif

import Cardano.CLI.Pretty

import Cardano.Api
import Cardano.CLI.Environment (getEnvCli)
import Cardano.CLI.Options (opts, pref)
import Cardano.CLI.Run (renderClientCommandError, runClientCommand)
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ library
Cardano.CLI.Compatible.Run
Cardano.CLI.Compatible.Transaction
Cardano.CLI.Environment
Cardano.CLI.EraBased.Commands
Cardano.CLI.EraBased.Commands.Genesis
Cardano.CLI.EraBased.Commands.Governance
Cardano.CLI.EraBased.Commands.Governance.Actions
Expand All @@ -83,8 +82,10 @@ library
Cardano.CLI.EraBased.Commands.StakeAddress
Cardano.CLI.EraBased.Commands.StakePool
Cardano.CLI.EraBased.Commands.TextView
Cardano.CLI.EraBased.Commands.TopLevelCommands
Cardano.CLI.EraBased.Commands.Transaction
Cardano.CLI.EraBased.Options.Common
Cardano.CLI.EraBased.Options.Era
Cardano.CLI.EraBased.Options.Genesis
Cardano.CLI.EraBased.Options.Governance
Cardano.CLI.EraBased.Options.Governance.Actions
Expand All @@ -96,6 +97,7 @@ library
Cardano.CLI.EraBased.Options.StakeAddress
Cardano.CLI.EraBased.Options.StakePool
Cardano.CLI.EraBased.Options.TextView
Cardano.CLI.EraBased.Options.TopLevelCommands
Cardano.CLI.EraBased.Options.Transaction
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Genesis
Expand All @@ -114,7 +116,6 @@ library
Cardano.CLI.EraBased.Run.TextView
Cardano.CLI.EraBased.Run.Transaction
Cardano.CLI.Helpers
Cardano.CLI.IO.Compat
Cardano.CLI.IO.Lazy
Cardano.CLI.Json.Friendly
Cardano.CLI.Legacy.Commands
Expand All @@ -134,7 +135,6 @@ library
Cardano.CLI.Options.Ping
Cardano.CLI.Orphans
Cardano.CLI.Parser
Cardano.CLI.Pretty
Cardano.CLI.Read
Cardano.CLI.Render
Cardano.CLI.Run
Expand Down Expand Up @@ -260,6 +260,7 @@ executable cardano-cli
-with-rtsopts=-T

build-depends:
cardano-api,
cardano-cli,
cardano-crypto-class ^>=2.1.2,
optparse-applicative-fork,
Expand Down Expand Up @@ -394,7 +395,6 @@ test-suite cardano-cli-golden
tasty-hedgehog,
text,
time,
transformers,
unordered-containers,

build-tool-depends:
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Byron/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ module Cardano.CLI.Byron.Genesis
)
where

import Cardano.Api (Key (..), NetworkId, writeSecrets)
import Cardano.Api (Doc, Key (..), NetworkId, pretty, pshow, writeSecrets)
import Cardano.Api.Byron (ByronKey, SerialiseAsRawBytes (..), SigningKey (..),
toByronRequiresNetworkMagic)
import qualified Cardano.Api.Byron as Byron

import Cardano.CLI.Byron.Delegation
import Cardano.CLI.Byron.Key
import Cardano.CLI.Pretty
import Cardano.CLI.Types.Common (GenesisFile (..))
import qualified Cardano.Crypto as Crypto
import Cardano.Prelude (canonicalDecodePretty, canonicalEncodePretty)

import Control.Monad.IO.Class
import Control.Monad.Trans (MonadTrans (..))
import Control.Monad.Trans.Except (ExceptT (..), withExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, left, right)
Expand Down
5 changes: 1 addition & 4 deletions cardano-cli/src/Cardano/CLI/Byron/UpdateProposal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Cardano.CLI.Byron.UpdateProposal
)
where

import Cardano.Api (NetworkId, SerialiseAsRawBytes (..), SocketPath)
import Cardano.Api
import Cardano.Api.Byron (AsType (AsByronUpdateProposal), ByronProtocolParametersUpdate,
ByronUpdateProposal, makeByronUpdateProposal, toByronLedgerUpdateProposal)
import qualified Cardano.Api.Byron as Byron
Expand All @@ -20,14 +20,11 @@ import Cardano.CLI.Byron.Genesis (ByronGenesisError)
import Cardano.CLI.Byron.Key (ByronKeyFailure, readByronSigningKey)
import Cardano.CLI.Byron.Tx (ByronTxError, nodeSubmitTx)
import Cardano.CLI.Helpers (HelpersError, ensureNewFileLBS, renderHelpersError)
import Cardano.CLI.Pretty
import Cardano.CLI.Types.Common
import Ouroboros.Consensus.Ledger.SupportsMempool (txId)
import Ouroboros.Consensus.Util.Condense (condense)

import Control.Exception (Exception (..))
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither)
import Control.Tracer (stdoutTracer, traceWith)
import Data.Bifunctor (Bifunctor (..))
import qualified Data.ByteString as BS
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import Cardano.CLI.Commands.Key
import Cardano.CLI.Commands.Node
import Cardano.CLI.Commands.Ping (PingCmd (..))
import Cardano.CLI.Compatible.Commands
import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Commands.Query
import Cardano.CLI.EraBased.Commands.TopLevelCommands
import Cardano.CLI.Legacy.Commands

import Options.Applicative.Types (ParserInfo (..), ParserPrefs (..))
Expand Down
132 changes: 0 additions & 132 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands.hs

This file was deleted.

68 changes: 68 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/TopLevelCommands.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.EraBased.Commands.TopLevelCommands
( AnyEraCommand (..)
, Cmds (..)
, renderAnyEraCommand
, renderCmds
)
where

import Cardano.Api (ShelleyBasedEra (..))

import Cardano.CLI.Commands.Address
import Cardano.CLI.Commands.Key
import Cardano.CLI.Commands.Node
import Cardano.CLI.EraBased.Commands.Genesis
import Cardano.CLI.EraBased.Commands.Query
import Cardano.CLI.EraBased.Commands.StakeAddress
import Cardano.CLI.EraBased.Commands.StakePool
import Cardano.CLI.EraBased.Commands.TextView
import Cardano.CLI.EraBased.Commands.Transaction
import Cardano.CLI.EraBased.Options.Governance (GovernanceCmds, renderGovernanceCmds)

import Data.Text (Text)
import Data.Typeable (Typeable)

data AnyEraCommand where
AnyEraCommandOf :: Typeable era => ShelleyBasedEra era -> Cmds era -> AnyEraCommand

renderAnyEraCommand :: AnyEraCommand -> Text
renderAnyEraCommand = \case
AnyEraCommandOf _ cmd -> renderCmds cmd

data Cmds era
= AddressCmds AddressCmds
| KeyCmds KeyCmds
| GenesisCmds (GenesisCmds era)
| GovernanceCmds (GovernanceCmds era)
| NodeCmds NodeCmds
| QueryCmds (QueryCmds era)
| StakeAddressCmds (StakeAddressCmds era)
| StakePoolCmds (StakePoolCmds era)
| TextViewCmds (TextViewCmds era)
| TransactionCmds (TransactionCmds era)

renderCmds :: Cmds era -> Text
renderCmds = \case
AddressCmds cmd ->
renderAddressCmds cmd
KeyCmds cmd ->
renderKeyCmds cmd
GenesisCmds cmd ->
renderGenesisCmds cmd
GovernanceCmds cmd ->
renderGovernanceCmds cmd
NodeCmds cmd ->
renderNodeCmds cmd
QueryCmds cmd ->
renderQueryCmds cmd
StakeAddressCmds cmd ->
renderStakeAddressCmds cmd
StakePoolCmds cmd ->
renderStakePoolCmds cmd
TextViewCmds cmd ->
renderTextViewCmds cmd
TransactionCmds cmd ->
renderTransactionCmds cmd
44 changes: 44 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Era.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Cardano.CLI.EraBased.Options.Era
( pAnyEraCommand
)
where

import Cardano.Api (ShelleyBasedEra (..))

import Cardano.CLI.Environment
import Cardano.CLI.EraBased.Commands.TopLevelCommands
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.TopLevelCommands
import Cardano.CLI.Parser

import Data.Foldable
import Options.Applicative (Parser)
import qualified Options.Applicative as Opt

pAnyEraCommand :: EnvCli -> Parser AnyEraCommand
pAnyEraCommand envCli =
asum
[ -- Note, byron is ommitted because there is already a legacy command group for it.

subParser "shelley" $
Opt.info (AnyEraCommandOf ShelleyBasedEraShelley <$> pCmds ShelleyBasedEraShelley envCli) $
Opt.progDesc ("Shelley era commands" <> deprecationText)
, subParser "allegra" $
Opt.info (AnyEraCommandOf ShelleyBasedEraAllegra <$> pCmds ShelleyBasedEraAllegra envCli) $
Opt.progDesc ("Allegra era commands" <> deprecationText)
, subParser "mary" $
Opt.info (AnyEraCommandOf ShelleyBasedEraMary <$> pCmds ShelleyBasedEraMary envCli) $
Opt.progDesc ("Mary era commands" <> deprecationText)
, subParser "alonzo" $
Opt.info (AnyEraCommandOf ShelleyBasedEraAlonzo <$> pCmds ShelleyBasedEraAlonzo envCli) $
Opt.progDesc ("Alonzo era commands" <> deprecationText)
, subParser "babbage" $
Opt.info (AnyEraCommandOf ShelleyBasedEraBabbage <$> pCmds ShelleyBasedEraBabbage envCli) $
Opt.progDesc ("Babbage era commands" <> deprecationText)
, subParser "conway" $
Opt.info (AnyEraCommandOf ShelleyBasedEraConway <$> pCmds ShelleyBasedEraConway envCli) $
Opt.progDesc "Conway era commands"
, subParser "latest" $
Opt.info (AnyEraCommandOf ShelleyBasedEraConway <$> pCmds ShelleyBasedEraConway envCli) $
Opt.progDesc "Latest era commands (Conway)"
]
Loading
Loading