Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Oct 7, 2024
1 parent bda0cb3 commit fe6db73
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cardano.CLI.Commands.Debug
import Cardano.CLI.Commands.Hash (HashCmds)
import Cardano.CLI.Commands.Ping (PingCmd (..))
import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Commands.Node
import Cardano.CLI.Legacy.Commands

import Options.Applicative.Types (ParserInfo (..), ParserPrefs (..))
Expand All @@ -21,6 +22,8 @@ data ClientCommand
ByronCommand ByronCommand
| -- | Era-agnostic hashing commands
HashCmds HashCmds
| -- | Era agnostic node commands
NodeCommands NodeCmds
| -- | Legacy shelley-based Commands
LegacyCmds LegacyCmds
| CliPingCommand PingCmd
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data Cmds era
| KeyCmds (KeyCmds era)
| GenesisCmds (GenesisCmds era)
| GovernanceCmds (GovernanceCmds era)
| NodeCmds (NodeCmds era)
| NodeCmds NodeCmds
| QueryCmds (QueryCmds era)
| StakeAddressCmds (StakeAddressCmds era)
| StakePoolCmds (StakePoolCmds era)
Expand Down
13 changes: 12 additions & 1 deletion cardano-cli/src/Cardano/CLI/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ module Cardano.CLI.Options
)
where

import Cardano.Api (ShelleyBasedEra (..))

import Cardano.CLI.Byron.Parsers (backwardsCompatibilityCommands, parseByronCommands)
import Cardano.CLI.Environment (EnvCli)
import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.EraBased.Options.Node
import Cardano.CLI.Legacy.Options (parseLegacyCmds)
import Cardano.CLI.Options.Debug
import Cardano.CLI.Options.Hash
Expand Down Expand Up @@ -47,13 +50,21 @@ pref =
, helpRenderHelp customRenderHelp
]

-- 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
nodeCmdsTopLevel =
AnyEraCommand . AnyEraCommandOf ShelleyBasedEraShelley . NodeCmds <$> pNodeCmds

-- fmap (AnyEraCommand . AnyEraCommandOf ShelleyBasedEraShelley . NodeCmds) pNodeCmds
parseClientCommand :: EnvCli -> Parser ClientCommand
parseClientCommand envCli =
asum
-- 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.
[ parseLegacy envCli
[ nodeCmdsTopLevel
, parseLegacy envCli
, parseByron envCli
, parseAnyEra envCli
, parseHash
Expand Down
9 changes: 9 additions & 0 deletions cardano-cli/src/Cardano/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cardano.CLI.Byron.Run (ByronClientCmdError, renderByronClientCm
import Cardano.CLI.Commands
import Cardano.CLI.EraBased.Commands
import Cardano.CLI.EraBased.Run
import Cardano.CLI.EraBased.Run.Node
import Cardano.CLI.Legacy.Commands
import Cardano.CLI.Legacy.Run (runLegacyCmds)
import Cardano.CLI.Render (customRenderHelp)
Expand All @@ -27,9 +28,11 @@ import Cardano.CLI.Run.Ping (PingClientCmdError (..), renderPingClient
runPingCmd)
import Cardano.CLI.Types.Errors.CmdError
import Cardano.CLI.Types.Errors.HashCmdError
import Cardano.CLI.Types.Errors.NodeCmdError
import Cardano.Git.Rev (gitRev)

import Control.Monad (forM_)
import Data.Function
import qualified Data.List as L
import Data.Text (Text)
import qualified Data.Text as Text
Expand All @@ -47,13 +50,17 @@ data ClientCommandErrors
= ByronClientError ByronClientCmdError
| CmdError Text CmdError
| HashCmdError HashCmdError
| NodeCmdError NodeCmdError
| PingClientError PingClientCmdError
| DebugCmdError DebugCmdError

runClientCommand :: ClientCommand -> ExceptT ClientCommandErrors IO ()
runClientCommand = \case
AnyEraCommand cmds ->
firstExceptT (CmdError (renderAnyEraCommand cmds)) $ runAnyEraCommand cmds
NodeCommands cmds ->
runNodeCmds cmds
& firstExceptT NodeCmdError
ByronCommand cmds ->
firstExceptT ByronClientError $ runByronClientCommand cmds
HashCmds cmds ->
Expand All @@ -77,6 +84,8 @@ renderClientCommandError = \case
renderByronClientCmdError err
HashCmdError err ->
prettyError err
NodeCmdError err ->
renderNodeCmdError err
PingClientError err ->
renderPingClientCmdError err
DebugCmdError err ->
Expand Down

0 comments on commit fe6db73

Please sign in to comment.