-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from IntersectMBO/jordan/expose-compatible-co…
…mmand Add compatible command group
- Loading branch information
Showing
111 changed files
with
4,294 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.