Commit 559c4a98 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add description to personality definitions



This allows usage information to display nicer help (like in Python).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 630c73e5
......@@ -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
......
......@@ -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
......
......@@ -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"))
]
......@@ -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"))
]
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment