Group subcommands into sections in usage. Closes: #703797
authorJoey Hess <joey@kitenet.net>
Mon, 25 Mar 2013 14:23:05 +0000 (10:23 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 25 Mar 2013 14:23:05 +0000 (10:23 -0400)
Types/Command.hs
Usage.hs
debian/changelog

index 1d64c16d16111784185a62110e045846e8041a4f..1679dcbcaf60d85bb4c9e41c8869e4b21f4d0836 100644 (file)
@@ -53,9 +53,9 @@ instance Eq CommandCheck where
 instance Eq Command where
        a == b = cmdname a == cmdname b
 
-{- Order commands by name -}
+{- Order commands by section and then by name -}
 instance Ord Command where
-       compare = comparing cmdname
+       compare = comparing (\c -> (cmdsection c, cmdname c))
 
 {- The same sections are listed in doc/git-annex.mdwn -}
 data CommandSection 
@@ -66,3 +66,11 @@ data CommandSection
        | SectionUtility
        | SectionPlumbing
        deriving (Eq, Ord, Enum, Bounded)
+
+descSection :: CommandSection -> String
+descSection SectionCommon = "Commonly used commands"
+descSection SectionSetup = "Repository setup commands"
+descSection SectionMaintenance = "Repository maintenance commands"
+descSection SectionQuery = "Query commands"
+descSection SectionUtility = "Utility commands"
+descSection SectionPlumbing = "Plumbing commands"
index fc62bf5d2dfa7f4c1eb3d96ca8a2a12b9ed24c16..6259f0b71a14c9f6464be9c63b1d5900f5c6ed32 100644 (file)
--- a/Usage.hs
+++ b/Usage.hs
@@ -18,11 +18,7 @@ usage header cmds commonoptions = unlines $
        [ header
        , ""
        , "Options:"
-       ] ++ optlines ++
-       [ ""
-       , "Commands:"
-       , ""
-       ] ++ cmdlines
+       ] ++ optlines ++ cmdlines
   where
        -- To get consistent indentation of options, generate the
        -- usage for all options at once. A command's options will
@@ -30,12 +26,17 @@ usage header cmds commonoptions = unlines $
        alloptlines = filter (not . null) $
                lines $ usageInfo "" $
                        concatMap cmdoptions scmds ++ commonoptions
-       (cmdlines, optlines) = go scmds alloptlines []
-       go [] os ls = (ls, os)
-       go (c:cs) os ls = go cs os' (ls++(l:o))
+       (cmdlines, optlines) = go Nothing scmds alloptlines []
+       go [] os ls = (ls, os)
+       go section (c:cs) os ls = go section' cs os' ls'
          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 
+               l = concat
                        [ cmdname c
                        , namepad (cmdname c)
                        , cmdparamdesc c
index 51d17c53b2ab0d330d53a4c8368c13109096f179..885fca35ae8035cc5c28dffafb02aa37a6b042d5 100644 (file)
@@ -1,3 +1,9 @@
+git-annex (4.20130324) UNRELEASED; urgency=low
+
+  * Group subcommands into sections in usage. Closes: #703797
+
+ -- Joey Hess <joeyh@debian.org>  Mon, 25 Mar 2013 10:21:46 -0400
+
 git-annex (4.20130323) unstable; urgency=low
 
   * webapp: Repository list is now included in the dashboard, and other