summaryrefslogtreecommitdiff
path: root/Usage.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-25 12:41:57 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-25 12:41:57 -0400
commitbf0af38ca4e69c83abd95a74379bd8bc672cd0e3 (patch)
tree9fa20f0b4486d4286242f44cf68d7e94bd781aca /Usage.hs
parent70912c45d126b06fe52890e26040bbd180f4f3d8 (diff)
make usage less terrifying
Need to make `git annex help command` show the options for that command.
Diffstat (limited to 'Usage.hs')
-rw-r--r--Usage.hs48
1 files changed, 18 insertions, 30 deletions
diff --git a/Usage.hs b/Usage.hs
index 6259f0b71..32d8b2829 100644
--- a/Usage.hs
+++ b/Usage.hs
@@ -8,41 +8,29 @@
module Usage where
import Common.Annex
-import System.Console.GetOpt
import Types.Command
-{- Usage message with lists of commands and options. -}
-usage :: String -> [Command] -> [Option] -> String
-usage header cmds commonoptions = unlines $
- [ header
- , ""
- , "Options:"
- ] ++ optlines ++ cmdlines
+{- Usage message with lists of commands by section. -}
+usage :: String -> [Command] -> String
+usage header cmds = unlines $ header : concatMap go [minBound..]
where
- -- To get consistent indentation of options, generate the
- -- usage for all options at once. A command's options will
- -- be displayed after the command.
- alloptlines = filter (not . null) $
- lines $ usageInfo "" $
- concatMap cmdoptions scmds ++ commonoptions
- (cmdlines, optlines) = go Nothing scmds alloptlines []
- go _ [] os ls = (ls, os)
- go section (c:cs) os ls = go section' cs os' ls'
+ go section
+ | null cs = []
+ | otherwise =
+ [ ""
+ , descSection section ++ ":"
+ , ""
+ ] ++ map cmdline cs
where
- ls' = ls++sectionheader++(l:o)
- sectionheader
- | section == section' = []
- | otherwise = ["", descSection (cmdsection c) ++ ":", ""]
- section' = Just (cmdsection c)
- (o, os') = splitAt (length $ cmdoptions c) os
- l = concat
- [ cmdname c
- , namepad (cmdname c)
- , cmdparamdesc c
- , descpad (cmdparamdesc c)
- , cmddesc c
- ]
+ cs = filter (\c -> cmdsection c == section) scmds
+ cmdline c = concat
+ [ cmdname c
+ , namepad (cmdname c)
+ , cmdparamdesc c
+ , descpad (cmdparamdesc c)
+ , cmddesc c
+ ]
pad n s = replicate (n - length s) ' '
namepad = pad $ longest cmdname + 1
descpad = pad $ longest cmdparamdesc + 2