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

Colors in cli output #3023

Merged
merged 5 commits into from
Aug 17, 2021
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
2 changes: 1 addition & 1 deletion bench/cardano-topology/cardano-topology.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ executable cardano-topology
, bytestring
, containers
, graphviz
, optparse-applicative-fork
, optparse-applicative
, split
, text
4 changes: 2 additions & 2 deletions bench/locli/locli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ library
, gnuplot
, Histogram
, iohk-monitoring
, optparse-applicative-fork
, optparse-applicative
, optparse-generic
, ouroboros-network
, process
Expand Down Expand Up @@ -94,7 +94,7 @@ executable locli
build-depends: base
, cardano-prelude
, locli
, optparse-applicative-fork
, optparse-applicative
, text
, text-short
, transformers
Expand Down
4 changes: 2 additions & 2 deletions bench/tx-generator/tx-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ library
, ixset-typed
, network
, network-mux
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
, ouroboros-consensus-cardano
Expand Down Expand Up @@ -139,7 +139,7 @@ test-suite tx-generator-test
build-depends: base >=4.12 && <5
, hedgehog
, heredoc
, optparse-applicative-fork
, optparse-applicative
, tasty
, tasty-hedgehog
, tasty-hunit
Expand Down
11 changes: 9 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,19 @@ package cardano-ledger-alonzo-test
-- --------------------------- 8< --------------------------
-- Please do not put any `source-repository-package` clause above this line.

-- Using a fork until our patches can be merged upstream
source-repository-package
type: git
location: https://github.com/input-output-hk/criterion
tag: fb2e7be532db96255d203f86360230cae37130f3
--sha256: 14r9zkfa8zslky3969gaq27gi7yi9rlqv0h1iq7zam9l15z53vhr

-- Using a fork until our patches can be merged upstream
source-repository-package
type: git
location: https://github.com/input-output-hk/optparse-applicative
tag: 7497a29cb998721a9068d5725d49461f2bba0e7a
--sha256: 1gvsrg925vynwgqwplgjmp53vj953qyh3wbdf34pw21c8r47w35r
tag: 84bcc6f18992a441886589a117249bfface8630e
--sha256: 09pr7m9gjsk8889m9d3mj75p69viv1acnrq63dgb11jl5gnnsblr

source-repository-package
type: git
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ library
, formatting
, iproute
, network
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
, ouroboros-consensus-cardano
Expand Down Expand Up @@ -158,7 +158,7 @@ executable cardano-cli
build-depends: cardano-cli
, cardano-crypto-class
, cardano-prelude
, optparse-applicative-fork
, optparse-applicative
, transformers-except

test-suite cardano-cli-test
Expand Down
19 changes: 14 additions & 5 deletions cardano-cli/src/Cardano/CLI/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Cardano.Prelude
import Data.Function (id)
import Options.Applicative
import Options.Applicative.Help.Ann
import Options.Applicative.Help.Types (helpText)
import Options.Applicative.Help.Types (helpText, renderHelp)
import Prelude (String)
import Prettyprinter
import Prettyprinter.Render.Util.SimpleDocTree
Expand All @@ -26,19 +26,25 @@ cliHelpTraceEnabled = IO.unsafePerformIO $ do
-- tools can be used to inspect tracing that aids in describing the structure of the output
-- document.
customRenderHelp :: Int -> ParserHelp -> String
customRenderHelp cols
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 = if cliHelpTraceEnabled
then \ann x -> case ann of
renderElement :: Ann -> Text -> Text
renderElement ann x = if cliHelpTraceEnabled
then case ann of
AnnTrace _ name -> "<span name=" <> show name <> ">" <> x <> "</span>"
AnnStyle _ -> x
else flip const
else x
wrapper = if cliHelpTraceEnabled
then id
. ("<html>\n" <>)
Expand All @@ -48,3 +54,6 @@ customRenderHelp cols
. (<> "\n</body>")
. (<> "\n</pre>")
else id

