From 559c4a98ec194fc3e300311b313b79aaec2e17bd Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 17 Dec 2012 16:15:01 +0100
Subject: [PATCH] Add description to personality definitions

This allows usage information to display nicer help (like in Python).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
---
 htest/Test/Ganeti/HTools/CLI.hs         |  2 +-
 htools/Ganeti/Common.hs                 |  8 ++++---
 htools/Ganeti/DataCollectors/Program.hs |  4 +++-
 htools/Ganeti/HTools/Program.hs         | 31 +++++++++++++++++++------
 htools/htools.hs                        |  2 +-
 5 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/htest/Test/Ganeti/HTools/CLI.hs b/htest/Test/Ganeti/HTools/CLI.hs
index 5b6b369ec..2ecff7528 100644
--- a/htest/Test/Ganeti/HTools/CLI.hs
+++ b/htest/Test/Ganeti/HTools/CLI.hs
@@ -119,7 +119,7 @@ case_wrong_arg =
 -- | Test that all binaries support some common options.
 case_stdopts :: Assertion
 case_stdopts =
-  mapM_ (\(name, (_, o, a)) -> do
+  mapM_ (\(name, (_, o, a, _)) -> do
            o' <- o
            checkEarlyExit defaultOptions name
              (o' ++ genericOpts) a) Program.personalities
diff --git a/htools/Ganeti/Common.hs b/htools/Ganeti/Common.hs
index 6a4154897..1906b7f49 100644
--- a/htools/Ganeti/Common.hs
+++ b/htools/Ganeti/Common.hs
@@ -96,6 +96,7 @@ data ArgCompletion = ArgCompletion OptCompletion Int (Maybe Int)
 type Personality a = ( a -> [String] -> IO () -- The main function
                      , IO [GenericOptType a]  -- The options
                      , [ArgCompletion]        -- The description of args
+                     , String                 -- Description
                      )
 
 -- | Personality lists type, common across all binaries that expose
@@ -209,8 +210,9 @@ formatCmdUsage prog personalities =
                , ""
                , "Commands:"
                ]
-      rows = map (\(cmd, _) ->
-                    printf " %-*s" mlen cmd::String) sorted
+      rows = map (\(cmd, (_, _, _, desc)) ->
+                    -- FIXME: not wrapped here
+                    printf " %-*s - %s" mlen cmd desc::String) sorted
   in unlines $ header ++ rows
 
 -- | Displays usage for a program and exits.
@@ -266,7 +268,7 @@ parseOptsCmds defaults argv progname personalities genopts = do
                        [] -> usage False
   case cmd `lookup` personalities of
     Nothing -> usage False
-    Just (mainfn, optdefs, argdefs) -> do
+    Just (mainfn, optdefs, argdefs, _) -> do
       optdefs' <- optdefs
       (opts, args) <- parseOpts defaults cmd_args progname
                       (optdefs' ++ genopts) argdefs
diff --git a/htools/Ganeti/DataCollectors/Program.hs b/htools/Ganeti/DataCollectors/Program.hs
index 3bd9b2fb9..4e5ce133d 100644
--- a/htools/Ganeti/DataCollectors/Program.hs
+++ b/htools/Ganeti/DataCollectors/Program.hs
@@ -32,5 +32,7 @@ import qualified Ganeti.DataCollectors.Drbd as Drbd
 
 -- | Supported binaries.
 personalities :: PersonalityList Options
-personalities = [ ("drbd",   (Drbd.main, Drbd.options, Drbd.arguments))
+personalities = [ ("drbd",   (Drbd.main, Drbd.options, Drbd.arguments,
+                             "gathers and displays DRBD statistics in JSON\
+                             \ format"))
                 ]
diff --git a/htools/Ganeti/HTools/Program.hs b/htools/Ganeti/HTools/Program.hs
index 04ed53fb5..7e9554643 100644
--- a/htools/Ganeti/HTools/Program.hs
+++ b/htools/Ganeti/HTools/Program.hs
@@ -39,10 +39,27 @@ import qualified Ganeti.HTools.Program.Hinfo as Hinfo
 
 -- | Supported binaries.
 personalities :: PersonalityList Options
-personalities = [ ("hail",   (Hail.main,   Hail.options,   Hail.arguments))
-                , ("hbal",   (Hbal.main,   Hbal.options,   Hbal.arguments))
-                , ("hcheck", (Hcheck.main, Hcheck.options, Hcheck.arguments))
-                , ("hscan",  (Hscan.main,  Hscan.options,  Hscan.arguments ))
-                , ("hspace", (Hspace.main, Hspace.options, Hspace.arguments))
-                , ("hinfo",  (Hinfo.main,  Hinfo.options,  Hinfo.arguments))
-                ]
+personalities =
+  [ ("hail",   (Hail.main,   Hail.options,   Hail.arguments,
+                "Ganeti IAllocator plugin that implements the instance\
+                \ placement and movement using the same algorithm as\
+                \ hbal(1)"))
+  , ("hbal",   (Hbal.main,   Hbal.options,   Hbal.arguments,
+                "cluster balancer that looks at the current state of\
+                \ the cluster and computes a series of steps designed\
+                \ to bring the cluster into a better state"))
+  , ("hcheck", (Hcheck.main, Hcheck.options, Hcheck.arguments,
+               "cluster checker; prints information about cluster's\
+               \ health and checks whether a rebalance done using\
+               \ hbal would help"))
+  , ("hscan",  (Hscan.main,  Hscan.options,  Hscan.arguments,
+               "tool for scanning clusters via RAPI and saving their\
+               \ data in the input format used by hbal(1) and hspace(1)"))
+  , ("hspace", (Hspace.main, Hspace.options, Hspace.arguments,
+               "computes how many additional instances can be fit on a\
+               \ cluster, while maintaining N+1 status."))
+  , ("hinfo",  (Hinfo.main,  Hinfo.options,  Hinfo.arguments,
+               "cluster information printer; it prints information\
+               \ about the current cluster state and its residing\
+               \ nodes/instances"))
+  ]
diff --git a/htools/htools.hs b/htools/htools.hs
index 1b491e2b4..2dabb5b35 100644
--- a/htools/htools.hs
+++ b/htools/htools.hs
@@ -54,7 +54,7 @@ main = do
       boolnames = map (\(x, y) -> (x == name, Just y)) personalities
   case select Nothing boolnames of
     Nothing -> usage name
-    Just (fn, options, arguments) -> do
+    Just (fn, options, arguments, _) -> do
          cmd_args <- getArgs
          real_options <- options
          (opts, args) <- parseOpts cmd_args name (real_options ++ genericOpts)
-- 
GitLab