Skip to content

Commit

Permalink
Merge pull request #917 from IntersectMBO/jordan/expose-compatible-co…
Browse files Browse the repository at this point in the history
…mmand

Add compatible command group
  • Loading branch information
Jimbo4350 authored Oct 22, 2024
2 parents bc62e86 + 70c7079 commit 9197c62
Show file tree
Hide file tree
Showing 111 changed files with 4,294 additions and 20 deletions.
4 changes: 4 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ library
Cardano.CLI.Commands.Key
Cardano.CLI.Commands.Node
Cardano.CLI.Commands.Ping
Cardano.CLI.Compatible.Commands
Cardano.CLI.Compatible.Governance
Cardano.CLI.Compatible.Run
Cardano.CLI.Compatible.Transaction
Cardano.CLI.Environment
Cardano.CLI.EraBased.Commands
Cardano.CLI.EraBased.Commands.Genesis
Expand Down
5 changes: 4 additions & 1 deletion cardano-cli/src/Cardano/CLI/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Cardano.CLI.Commands.Hash (HashCmds)
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.Legacy.Commands

Expand All @@ -23,7 +24,9 @@ data ClientCommand
| AddressCommand AddressCmds
| -- | Byron Related Commands
ByronCommand ByronCommand
| -- | Era agnostic hashing commands
| -- | Backward compatible commands for testing only
CompatibleCommands AnyCompatibleCommand
| -- | Era-agnostic hashing commands
HashCmds HashCmds
| -- | Era agnostic key commands
KeyCommands KeyCmds
Expand Down
75 changes: 75 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Commands.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}

{-
This module is concerned with providing backwards compatible cli commands for our internal
testing needs. The intention is to restrict as much as possible which functionality we maintain backwards
compatibility for.
-}

module Cardano.CLI.Compatible.Commands
( AnyCompatibleCommand (..)
, CompatibleCommand (..)
, pAnyCompatibleCommand
, renderAnyCompatibleCommand
)
where

import Cardano.Api

import Cardano.CLI.Compatible.Governance
import Cardano.CLI.Compatible.Transaction
import Cardano.CLI.Environment
import Cardano.CLI.Parser

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

data AnyCompatibleCommand where
AnyCompatibleCommand :: CompatibleCommand era -> AnyCompatibleCommand

renderAnyCompatibleCommand :: AnyCompatibleCommand -> Text
renderAnyCompatibleCommand = \case
AnyCompatibleCommand cmd -> renderCompatibleCommand cmd

data CompatibleCommand era
= CompatibleTransactionCmd (CompatibleTransactionCmds era)
| CompatibleGovernanceCmds (CompatibleGovernanceCmds era)

renderCompatibleCommand :: CompatibleCommand era -> Text
renderCompatibleCommand = \case
CompatibleTransactionCmd cmd -> renderCompatibleTransactionCmd cmd
CompatibleGovernanceCmds cmd -> renderCompatibleGovernanceCmds cmd

pAnyCompatibleCommand :: EnvCli -> Parser AnyCompatibleCommand
pAnyCompatibleCommand envCli =
asum
[ -- Note, byron is ommitted because there is already a legacy command group for it.
subParser "shelley" $
Opt.info (AnyCompatibleCommand <$> pCompatibleCommand ShelleyBasedEraShelley envCli) $
Opt.progDesc "Shelley era commands"
, subParser "allegra" $
Opt.info (AnyCompatibleCommand <$> pCompatibleCommand ShelleyBasedEraAllegra envCli) $
Opt.progDesc "Allegra era commands"
, subParser "mary" $
Opt.info (AnyCompatibleCommand <$> pCompatibleCommand ShelleyBasedEraMary envCli) $
Opt.progDesc "Mary era commands"
, subParser "alonzo" $
Opt.info (AnyCompatibleCommand <$> pCompatibleCommand ShelleyBasedEraAlonzo envCli) $
Opt.progDesc "Alonzo era commands"
, subParser "babbage" $
Opt.info (AnyCompatibleCommand <$> pCompatibleCommand ShelleyBasedEraBabbage envCli) $
Opt.progDesc "Babbage era commands"
, subParser "conway" $
Opt.info (AnyCompatibleCommand <$> pCompatibleCommand ShelleyBasedEraConway envCli) $
Opt.progDesc "Conway era commands"
]

