Skip to content

Commit

Permalink
Move Shelley commands to the top-lvl and deprecate "shelley" subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Nov 10, 2020
1 parent 103d7a3 commit 7b8d432
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cardano-cli/src/Cardano/CLI/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ parseClientCommand :: Parser ClientCommand
parseClientCommand =
asum
[ parseByron <|> backwardsCompatibilityCommands
, parseShelley
, parseShelley <|> parseDeprecatedShelleySubcommand
, parseDisplayVersion
]

Expand All @@ -51,15 +51,25 @@ parseByron =
parseByronCommands
]

-- | Parse Shelley-related commands at the top level of the CLI.
parseShelley :: Parser ClientCommand
parseShelley =
parseShelley = ShelleyCommand <$> parseShelleyCommands

-- | Parse Shelley-related commands under the now-deprecated \"shelley\"
-- subcommand.
--
-- Note that this subcommand is 'internal' and is therefore hidden from the
-- help text.
parseDeprecatedShelleySubcommand :: Parser ClientCommand
parseDeprecatedShelleySubcommand =
subparser $ mconcat
[ commandGroup "Shelley specific commands"
[ commandGroup "Shelley specific commands (deprecated)"
, metavar "Shelley specific commands"
, command'
"shelley"
"Shelley specific commands"
(ShelleyCommand <$> parseShelleyCommands)
"Shelley specific commands (deprecated)"
(DeprecatedShelleySubcommand <$> parseShelleyCommands)
, internal
]

-- Yes! A --version flag or version command. Either guess is right!
Expand Down
29 changes: 29 additions & 0 deletions cardano-cli/src/Cardano/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cardano.Prelude

import Control.Monad.Trans.Except.Extra (firstExceptT)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

import Cardano.CLI.Byron.Commands (ByronCommand)
import Cardano.CLI.Byron.Run (ByronClientCmdError, renderByronClientCmdError,
Expand All @@ -33,6 +34,10 @@ data ClientCommand =
-- | Shelley Related Commands
| ShelleyCommand ShelleyCommand

-- | Shelley-related commands that have been parsed under the
-- now-deprecated \"shelley\" subcommand.
| DeprecatedShelleySubcommand ShelleyCommand

| DisplayVersion
deriving Show

Expand All @@ -45,6 +50,10 @@ data ClientCommandErrors
runClientCommand :: ClientCommand -> ExceptT ClientCommandErrors IO ()
runClientCommand (ByronCommand c) = firstExceptT ByronClientError $ runByronClientCommand c
runClientCommand (ShelleyCommand c) = firstExceptT (ShelleyClientError c) $ runShelleyClientCommand c
runClientCommand (DeprecatedShelleySubcommand c) =
firstExceptT (ShelleyClientError c)
$ runShelleyClientCommandWithDeprecationWarning
$ runShelleyClientCommand c
runClientCommand DisplayVersion = runDisplayVersion

renderClientCommandError :: ClientCommandErrors -> Text
Expand All @@ -53,6 +62,26 @@ renderClientCommandError (ByronClientError err) =
renderClientCommandError (ShelleyClientError cmd err) =
renderShelleyClientCmdError cmd err

-- | Combine an 'ExceptT' that will write a warning message to @stderr@ with
-- the provided 'ExceptT'.
ioExceptTWithWarning :: MonadIO m => Text -> ExceptT e m () -> ExceptT e m ()
ioExceptTWithWarning warningMsg e =
liftIO (Text.hPutStrLn stderr warningMsg) >> e

-- | Used in the event that Shelley-related commands are run using the
-- now-deprecated \"shelley\" subcommand.
runShelleyClientCommandWithDeprecationWarning
:: MonadIO m
=> ExceptT e m ()
-> ExceptT e m ()
runShelleyClientCommandWithDeprecationWarning =
ioExceptTWithWarning warningMsg
where
warningMsg :: Text
warningMsg =
"WARNING: The \"shelley\" subcommand is now deprecated and will be "
<> "removed in the future. Please use the top-level commands instead."

runDisplayVersion :: ExceptT ClientCommandErrors IO ()
runDisplayVersion = do
liftIO . putTextLn $ mconcat
Expand Down

0 comments on commit 7b8d432

Please sign in to comment.