ui, web, api: fix -h, --help
This commit is contained in:
		
							parent
							
								
									ee279fd438
								
							
						
					
					
						commit
						f9362707b6
					
				| @ -57,7 +57,8 @@ Options: | ||||
|                   (default: .) | ||||
|   -p --port PORT  use a different TCP port (default: 8001) | ||||
|      --version    show version | ||||
|   -h --help       show this help | ||||
|   -h              show usage | ||||
|      --help       show detailed help | ||||
| |] | ||||
| 
 | ||||
| swaggerSpec :: Swagger | ||||
| @ -70,7 +71,8 @@ swaggerSpec = toSwagger (Proxy :: Proxy HledgerApi) | ||||
| main :: IO () | ||||
| main = do | ||||
|   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 "swagger")) $ BL8.putStrLn (encode swaggerSpec) >> exitSuccess | ||||
|   let defp = "8001" | ||||
|  | ||||
| @ -42,7 +42,8 @@ main = do | ||||
|   run opts | ||||
|     where | ||||
|       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 | ||||
|         | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) | ||||
|         | otherwise                                                = withJournalDoUICommand opts runBrickUi | ||||
|  | ||||
| @ -43,7 +43,8 @@ hledgerWebMain = do | ||||
| 
 | ||||
| runWith :: WebOpts -> IO () | ||||
| 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 | ||||
|   | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) | ||||
|   | otherwise = do | ||||
|  | ||||
| @ -230,10 +230,16 @@ showModeUsage :: Mode a -> String | ||||
| showModeUsage = (showText defaultWrap :: [Text] -> String) . | ||||
|                (helpText [] HelpFormatDefault :: Mode a -> [Text]) | ||||
| 
 | ||||
| -- | Get a mode's long help, ready for console output | ||||
| -- (currently, the hledger man page formatted for 80 columns). | ||||
| -- | Get a mode's long help, ready for console output.  Currently that | ||||
| -- will be the hledger, hledger-ui, hledger-web or hledger-api man page, | ||||
| -- formatted for 80 columns. | ||||
| 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. | ||||
| withAliases :: String -> [String] -> String | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user