-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switch to prettyprinter library * Tracing * Command for printing all help * Option ordering note on build-raw command
- Loading branch information
Showing
9 changed files
with
162 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Cardano.CLI.Render | ||
( customRenderHelp | ||
) where | ||
|
||
import Cardano.Prelude | ||
import Data.Function (id) | ||
import Options.Applicative | ||
import Options.Applicative.Help.Ann | ||
import Options.Applicative.Help.Types (helpText) | ||
import Prelude (String) | ||
import Prettyprinter | ||
import Prettyprinter.Render.Util.SimpleDocTree | ||
|
||
import qualified Data.Text as T | ||
import qualified System.Environment as IO | ||
import qualified System.IO.Unsafe 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 cols | ||
= T.unpack | ||
. wrapper | ||
. renderSimplyDecorated id renderElement | ||
. treeForm | ||
. layoutSmart (LayoutOptions (AvailablePerLine cols 1.0)) | ||
. helpText | ||
where | ||
renderElement = if cliHelpTraceEnabled | ||
then \(AnnTrace _ name) x -> "<span name=" <> show name <> ">" <> x <> "</span>" | ||
else flip const | ||
wrapper = if cliHelpTraceEnabled | ||
then id | ||
. ("<html>\n" <>) | ||
. ("<body>\n" <>) | ||
. ("<pre>\n" <>) | ||
. (<> "\n</html>") | ||
. (<> "\n</body>") | ||
. (<> "\n</pre>") | ||
else id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters