diff options
-rw-r--r-- | CmdLine.hs | 2 | ||||
-rw-r--r-- | GitAnnexShell.hs | 2 | ||||
-rw-r--r-- | Types/Command.hs | 4 | ||||
-rw-r--r-- | Usage.hs | 48 |
4 files changed, 22 insertions, 34 deletions
diff --git a/CmdLine.hs b/CmdLine.hs index 0b155215d..489935453 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -45,7 +45,7 @@ dispatch fuzzyok allargs allcmds commonoptions fields header getgitrepo = do prepCommand cmd params tryRun state' cmd $ [startup] ++ actions ++ [shutdown $ cmdnocommit cmd] where - err msg = msg ++ "\n\n" ++ usage header allcmds commonoptions + err msg = msg ++ "\n\n" ++ usage header allcmds cmd = Prelude.head cmds (fuzzy, cmds, name, args) = findCmd fuzzyok allargs allcmds err (flags, params) = getOptCmd args cmd commonoptions err diff --git a/GitAnnexShell.hs b/GitAnnexShell.hs index fca36cfc5..0431b06f2 100644 --- a/GitAnnexShell.hs +++ b/GitAnnexShell.hs @@ -126,7 +126,7 @@ checkField (field, value) | otherwise = False failure :: IO () -failure = error $ "bad parameters\n\n" ++ usage header cmds options +failure = error $ "bad parameters\n\n" ++ usage header cmds checkNotLimited :: IO () checkNotLimited = checkEnv "GIT_ANNEX_SHELL_LIMITED" diff --git a/Types/Command.hs b/Types/Command.hs index 1679dcbca..4b92ca173 100644 --- a/Types/Command.hs +++ b/Types/Command.hs @@ -53,9 +53,9 @@ instance Eq CommandCheck where instance Eq Command where a == b = cmdname a == cmdname b -{- Order commands by section and then by name -} +{- Order commands by name. -} instance Ord Command where - compare = comparing (\c -> (cmdsection c, cmdname c)) + compare = comparing cmdname {- The same sections are listed in doc/git-annex.mdwn -} data CommandSection @@ -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 |