Revision 814e1e23 htools/Ganeti/Common.hs

b/htools/Ganeti/Common.hs
38 38
  , oShowComp
39 39
  , usageHelp
40 40
  , versionInfo
41
  , formatCommands
41 42
  , reqWithConversion
42 43
  , parseYesNo
43 44
  , parseOpts
......
199 200
maxCmdLen :: Int
200 201
maxCmdLen = 60
201 202

  
203
-- | Formats the description of various commands.
204
formatCommands :: (StandardOptions a) => PersonalityList a -> [String]
205
formatCommands personalities =
206
  -- FIXME: add wrapping of descriptions
207
  map (\(cmd, (_, _, _, desc)) -> printf " %-*s - %s" mlen cmd desc::String) $
208
  sortBy (comparing fst) personalities
209
    where mlen = min maxCmdLen . maximum $ map (length . fst) personalities
210

  
202 211
-- | Formats usage for a multi-personality program.
203 212
formatCmdUsage :: (StandardOptions a) => String -> PersonalityList a -> String
204 213
formatCmdUsage prog personalities =
205
  let mlen = min maxCmdLen . maximum $ map (length . fst) personalities
206
      sorted = sortBy (comparing fst) personalities
207
      header = [ printf "Usage: %s {command} [options...] [argument...]" prog
214
  let header = [ printf "Usage: %s {command} [options...] [argument...]" prog
208 215
               , printf "%s <command> --help to see details, or man %s"
209 216
                   prog prog
210 217
               , ""
211 218
               , "Commands:"
212 219
               ]
213
      rows = map (\(cmd, (_, _, _, desc)) ->
214
                    -- FIXME: not wrapped here
215
                    printf " %-*s - %s" mlen cmd desc::String) sorted
220
      rows = formatCommands personalities
216 221
  in unlines $ header ++ rows
217 222

  
218 223
-- | Displays usage for a program and exits.

Also available in: Unified diff