customRenderHelpAsAnsi :: Int -> ParserHelp -> String
customRenderHelpAsAnsi = renderHelp
31 changes: 21 additions & 10 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Parser as Aeson.Parser
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import qualified Options.Applicative as Opt
import qualified Options.Applicative.Help as H
import qualified Text.Parsec as Parsec
import qualified Text.Parsec.Error as Parsec
import qualified Text.Parsec.Language as Parsec
Expand Down Expand Up @@ -558,17 +559,27 @@ pTransaction :: Parser TransactionCmd
pTransaction =
asum
[ subParser "build-raw"
$ Opt.info pTransactionBuildRaw $ Opt.progDescDoc $ Just $
pretty @String "Build a transaction (low-level, inconvenient)"
<> line <> line
<> "Please note the order of some cmd options is crucial. If used incorrectly may produce "
<> "undesired tx body. See nested [] notation above for details."
$ Opt.info pTransactionBuildRaw $ Opt.progDescDoc $ Just $ mconcat
[ pretty @String "Build a transaction (low-level, inconvenient)"
, line
, line
, H.yellow $ mconcat
[ "Please note the order of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
, subParser "build"
$ Opt.info pTransactionBuild $ Opt.progDescDoc $ Just $
pretty @String "Build a balanced transaction (automatically calculates fees)"
<> line <> line
<> "Please note the order of some cmd options is crucial. If used incorrectly may produce "
<> "undesired tx body. See nested [] notation above for details."
$ Opt.info pTransactionBuild $ Opt.progDescDoc $ Just $ mconcat
[ pretty @String "Build a balanced transaction (automatically calculates fees)"
, line
, line
, H.yellow $ mconcat
[ "Please note "
, H.underline "the order"
, " of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
, subParser "sign"
(Opt.info pTransactionSign $ Opt.progDesc "Sign a transaction")
, subParser "witness"
Expand Down
2 changes: 1 addition & 1 deletion cardano-node-chairman/cardano-node-chairman.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ executable cardano-node-chairman
, contra-tracer
, io-classes
, network-mux
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-network
, ouroboros-network-framework
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ library
, network
, network-mux
, nothunks
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus
, ouroboros-consensus-byron
, ouroboros-consensus-cardano
Expand Down Expand Up @@ -167,7 +167,7 @@ executable cardano-node
build-depends: cardano-config
, cardano-node
, cardano-prelude
, optparse-applicative-fork
, optparse-applicative
, text

test-suite cardano-node-test
Expand Down
6 changes: 3 additions & 3 deletions cardano-submit-api/cardano-submit-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ common http-media { build-depends: http-media
common iohk-monitoring { build-depends: iohk-monitoring >= 0.1.10.1 }
common mtl { build-depends: mtl >= 2.2.2 }
common network { build-depends: network >= 3.1.2.1 }
common optparse-applicative-fork { build-depends: optparse-applicative-fork >= 0.16.1.0 }
common optparse-applicative { build-depends: optparse-applicative >= 0.16.1.0 }
common ouroboros-consensus-cardano { build-depends: ouroboros-consensus-cardano >= 0.1.0.0 }
common ouroboros-network { build-depends: ouroboros-network >= 0.1.0.0 }
common prometheus { build-depends: prometheus >= 2.2.2 }
Expand Down Expand Up @@ -78,7 +78,7 @@ library
, iohk-monitoring
, mtl
, network
, optparse-applicative-fork
, optparse-applicative
, ouroboros-consensus-cardano
, ouroboros-network
, prometheus
Expand Down Expand Up @@ -111,7 +111,7 @@ library
executable cardano-submit-api
import: base, project-config
, cardano-submit-api
, optparse-applicative-fork
, optparse-applicative
main-is: Main.hs
hs-source-dirs: app
ghc-options: -threaded -rtsopts "-with-rtsopts=-T -I0"
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ executable cardano-testnet
, cardano-testnet
, hedgehog
, hedgehog-extras
, optparse-applicative-fork
, optparse-applicative
, resourcet
, stm
, text
Expand Down
Loading