From 0d0820d469a44a262f248d23c6bcb07f4065d761 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 16 Jun 2026 11:53:13 -0400 Subject: [PATCH] Migrate from optparse-applicative-fork to optparse-applicative 0.19 Upstream now includes the prettyprinter switch (PR #428) and briefHangPoint formatter (PR #425), making the fork unnecessary. Two capabilities from the fork are not available in upstream: - prefRenderHelp: no hook to inject a custom renderer into the --help path - helpEmbedBriefDesc: replaced with the coarser briefHangPoint 35 The CLI_HELP_TRACE tracing (Ann/AnnTrace) is removed; it was never wired up. Golden tests will need updating due to formatting changes. --- cardano-cli/cardano-cli.cabal | 4 +- .../CLI/EraBased/Transaction/Option.hs | 20 ++++--- cardano-cli/src/Cardano/CLI/Option.hs | 5 +- cardano-cli/src/Cardano/CLI/Render.hs | 56 +------------------ 4 files changed, 18 insertions(+), 67 deletions(-) diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 2e24f66059..b1ea606a9f 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -280,7 +280,7 @@ library mtl, network, network-uri, - optparse-applicative-fork, + optparse-applicative ^>=0.19, ordered-containers, prettyprinter, prettyprinter-ansi-terminal, @@ -310,7 +310,7 @@ executable cardano-cli cardano-api, cardano-cli, cardano-crypto-class, - optparse-applicative-fork, + optparse-applicative ^>=0.19, rio, terminal-size, diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Transaction/Option.hs b/cardano-cli/src/Cardano/CLI/EraBased/Transaction/Option.hs index 424a55915d..83bde4550b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Transaction/Option.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Transaction/Option.hs @@ -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 (..)) @@ -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 @@ -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." ] @@ -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." ] @@ -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." ] diff --git a/cardano-cli/src/Cardano/CLI/Option.hs b/cardano-cli/src/Cardano/CLI/Option.hs index 328f78722f..82fe78110c 100644 --- a/cardano-cli/src/Cardano/CLI/Option.hs +++ b/cardano-cli/src/Cardano/CLI/Option.hs @@ -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 = @@ -51,8 +49,7 @@ pref = Opt.prefs $ mconcat [ showHelpOnEmpty - , helpEmbedBriefDesc PP.align - , helpRenderHelp customRenderHelp + , briefHangPoint 35 ] addressCmdsTopLevel :: EnvCli -> Parser ClientCommand diff --git a/cardano-cli/src/Cardano/CLI/Render.hs b/cardano-cli/src/Cardano/CLI/Render.hs index d3043fd4ae..38bd29b968 100644 --- a/cardano-cli/src/Cardano/CLI/Render.hs +++ b/cardano-cli/src/Cardano/CLI/Render.hs @@ -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 -> "" <> x <> "" - AnnStyle _ -> x - else x - wrapper = - if cliHelpTraceEnabled - then - id - . ("\n" <>) - . ("\n" <>) - . ("
\n" <>)
-          . (<> "\n")
-          . (<> "\n")
-          . (<> "\n
") - else id - -customRenderHelpAsAnsi :: Int -> ParserHelp -> String -customRenderHelpAsAnsi = renderHelp +customRenderHelp = renderHelp renderAnyCmdError :: Text -> (a -> Doc ann) -> a -> Doc ann renderAnyCmdError cmdText renderer shelCliCmdErr =