Fix some terminal help issues.

This commit is contained in:
Robin Heggelund Hansen 2022-09-23 09:35:54 +02:00
parent ec26054a26
commit 42c38389ea

View File

@ -66,10 +66,22 @@ exitWith code docs =
P.renderPretty 1 80 $ P.renderPretty 1 80 $
adjust $ adjust $
P.vcat $ P.vcat $
concatMap (\d -> [d, ""]) docs concatMap (\d -> [d, ""]) $
trimDocs docs
hPutStrLn stderr "" hPutStrLn stderr ""
Exit.exitWith code Exit.exitWith code
trimDocs :: [P.Doc] -> [P.Doc]
trimDocs docs =
let reversed =
case reverse docs of
[] -> []
first : rest ->
case P.renderCompact first of
P.SEmpty -> rest
_ -> first : rest
in reverse reversed
getExeName :: IO String getExeName :: IO String
getExeName = getExeName =
FP.takeFileName <$> Env.getProgName FP.takeFileName <$> Env.getProgName
@ -173,15 +185,15 @@ exitWithOverview intro outro maybePrefix commands =
exitSuccess exitSuccess
[ intro, [ intro,
"The most common commands are:", "The most common commands are:",
P.indent 4 $ stack $ Maybe.mapMaybe (toSummary exeName) commands, P.indent 4 $ stack $ Maybe.mapMaybe (toSummary exeName maybePrefix) commands,
"There are a bunch of other commands as well though. Here is a full list:", "There are a bunch of other commands as well though. Here is a full list:",
P.indent 4 $ P.dullcyan $ toCommandList exeName maybePrefix commands, P.indent 4 $ P.dullcyan $ toCommandList exeName maybePrefix commands,
"Adding the --help flag gives a bunch of additional details about each one.", "Adding the --help flag gives a bunch of additional details about each one.",
outro outro
] ]
toSummary :: String -> Command -> Maybe P.Doc toSummary :: String -> Maybe String -> Command -> Maybe P.Doc
toSummary exeName cmd = toSummary exeName maybePrefix cmd =
case cmd of case cmd of
Prefix _ _ _ _ -> Prefix _ _ _ _ ->
Nothing Nothing
@ -190,9 +202,15 @@ toSummary exeName cmd =
Uncommon -> Uncommon ->
Nothing Nothing
Common summaryString -> Common summaryString ->
Just $ let prefixSep =
case maybePrefix of
Just prefix ->
" " ++ prefix ++ " "
Nothing ->
" "
in Just $
P.vcat P.vcat
[ P.cyan $ argsToDoc (exeName ++ " " ++ name) (head args), [ P.cyan $ argsToDoc (exeName ++ prefixSep ++ name) (head args),
P.indent 4 $ reflow summaryString P.indent 4 $ reflow summaryString
] ]