ui, web, api: fix -h, --help
This commit is contained in:
parent
ee279fd438
commit
f9362707b6
@ -57,7 +57,8 @@ Options:
|
|||||||
(default: .)
|
(default: .)
|
||||||
-p --port PORT use a different TCP port (default: 8001)
|
-p --port PORT use a different TCP port (default: 8001)
|
||||||
--version show version
|
--version show version
|
||||||
-h --help show this help
|
-h show usage
|
||||||
|
--help show detailed help
|
||||||
|]
|
|]
|
||||||
|
|
||||||
swaggerSpec :: Swagger
|
swaggerSpec :: Swagger
|
||||||
@ -70,7 +71,8 @@ swaggerSpec = toSwagger (Proxy :: Proxy HledgerApi)
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs >>= parseArgsOrExit doc
|
args <- getArgs >>= parseArgsOrExit doc
|
||||||
when (isPresent args (longOption "help")) $ exitWithUsage doc
|
when (isPresent args (shortOption 'h')) $ exitWithUsage doc
|
||||||
|
when (isPresent args (longOption "help")) $ putStr (lookupDocTxt "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 defp = "8001"
|
let defp = "8001"
|
||||||
|
|||||||
@ -42,7 +42,8 @@ main = do
|
|||||||
run opts
|
run opts
|
||||||
where
|
where
|
||||||
run opts
|
run opts
|
||||||
| "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeHelp uimode) >> exitSuccess
|
| "shorthelp" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage uimode) >> exitSuccess
|
||||||
|
| "longhelp" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeHelp 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
|
||||||
|
|||||||
@ -43,7 +43,8 @@ hledgerWebMain = do
|
|||||||
|
|
||||||
runWith :: WebOpts -> IO ()
|
runWith :: WebOpts -> IO ()
|
||||||
runWith opts
|
runWith opts
|
||||||
| "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeHelp webmode) >> exitSuccess
|
| "shorthelp" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage webmode) >> exitSuccess
|
||||||
|
| "longhelp" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeHelp 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
|
||||||
|
|||||||
@ -230,10 +230,16 @@ showModeUsage :: Mode a -> String
|
|||||||
showModeUsage = (showText defaultWrap :: [Text] -> String) .
|
showModeUsage = (showText defaultWrap :: [Text] -> String) .
|
||||||
(helpText [] HelpFormatDefault :: Mode a -> [Text])
|
(helpText [] HelpFormatDefault :: Mode a -> [Text])
|
||||||
|
|
||||||
-- | Get a mode's long help, ready for console output
|
-- | Get a mode's long help, ready for console output. Currently that
|
||||||
-- (currently, the hledger man page formatted for 80 columns).
|
-- will be the hledger, hledger-ui, hledger-web or hledger-api man page,
|
||||||
|
-- formatted for 80 columns.
|
||||||
showModeHelp :: Mode a -> String
|
showModeHelp :: Mode a -> String
|
||||||
showModeHelp _ = lookupDocTxt "cli"
|
showModeHelp m
|
||||||
|
| n == "hledger-ui" = lookupDocTxt "ui"
|
||||||
|
| n == "hledger-web" = lookupDocTxt "web"
|
||||||
|
-- | n == "hledger-api" = lookupDocTxt "api" -- hledger-api uses docopt
|
||||||
|
| otherwise = lookupDocTxt "cli"
|
||||||
|
where n = headDef "" $ modeNames m
|
||||||
|
|
||||||
-- | Add command aliases to the command's help string.
|
-- | Add command aliases to the command's help string.
|
||||||
withAliases :: String -> [String] -> String
|
withAliases :: String -> [String] -> String
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user