Skip to content
Draft
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
4 changes: 2 additions & 2 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ library
mtl,
network,
network-uri,
optparse-applicative-fork,
optparse-applicative ^>=0.19,
ordered-containers,
prettyprinter,
prettyprinter-ansi-terminal,
Expand Down Expand Up @@ -310,7 +310,7 @@ executable cardano-cli
cardano-api,
cardano-cli,
cardano-crypto-class,
optparse-applicative-fork,
optparse-applicative ^>=0.19,
rio,
terminal-size,

Expand Down
20 changes: 13 additions & 7 deletions cardano-cli/src/Cardano/CLI/EraBased/Transaction/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Cardano.CLI.EraBased.Transaction.Option
)
where

import Cardano.Api hiding (QueryInShelleyBasedEra (..))
import Cardano.Api hiding (QueryInShelleyBasedEra (..), yellow)
import Cardano.Api.Experimental qualified as Exp

import Cardano.CLI.Environment (EnvCli (..))
Expand All @@ -33,6 +33,12 @@ import Options.Applicative qualified as Opt
import Options.Applicative.Help qualified as H
import Prettyprinter (line)

yellow :: H.Doc -> H.Doc
yellow = H.annotate (H.color H.Yellow)

underline :: H.Doc -> H.Doc
underline = H.annotate H.underlined

pTransactionCmds
:: Exp.IsEra era
=> EnvCli
Expand All @@ -55,10 +61,10 @@ pTransactionCmds envCli =
[ pretty @String "Build a transaction (low-level, inconvenient)"
, line
, line
, H.yellow $
, yellow $
mconcat
[ "Please note "
, H.underline "the order"
, underline "the order"
, " of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
Expand Down Expand Up @@ -179,10 +185,10 @@ pTransactionBuildCmd envCli = do
[ pretty @String "Build a balanced transaction (automatically calculates fees)"
, line
, line
, H.yellow $
, yellow $
mconcat
[ "Please note "
, H.underline "the order"
, underline "the order"
, " of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
Expand Down Expand Up @@ -243,10 +249,10 @@ pTransactionBuildEstimateCmd _envCli = do
"Build a balanced transaction without access to a live node (automatically estimates fees)"
, line
, line
, H.yellow $
, yellow $
mconcat
[ "Please note "
, H.underline "the order"
, underline "the order"
, " of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
Expand Down
5 changes: 1 addition & 4 deletions cardano-cli/src/Cardano/CLI/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import Cardano.CLI.EraIndependent.Node.Option
import Cardano.CLI.EraIndependent.Ping.Option (parsePingCmd)
import Cardano.CLI.Legacy.Option (parseLegacyCmds)
import Cardano.CLI.Parser
import Cardano.CLI.Render (customRenderHelp)
import Cardano.CLI.Run (ClientCommand (..))

import Data.Foldable
import Options.Applicative
import Options.Applicative qualified as Opt
import Prettyprinter qualified as PP

opts :: EnvCli -> ParserInfo ClientCommand
opts envCli =
Expand All @@ -51,8 +49,7 @@ pref =
Opt.prefs $
mconcat
[ showHelpOnEmpty
, helpEmbedBriefDesc PP.align
, helpRenderHelp customRenderHelp
, briefHangPoint 35
]

addressCmdsTopLevel :: EnvCli -> Parser ClientCommand
Expand Down
56 changes: 2 additions & 54 deletions cardano-cli/src/Cardano/CLI/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,12 @@ module Cardano.CLI.Render
)
where

import Cardano.Api (textShow)

import Data.Text (Text)
import Data.Text qualified as T
import Options.Applicative
import Options.Applicative.Help.Ann
import Options.Applicative.Help.Types (helpText, renderHelp)
import Options.Applicative.Help.Types (ParserHelp, renderHelp)
import Prettyprinter
import Prettyprinter.Render.Util.SimpleDocTree
import System.Environment qualified as IO
import System.IO.Unsafe qualified as IO

cliHelpTraceEnabled :: Bool
cliHelpTraceEnabled = IO.unsafePerformIO $ do
mValue <- IO.lookupEnv "CLI_HELP_TRACE"
return $ mValue == Just "1"
{-# NOINLINE cliHelpTraceEnabled #-}

-- | Convert a help text to 'String'. When the CLI_HELP_TRACE environment variable is set
-- to '1', the output will be in HTML so that it can be viewed in a browser where developer
-- tools can be used to inspect tracing that aids in describing the structure of the output
-- document.
customRenderHelp :: Int -> ParserHelp -> String
customRenderHelp =
if cliHelpTraceEnabled
then customRenderHelpAsHtml
else customRenderHelpAsAnsi

customRenderHelpAsHtml :: Int -> ParserHelp -> String
customRenderHelpAsHtml cols =
T.unpack
. wrapper
. renderSimplyDecorated id renderElement
. treeForm
. layoutSmart (LayoutOptions (AvailablePerLine cols 1.0))
. helpText
where
renderElement :: Ann -> Text -> Text
renderElement ann x =
if cliHelpTraceEnabled
then case ann of
AnnTrace _ name -> "<span name=" <> textShow name <> ">" <> x <> "</span>"
AnnStyle _ -> x
else x
wrapper =
if cliHelpTraceEnabled
then
id
. ("<html>\n" <>)
. ("<body>\n" <>)
. ("<pre>\n" <>)
. (<> "\n</html>")
. (<> "\n</body>")
. (<> "\n</pre>")
else id

customRenderHelpAsAnsi :: Int -> ParserHelp -> String
customRenderHelpAsAnsi = renderHelp
customRenderHelp = renderHelp

renderAnyCmdError :: Text -> (a -> Doc ann) -> a -> Doc ann
renderAnyCmdError cmdText renderer shelCliCmdErr =
Expand Down
Loading