cli: general --man, --info flags show the manual
This commit is contained in:
parent
f20cd2b112
commit
54af71a0b1
@ -55,7 +55,13 @@ m4_dnl Should be kept synced with CliOptions.hs etc.
|
|||||||
m4_define({{_helpoptions_}}, {{
|
m4_define({{_helpoptions_}}, {{
|
||||||
|
|
||||||
`-h --help`
|
`-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`
|
`--version`
|
||||||
: show version
|
: show version
|
||||||
|
|||||||
@ -106,7 +106,10 @@ import Hledger.Cli.Version
|
|||||||
-- | Common help flags: --help, --debug, --version...
|
-- | Common help flags: --help, --debug, --version...
|
||||||
helpflags :: [Flag RawOpts]
|
helpflags :: [Flag RawOpts]
|
||||||
helpflags = [
|
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"
|
-- ,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)"
|
,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"
|
,flagNone ["version"] (setboolopt "version") "show version information"
|
||||||
@ -273,8 +276,10 @@ defCommandMode names = defMode {
|
|||||||
,modeGroupFlags = Group {
|
,modeGroupFlags = Group {
|
||||||
groupNamed = []
|
groupNamed = []
|
||||||
,groupUnnamed = [
|
,groupUnnamed = [
|
||||||
flagNone ["help"] (setboolopt "help") "Show usage."
|
flagNone ["help"] (setboolopt "help") "Show command-line help"
|
||||||
-- ,flagNone ["help"] (setboolopt "help") "Show long 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
|
,groupHidden = [] -- flags not displayed in the usage
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,9 +142,15 @@ main = do
|
|||||||
printUsage = putStr $ showModeUsage $ mainmode addons
|
printUsage = putStr $ showModeUsage $ mainmode addons
|
||||||
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure -- PARTIAL:
|
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure -- PARTIAL:
|
||||||
hasHelpFlag args = any (`elem` args) ["-h","--help"]
|
hasHelpFlag args = any (`elem` args) ["-h","--help"]
|
||||||
|
hasManFlag args = any (`elem` args) ["--man"]
|
||||||
|
hasInfoFlag args = any (`elem` args) ["--info"]
|
||||||
f `orShowHelp` mode
|
f `orShowHelp` mode
|
||||||
| hasHelpFlag args = putStr $ showModeUsage mode
|
| hasHelpFlag args = putStr $ showModeUsage mode
|
||||||
|
| hasInfoFlag args = runInfoForTopic "hledger"
|
||||||
|
| hasManFlag args = runManForTopic "hledger"
|
||||||
| otherwise = f
|
| otherwise = f
|
||||||
|
-- where
|
||||||
|
-- lastdocflag
|
||||||
dbgIO "processed opts" opts
|
dbgIO "processed opts" opts
|
||||||
dbgIO "command matched" cmd
|
dbgIO "command matched" cmd
|
||||||
dbgIO "isNullCommand" isNullCommand
|
dbgIO "isNullCommand" isNullCommand
|
||||||
@ -158,10 +164,12 @@ main = do
|
|||||||
journallesserror = error $ cmd++" tried to read the journal but is not supposed to"
|
journallesserror = error $ cmd++" tried to read the journal but is not supposed to"
|
||||||
runHledgerCommand
|
runHledgerCommand
|
||||||
-- high priority flags and situations. -h, then --help, then --info are highest priority.
|
-- high priority flags and situations. -h, then --help, then --info are highest priority.
|
||||||
| hasHelpFlag argsbeforecmd = dbgIO "" "-h before command, showing general usage" >> printUsage
|
| hasHelpFlag argsbeforecmd = dbgIO "" "-h/--help before command, showing general usage" >> printUsage
|
||||||
| not (hasHelpFlag argsaftercmd) && (hasVersion argsbeforecmd || (hasVersion argsaftercmd && isInternalCommand))
|
| 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
|
= putStrLn prognameandversion
|
||||||
| not (hasHelpFlag argsaftercmd) && (hasDetailedVersion argsbeforecmd || (hasDetailedVersion argsaftercmd && isInternalCommand))
|
| not (hasHelpFlag argsaftercmd || hasInfoFlag argsaftercmd || hasManFlag argsaftercmd) && (hasDetailedVersion argsbeforecmd || (hasDetailedVersion argsaftercmd && isInternalCommand))
|
||||||
= putStrLn prognameanddetailedversion
|
= putStrLn prognameanddetailedversion
|
||||||
-- \| (null externalcmd) && "binary-filename" `inRawOpts` rawopts = putStrLn $ binaryfilename progname
|
-- \| (null externalcmd) && "binary-filename" `inRawOpts` rawopts = putStrLn $ binaryfilename progname
|
||||||
-- \| "--browse-args" `elem` args = System.Console.CmdArgs.Helper.execute "cmdargs-browser" mainmode' args >>= (putStr . show)
|
-- \| "--browse-args" `elem` args = System.Console.CmdArgs.Helper.execute "cmdargs-browser" mainmode' args >>= (putStr . show)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user