summaryrefslogtreecommitdiff
path: root/Usage.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-27 13:51:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-27 13:51:24 -0400
commitd010ee969c82d6bb2d0f60c4b1ce2de3543e0920 (patch)
treefef62e7155b8ae9977ce51294339693f548cd964 /Usage.hs
parent3b1d7915569b0dbfa6cefc54e0537d19290e08bf (diff)
Per-command usage messages.
Diffstat (limited to 'Usage.hs')
-rw-r--r--Usage.hs21
1 files changed, 20 insertions, 1 deletions
diff --git a/Usage.hs b/Usage.hs
index 32d8b2829..a9c8fa7f2 100644
--- a/Usage.hs
+++ b/Usage.hs
@@ -11,9 +11,14 @@ import Common.Annex
import Types.Command
+import System.Console.GetOpt
+
+usageMessage :: String -> String
+usageMessage s = "Usage: " ++ s
+
{- Usage message with lists of commands by section. -}
usage :: String -> [Command] -> String
-usage header cmds = unlines $ header : concatMap go [minBound..]
+usage header cmds = unlines $ usageMessage header : concatMap go [minBound..]
where
go section
| null cs = []
@@ -37,6 +42,20 @@ usage header cmds = unlines $ header : concatMap go [minBound..]
longest f = foldl max 0 $ map (length . f) cmds
scmds = sort cmds
+{- Usage message for a single command. -}
+commandUsage :: Command -> String
+commandUsage cmd = unlines
+ [ usageInfo header (cmdoptions cmd)
+ , "To see additional options common to all commands, run: git annex help options"
+ ]
+ where
+ header = usageMessage $ unwords
+ [ "git-annex"
+ , cmdname cmd
+ , cmdparamdesc cmd
+ , "[option ...]"
+ ]
+
{- Descriptions of params used in usage messages. -}
paramPaths :: String
paramPaths = paramOptional $ paramRepeating paramPath -- most often used