cli: make --help/--version always CMD-specific
This simplifies the --help/-h and --version flags by making them position independent: no matter where they appear in the command line, if there is a command argument they will show the command's help or version (where applicable), instead of the hledger executable's.
This commit is contained in:
parent
12447ffab7
commit
4330427f6b
@ -55,16 +55,16 @@ m4_dnl Should be kept synced with CliOptions.hs etc.
|
|||||||
m4_define({{_helpoptions_}}, {{
|
m4_define({{_helpoptions_}}, {{
|
||||||
|
|
||||||
`-h --help`
|
`-h --help`
|
||||||
: show general help (or after COMMAND, command help)
|
: show general or COMMAND help
|
||||||
|
|
||||||
`--man`
|
`--man`
|
||||||
: show user manual with man
|
: show general or COMMAND user manual with man
|
||||||
|
|
||||||
`--info`
|
`--info`
|
||||||
: show user manual with info
|
: show general or COMMAND user manual with info
|
||||||
|
|
||||||
`--version`
|
`--version`
|
||||||
: show version
|
: show general or ADDONCOMMAND version
|
||||||
|
|
||||||
`--debug[=N]`
|
`--debug[=N]`
|
||||||
: show debug output (levels 1-9, default: 1)
|
: show debug output (levels 1-9, default: 1)
|
||||||
|
|||||||
@ -164,12 +164,14 @@ 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/--help before command, showing general usage" >> printUsage
|
| isNullCommand && hasHelpFlag args = dbgIO "" "-h/--help with no command, showing general help" >> printUsage
|
||||||
| hasInfoFlag argsbeforecmd = dbgIO "" "--info before command, showing general info manual" >> runInfoForTopic "hledger" Nothing
|
| isNullCommand && hasInfoFlag args = dbgIO "" "--info with no command, showing general info manual" >> runInfoForTopic "hledger" Nothing
|
||||||
| hasManFlag argsbeforecmd = dbgIO "" "--man before command, showing general man page" >> runManForTopic "hledger" Nothing
|
| isNullCommand && hasManFlag args = dbgIO "" "--man with no command, showing general man page" >> runManForTopic "hledger" Nothing
|
||||||
| not (hasHelpFlag argsaftercmd || hasInfoFlag argsaftercmd || hasManFlag argsaftercmd) && (hasVersion argsbeforecmd || (hasVersion argsaftercmd && isInternalCommand))
|
| not (isExternalCommand || hasHelpFlag args || hasInfoFlag args || hasManFlag args)
|
||||||
|
&& (hasVersion args) -- || (hasVersion argsaftercmd && isInternalCommand))
|
||||||
= putStrLn prognameandversion
|
= putStrLn prognameandversion
|
||||||
| not (hasHelpFlag argsaftercmd || hasInfoFlag argsaftercmd || hasManFlag argsaftercmd) && (hasDetailedVersion argsbeforecmd || (hasDetailedVersion argsaftercmd && isInternalCommand))
|
| not (isExternalCommand || hasHelpFlag args || hasInfoFlag args || hasManFlag args)
|
||||||
|
&& (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)
|
||||||
|
|||||||
@ -1357,8 +1357,7 @@ $ hledger web --serve
|
|||||||
```
|
```
|
||||||
(because the `--serve` flag belongs to `hledger-web`, not `hledger`).
|
(because the `--serve` flag belongs to `hledger-web`, not `hledger`).
|
||||||
|
|
||||||
The `-h/--help` and `--version` flags work without `--`, with their position deciding which program they refer to.
|
The `-h/--help` and `--version` flags don't require `--`.
|
||||||
Eg `hledger -h web` shows hledger's help, `hledger web -h` shows hledger-web's help.
|
|
||||||
|
|
||||||
If you have any trouble with this, remember you can always run the add-on program directly, eg:
|
If you have any trouble with this, remember you can always run the add-on program directly, eg:
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user