aboutsummaryrefslogtreecommitdiff
path: root/CmdLine/Usage.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-09 11:49:52 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-09 11:52:47 -0400
commit6ddffe0f0e64a87fd924f736941fa242e0d740a6 (patch)
tree94bc5fed6512ea3cfab47b274cf5534edf889b77 /CmdLine/Usage.hs
parent1e4c1adeae64baa4eb30fd7e1171620c27e0e17f (diff)
let optparse-applicative handle the usage display when run w/o command or bad command
Still generating the list of commands myself, to get it sorted into sections and with short synopses.
Diffstat (limited to 'CmdLine/Usage.hs')
-rw-r--r--CmdLine/Usage.hs8
1 files changed, 6 insertions, 2 deletions
diff --git a/CmdLine/Usage.hs b/CmdLine/Usage.hs
index 0b1cade05..a6cc90a71 100644
--- a/CmdLine/Usage.hs
+++ b/CmdLine/Usage.hs
@@ -13,9 +13,12 @@ import Types.Command
usageMessage :: String -> String
usageMessage s = "Usage: " ++ s
-{- Usage message with lists of commands by section. -}
usage :: String -> [Command] -> String
-usage header cmds = unlines $ usageMessage header : concatMap go [minBound..]
+usage header cmds = unlines $ usageMessage header : commandList cmds
+
+{- Commands listed by section, with breif usage and description. -}
+commandList :: [Command] -> [String]
+commandList cmds = concatMap go [minBound..]
where
go section
| null cs = []
@@ -39,6 +42,7 @@ usage header cmds = unlines $ usageMessage header : concatMap go [minBound..]
longest f = foldl max 0 $ map (length . f) cmds
scmds = sort cmds
+
{- Descriptions of params used in usage messages. -}
paramPaths :: String
paramPaths = paramRepeating paramPath -- most often used