1
0
forked from GitHub/gf-core

GF shell command 'help -t2t' outputs help in txt2tags format

This commit is contained in:
hallgren
2011-09-14 19:40:28 +00:00
parent a3b7e72426
commit ac0b6db821

View File

@@ -83,9 +83,11 @@ lookCommand = Map.lookup
commandHelpAll :: PGFEnv -> [Option] -> String commandHelpAll :: PGFEnv -> [Option] -> String
commandHelpAll pgf opts = unlines commandHelpAll pgf opts = unlines
[commandHelp (isOpt "full" opts) (co,info) [commandHelp' opts (isOpt "full" opts) (co,info)
| (co,info) <- Map.assocs (allCommands pgf)] | (co,info) <- Map.assocs (allCommands pgf)]
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 $ [
co ++ ", " ++ longname info, co ++ ", " ++ longname info,
@@ -104,11 +106,11 @@ commandHelp full (co,info) = unlines $ [
commandHelpTags :: Bool -> (String,CommandInfo) -> String commandHelpTags :: Bool -> (String,CommandInfo) -> String
commandHelpTags full (co,info) = unlines $ [ commandHelpTags full (co,info) = unlines $ [
"#VSPACE","","#NOINDENT", "#VSPACE","","#NOINDENT",
lit co ++ " = " ++ 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: ``" ++ syntax info ++ "``", "- Syntax: " ++ lit (syntax info),
"- Options:\n" ++++ "- Options:\n" ++++
unlines [" | ``-" ++ o ++ "`` | " ++ e | (o,e) <- options info], unlines [" | ``-" ++ o ++ "`` | " ++ e | (o,e) <- options info],
"- Flags:\n" ++++ "- Flags:\n" ++++
@@ -119,6 +121,10 @@ commandHelpTags full (co,info) = unlines $ [
"", "#NORMAL", "" "", "#NORMAL", ""
] else [] ] else []
where where
equal "" = ""
equal s = " = " ++ s
lit "" = ""
lit s = "``" ++ s ++ "``" lit s = "``" ++ s ++ "``"
type PGFEnv = (PGF, Map.Map Language Morpho) type PGFEnv = (PGF, Map.Map Language Morpho)
@@ -415,7 +421,8 @@ allCommands env@(pgf, mos) = Map.fromList [
("changes","give a summary of changes from GF 2.9"), ("changes","give a summary of changes from GF 2.9"),
("coding","give advice on character encoding"), ("coding","give advice on character encoding"),
("full","give full information of the commands"), ("full","give full information of the commands"),
("license","show copyright and license information") ("license","show copyright and license information"),
("t2t","output help in txt2tags format")
], ],
exec = \opts ts -> exec = \opts ts ->
let let
@@ -425,7 +432,7 @@ allCommands env@(pgf, mos) = Map.fromList [
_ | isOpt "license" opts -> licenseMsg _ | isOpt "license" opts -> licenseMsg
[t] -> let co = getCommandOp (showExpr [] t) in [t] -> let co = getCommandOp (showExpr [] t) in
case lookCommand co (allCommands env) of ---- new map ??!! case lookCommand co (allCommands env) of ---- new map ??!!
Just info -> commandHelp True (co,info) Just info -> commandHelp' opts True (co,info)
_ -> "command not found" _ -> "command not found"
_ -> commandHelpAll env opts _ -> commandHelpAll env opts
in return (fromString msg), in return (fromString msg),