cli: general --man, --info flags show the manual

This commit is contained in:
Simon Michael 2020-12-25 21:12:22 -08:00
parent f20cd2b112
commit 54af71a0b1
3 changed files with 25 additions and 6 deletions

View File

@ -55,7 +55,13 @@ m4_dnl Should be kept synced with CliOptions.hs etc.
m4_define({{_helpoptions_}}, {{
`-h --help`
: show general usage (or after COMMAND, command usage)
: show general help (or after COMMAND, command help)
`--man`
: show user manual with man
`--info`
: show user manual with info
`--version`
: show version

View File

@ -106,7 +106,10 @@ import Hledger.Cli.Version
-- | Common help flags: --help, --debug, --version...
helpflags :: [Flag RawOpts]
helpflags = [
flagNone ["help","h"] (setboolopt "help") "show general usage (or after CMD, command usage)"
-- XXX why are these duplicated in defCommandMode below ?
flagNone ["help","h"] (setboolopt "help") "show general help (or after CMD, command help)"
,flagNone ["man"] (setboolopt "man") "Show user manual with man"
,flagNone ["info"] (setboolopt "info") "Show info manual with info"
-- ,flagNone ["browse-args"] (setboolopt "browse-args") "use a web UI to select options and build up a command line"
,flagReq ["debug"] (\s opts -> Right $ setopt "debug" s opts) "[N]" "show debug output (levels 1-9, default: 1)"
,flagNone ["version"] (setboolopt "version") "show version information"
@ -273,8 +276,10 @@ defCommandMode names = defMode {
,modeGroupFlags = Group {
groupNamed = []
,groupUnnamed = [
flagNone ["help"] (setboolopt "help") "Show usage."
flagNone ["help"] (setboolopt "help") "Show command-line help"
-- ,flagNone ["help"] (setboolopt "help") "Show long help."
,flagNone ["man"] (setboolopt "man") "Show user manual with man"
,flagNone ["info"] (setboolopt "info") "Show info manual with info"
]
,groupHidden = [] -- flags not displayed in the usage
}

View File

@ -142,9 +142,15 @@ main = do
printUsage = putStr $ showModeUsage $ mainmode addons
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure -- PARTIAL:
hasHelpFlag args = any (`elem` args) ["-h","--help"]
hasManFlag args = any (`elem` args) ["--man"]
hasInfoFlag args = any (`elem` args) ["--info"]
f `orShowHelp` mode
| hasHelpFlag args = putStr $ showModeUsage mode
| hasInfoFlag args = runInfoForTopic "hledger"
| hasManFlag args = runManForTopic "hledger"
| otherwise = f
-- where
-- lastdocflag
dbgIO "processed opts" opts
dbgIO "command matched" cmd
dbgIO "isNullCommand" isNullCommand
@ -158,10 +164,12 @@ main = do
journallesserror = error $ cmd++" tried to read the journal but is not supposed to"
runHledgerCommand
-- high priority flags and situations. -h, then --help, then --info are highest priority.
| hasHelpFlag argsbeforecmd = dbgIO "" "-h before command, showing general usage" >> printUsage
| not (hasHelpFlag argsaftercmd) && (hasVersion argsbeforecmd || (hasVersion argsaftercmd && isInternalCommand))
| hasHelpFlag argsbeforecmd = dbgIO "" "-h/--help before command, showing general usage" >> printUsage
| hasInfoFlag argsbeforecmd = dbgIO "" "--info before command, showing general info manual" >> runInfoForTopic "hledger"
| hasManFlag argsbeforecmd = dbgIO "" "--man before command, showing general man page" >> runManForTopic "hledger"
| not (hasHelpFlag argsaftercmd || hasInfoFlag argsaftercmd || hasManFlag argsaftercmd) && (hasVersion argsbeforecmd || (hasVersion argsaftercmd && isInternalCommand))
= putStrLn prognameandversion
| not (hasHelpFlag argsaftercmd) && (hasDetailedVersion argsbeforecmd || (hasDetailedVersion argsaftercmd && isInternalCommand))
| not (hasHelpFlag argsaftercmd || hasInfoFlag argsaftercmd || hasManFlag argsaftercmd) && (hasDetailedVersion argsbeforecmd || (hasDetailedVersion argsaftercmd && isInternalCommand))
= putStrLn prognameanddetailedversion
-- \| (null externalcmd) && "binary-filename" `inRawOpts` rawopts = putStrLn $ binaryfilename progname
-- \| "--browse-args" `elem` args = System.Console.CmdArgs.Helper.execute "cmdargs-browser" mainmode' args >>= (putStr . show)