1
0
forked from GitHub/gf-core

Omit empty sections in gf help output

This commit is contained in:
hallgren
2011-09-14 20:26:22 +00:00
parent 6de924537d
commit e837f072f4

View File

@@ -89,43 +89,46 @@ commandHelpAll pgf opts = unlines
commandHelp' opts = if isOpt "t2t" opts then commandHelpTags else commandHelp commandHelp' opts = if isOpt "t2t" opts then commandHelpTags else commandHelp
commandHelp :: Bool -> (String,CommandInfo) -> String commandHelp :: Bool -> (String,CommandInfo) -> String
commandHelp full (co,info) = unlines $ [ commandHelp full (co,info) = unlines . compact $ [
co ++ ", " ++ longname info, co ++ optionally (", " ++) (longname info),
synopsis info] ++ if full then [ synopsis info] ++ if full then [
"", "",
"syntax:" ++++ " " ++ syntax info, optionally (("syntax:" ++++).(" "++).(++"\n")) (syntax info),
"",
explanation info, explanation info,
"options:" ++++ unlines [" -" ++ o ++ "\t" ++ e | (o,e) <- options info], section "options:" [" -" ++ o ++ "\t" ++ e | (o,e) <- options info],
"flags:" ++++ unlines [" -" ++ o ++ "\t" ++ e | (o,e) <- flags info], section "flags:" [" -" ++ o ++ "\t" ++ e | (o,e) <- flags info],
"examples:" ++++ unlines [" " ++ s | s <- examples info] section "examples:" [" " ++ s | s <- examples info]
] else [] ] else []
-- for printing with txt2tags formatting -- for printing with txt2tags formatting
commandHelpTags :: Bool -> (String,CommandInfo) -> String commandHelpTags :: Bool -> (String,CommandInfo) -> String
commandHelpTags full (co,info) = unlines $ [ commandHelpTags full (co,info) = unlines . compact $ [
"#VSPACE","","#NOINDENT", "#VSPACE","","#NOINDENT",
lit co ++ equal (lit (longname info)) ++ ": " ++ lit co ++ equal (lit (longname info)) ++ ": " ++
"//" ++ synopsis info ++ ".//"] ++ if full then [ "//" ++ synopsis info ++ ".//"] ++ if full then [
"","#TINY","", "","#TINY","",
explanation info, explanation info,
"- Syntax: " ++ lit (syntax info), optionally ("- Syntax: "++) (lit (syntax info)),
"- Options:\n" ++++ section "- Options:\n" [" | ``-" ++ o ++ "`` | " ++ e | (o,e)<- options info],
unlines [" | ``-" ++ o ++ "`` | " ++ e | (o,e) <- options info], section "- Flags:\n" [" | ``-" ++ o ++ "`` | " ++ e | (o,e) <- flags info],
"- Flags:\n" ++++ section "- Examples:\n" (verbatim [" " ++ s | s <- examples info]),
unlines [" | ``-" ++ o ++ "`` | " ++ e | (o,e) <- flags info],
"- Examples:\n```" ++++
unlines [" " ++ s | s <- examples info],
"```",
"", "#NORMAL", "" "", "#NORMAL", ""
] else [] ] else []
where where
equal "" = "" lit = optionally (wrap "``")
equal s = " = " ++ s equal = optionally (" = "++)
verbatim = optionally (wrap ["```"])
wrap d s = d++s++d
lit "" = "" section hdr = optionally ((hdr++++).unlines)
lit s = "``" ++ s ++ "``"
optionally f [] = []
optionally f s = f s
compact [] = []
compact ([]:xs@([]:_)) = compact xs
compact (x:xs) = x:compact xs
type PGFEnv = (PGF, Map.Map Language Morpho) type PGFEnv = (PGF, Map.Map Language Morpho)