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

Move Shelley commands to the top-lvl and deprecate "shelley" subcommand #2076

Merged
merged 1 commit into from
Nov 23, 2020
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
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
Copy link
Contributor

@Jimbo4350 Jimbo4350 Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally wouldn't bother with defining two new functions, seems verbose when
liftIO (Text.hPutStrLn stderr warningMsg) >> e on its own would do with a comment. Your call though!

Copy link
Contributor Author

@intricate intricate Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering reusing this for other deprecated commands/arguments.

For example, after #1979 is merged, I'm considering whether we should print deprecation warnings when hex or TextEnvelope keys are specified.


-- | 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