pCompatibleCommand :: ShelleyBasedEra era -> EnvCli -> Parser (CompatibleCommand era)
pCompatibleCommand era env =
asum
[ CompatibleTransactionCmd <$> pAllCompatibleTransactionCommands env era
, CompatibleGovernanceCmds <$> pCompatibleGovernanceCmds era
]
39 changes: 39 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Governance.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Compatible.Governance
( CompatibleGovernanceCmds (..)
, pCompatibleGovernanceCmds
, renderCompatibleGovernanceCmds
, runCompatibleGovernanceCmds
)
where

import Cardano.Api

import Cardano.CLI.EraBased.Options.Governance
import Cardano.CLI.EraBased.Run.Governance
import Cardano.CLI.Types.Errors.CmdError

import Data.Foldable
import Data.Maybe
import Data.Text
import Options.Applicative

pCompatibleGovernanceCmds :: ShelleyBasedEra era -> Parser (CompatibleGovernanceCmds era)
pCompatibleGovernanceCmds sbe =
asum $ catMaybes [fmap CreateCompatibleProtocolUpdateCmd <$> pGovernanceCmds sbe]

-- TODO: After QA confirmms that the new compatibility commands meet their needs
-- we can remove all remaining legacy commands. We can also remove/move the exising
-- byron era commands under the new compatiblilty commands.
newtype CompatibleGovernanceCmds era
= CreateCompatibleProtocolUpdateCmd (GovernanceCmds era)

runCompatibleGovernanceCmds :: CompatibleGovernanceCmds era -> ExceptT CmdError IO ()
runCompatibleGovernanceCmds = \case
CreateCompatibleProtocolUpdateCmd cmd -> runGovernanceCmds cmd

renderCompatibleGovernanceCmds :: CompatibleGovernanceCmds era -> Text
renderCompatibleGovernanceCmds = \case
CreateCompatibleProtocolUpdateCmd cmd -> renderGovernanceCmds cmd
37 changes: 37 additions & 0 deletions cardano-cli/src/Cardano/CLI/Compatible/Run.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Compatible.Run
( CompatibleCmdError
, renderCompatibleCmdError
, runAnyCompatibleCommand
, runCompatibleCommand
)
where

import Cardano.Api

import Cardano.CLI.Compatible.Commands
import Cardano.CLI.Compatible.Governance
import Cardano.CLI.Compatible.Transaction
import Cardano.CLI.Render
import Cardano.CLI.Types.Errors.CmdError

import Data.Text (Text)

data CompatibleCmdError
= CompatibleTransactionError CompatibleTransactionError
| CompatibleGovernanceError CmdError

renderCompatibleCmdError :: Text -> CompatibleCmdError -> Doc ann
renderCompatibleCmdError cmdText = \case
CompatibleTransactionError e -> renderAnyCmdError cmdText prettyError e
CompatibleGovernanceError e -> renderCmdError cmdText e

runAnyCompatibleCommand :: AnyCompatibleCommand -> ExceptT CompatibleCmdError IO ()
runAnyCompatibleCommand (AnyCompatibleCommand cmd) = runCompatibleCommand cmd

runCompatibleCommand :: CompatibleCommand era -> ExceptT CompatibleCmdError IO ()
runCompatibleCommand (CompatibleTransactionCmd txCmd) =
firstExceptT CompatibleTransactionError $ runCompatibleTransactionCmd txCmd
runCompatibleCommand (CompatibleGovernanceCmds govCmd) =
firstExceptT CompatibleGovernanceError $ runCompatibleGovernanceCmds govCmd
Loading

0 comments on commit 9197c62

Please sign in to comment.