make --help and -h the same, drop --man and --info for now (#579)

This commit is contained in:
Simon Michael 2017-07-07 02:00:46 +01:00
parent 23c77a3ae8
commit 7e896572a7
8 changed files with 23 additions and 57 deletions

View File

@ -239,6 +239,6 @@ main = do
rawopts <- fmap decodeRawOpts . processArgs $ cmdmode rawopts <- fmap decodeRawOpts . processArgs $ cmdmode
opts <- rawOptsToCliOpts rawopts opts <- rawOptsToCliOpts rawopts
case find (\e -> command_ opts `elem` modeNames (fst e)) actions of case find (\e -> command_ opts `elem` modeNames (fst e)) actions of
Just (amode, _) | "h" `elem` map fst (rawopts_ opts) -> print amode Just (amode, _) | "help" `elem` map fst (rawopts_ opts) -> print amode
Just (_, action) -> action opts Just (_, action) -> action opts
Nothing -> print cmdmode Nothing -> print cmdmode

View File

@ -67,18 +67,9 @@ m4_define({{_timedot_}}, {{```timedot$1```}} )m4_dnl
m4_dnl m4_dnl
m4_define({{_helpoptions_}}, {{ m4_define({{_helpoptions_}}, {{
`-h` `-h --help`
: show general usage (or after COMMAND, command usage) : show general usage (or after COMMAND, command usage)
`--help`
: show this program's manual as plain text (or after an add-on COMMAND, the add-on's manual)
`--man`
: show this program's manual with man
`--info`
: show this program's manual with info
`--version` `--version`
: show version : show version

View File

@ -60,18 +60,9 @@ Note: if invoking hledger-api as a hledger subcommand, write `--` before options
`--version` `--version`
: show version : show version
`-h` `-h --help`
: show usage : show usage
`--help`
: show manual as plain text
`--man`
: show manual with man
`--info`
: show manual with info
_man_({{ _man_({{

View File

@ -50,7 +50,7 @@ Usage:
hledger-api --swagger hledger-api --swagger
print API docs in Swagger 2.0 format print API docs in Swagger 2.0 format
hledger-api --version hledger-api --version
hledger-api -h|--help|--man|--info hledger-api -h|--help
Options: Options:
-f --file FILE use a different input file -f --file FILE use a different input file
@ -60,10 +60,7 @@ Options:
--host IPADDR listen on this IP address (default: 127.0.0.1) --host IPADDR listen on this IP address (default: 127.0.0.1)
-p --port PORT listen on this TCP port (default: 8001) -p --port PORT listen on this TCP port (default: 8001)
--version show version --version show version
-h show usage -h --help show usage
--help show manual
--man show manual with man
--info show manual with info
|] |]
swaggerSpec :: Swagger swaggerSpec :: Swagger
@ -76,10 +73,7 @@ swaggerSpec = toSwagger (Proxy :: Proxy HledgerApi)
main :: IO () main :: IO ()
main = do main = do
args <- getArgs >>= parseArgsOrExit doc args <- getArgs >>= parseArgsOrExit doc
when (isPresent args (shortOption 'h')) $ exitWithUsage doc when (isPresent args (shortOption 'h') || isPresent args (longOption "help")) $ exitWithUsage doc
when (isPresent args (longOption "help")) $ printHelpForTopic "api" >> exitSuccess
when (isPresent args (longOption "man")) $ runManForTopic "api" >> exitSuccess
when (isPresent args (longOption "info")) $ runInfoForTopic "api" >> exitSuccess
when (isPresent args (longOption "version")) $ putStrLn hledgerApiVersion >> exitSuccess when (isPresent args (longOption "version")) $ putStrLn hledgerApiVersion >> exitSuccess
when (isPresent args (longOption "swagger")) $ BL8.putStrLn (encode swaggerSpec) >> exitSuccess when (isPresent args (longOption "swagger")) $ BL8.putStrLn (encode swaggerSpec) >> exitSuccess
let let

View File

@ -66,10 +66,7 @@ main = do
run opts run opts
where where
run opts run opts
| "h" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage uimode) >> exitSuccess | "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage uimode) >> exitSuccess
| "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = printHelpForTopic (topicForMode uimode) >> exitSuccess
| "man" `inRawOpts` (rawopts_ $ cliopts_ opts) = runManForTopic (topicForMode uimode) >> exitSuccess
| "info" `inRawOpts` (rawopts_ $ cliopts_ opts) = runInfoForTopic (topicForMode uimode) >> exitSuccess
| "version" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess | "version" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess
| "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname)
| otherwise = withJournalDoUICommand opts runBrickUi | otherwise = withJournalDoUICommand opts runBrickUi

View File

@ -43,10 +43,7 @@ hledgerWebMain = do
runWith :: WebOpts -> IO () runWith :: WebOpts -> IO ()
runWith opts runWith opts
| "h" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage webmode) >> exitSuccess | "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage webmode) >> exitSuccess
| "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = printHelpForTopic (topicForMode webmode) >> exitSuccess
| "man" `inRawOpts` (rawopts_ $ cliopts_ opts) = runManForTopic (topicForMode webmode) >> exitSuccess
| "info" `inRawOpts` (rawopts_ $ cliopts_ opts) = runInfoForTopic (topicForMode webmode) >> exitSuccess
| "version" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess | "version" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess
| "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname)
| otherwise = do | otherwise = do

View File

@ -102,10 +102,7 @@ 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 ["h"] (setboolopt "h") "show general usage (or after CMD, command usage)" flagNone ["help","h"] (setboolopt "help") "show general usage (or after CMD, command usage)"
,flagNone ["help"] (setboolopt "help") "show this program's manual as plain text (or after an addon CMD, the add-on's manual)"
,flagNone ["man"] (setboolopt "man") "show this program's manual with man"
,flagNone ["info"] (setboolopt "info") "show this program's 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"
@ -200,7 +197,7 @@ defCommandMode names = defMode {
,modeGroupFlags = Group { ,modeGroupFlags = Group {
groupNamed = [] groupNamed = []
,groupUnnamed = [ ,groupUnnamed = [
flagNone ["h"] (setboolopt "h") "Show usage." flagNone ["help"] (setboolopt "help") "Show usage."
-- ,flagNone ["help"] (setboolopt "help") "Show long help." -- ,flagNone ["help"] (setboolopt "help") "Show long help."
] ]
,groupHidden = [] -- flags not displayed in the usage ,groupHidden = [] -- flags not displayed in the usage
@ -447,8 +444,8 @@ getHledgerCliOpts mode' = do
let rawopts = either usageError decodeRawOpts $ process mode' args' let rawopts = either usageError decodeRawOpts $ process mode' args'
opts <- rawOptsToCliOpts rawopts opts <- rawOptsToCliOpts rawopts
debugArgs args' opts debugArgs args' opts
when ("help" `inRawOpts` rawopts_ opts) $ putStr longhelp >> exitSuccess when ("help" `inRawOpts` rawopts_ opts) $ putStr shorthelp >> exitSuccess
when ("h" `inRawOpts` rawopts_ opts) $ putStr shorthelp >> exitSuccess -- when ("help" `inRawOpts` rawopts_ opts) $ putStr longhelp >> exitSuccess
return opts return opts
where where
longhelp = showModeUsage mode' longhelp = showModeUsage mode'
@ -457,7 +454,7 @@ getHledgerCliOpts mode' = do
(reverse $ dropWhile null $ reverse $ takeWhile (not . ("flags:" `isInfixOf`)) $ lines longhelp) (reverse $ dropWhile null $ reverse $ takeWhile (not . ("flags:" `isInfixOf`)) $ lines longhelp)
++ ++
["" [""
," See --help for full detail, including common hledger options." ," See manual for full detail, including common hledger options." -- TODO
] ]
-- | Print debug info about arguments and options if --debug is present. -- | Print debug info about arguments and options if --debug is present.
debugArgs :: [String] -> CliOpts -> IO () debugArgs :: [String] -> CliOpts -> IO ()

View File

@ -127,15 +127,12 @@ mainmode addons = defMode {
PROGNAME list commands PROGNAME list commands
PROGNAME CMD [--] [OPTS] [ARGS] run a command (use -- with addon commands) PROGNAME CMD [--] [OPTS] [ARGS] run a command (use -- with addon commands)
PROGNAME-CMD [OPTS] [ARGS] or run addon commands directly PROGNAME-CMD [OPTS] [ARGS] or run addon commands directly
PROGNAME -h general usage PROGNAME -h show general usage
PROGNAME CMD -h command usage PROGNAME CMD -h show command usage
PROGNAME --help PROGNAME manual PROGNAME help list available manuals
PROGNAME --man PROGNAME manual as man page PROGNAME help MANUAL show a manual as plain text
PROGNAME --info PROGNAME manual as info manual PROGNAME man MANUAL show a manual as man page
PROGNAME help list help topics PROGNAME info MANUAL show a manual as info manual
PROGNAME help TOPIC TOPIC manual
PROGNAME man TOPIC TOPIC manual as man page
PROGNAME info TOPIC TOPIC manual as info manual
|] |]
} }
@ -264,8 +261,10 @@ Misc:
rewrite add automated postings to certain transactions rewrite add automated postings to certain transactions
test run some self tests test run some self tests
OTHERCMDS OTHERCMDS
Help: (see also -h, CMD -h, --help|--man|--info) Help:
help|man|info show any of the hledger manuals in text/man/info format hledger -h show general usage
hledger CMD -h show command usage
help|man|info show any of the hledger manuals in plain text/man/info format
|] |]
knownCommands :: [String] knownCommands :: [String]