Commit 42834645 authored by Iustin Pop's avatar Iustin Pop

Remove generic options from individual programs

Currently, we test and require that each individual program (hbal,
etc.) defines/supports the generic options (currently --help and
--version). Even with the test, this is not optimal, since it requires
changes in many places whenever we modify the list of generic options,
hence we move these out of the individual programs and into the
generic CLI handling code.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent d1da5a45
......@@ -118,8 +118,8 @@ case_wrong_arg =
-- | Test that all binaries support some common options.
case_stdopts :: Assertion
case_stdopts =
mapM_ (\(name, (_, o)) -> checkEarlyExit defaultOptions name o)
Program.personalities
mapM_ (\(name, (_, o)) -> checkEarlyExit defaultOptions name
(o ++ genericOpts)) Program.personalities
testSuite "HTools/CLI"
[ 'prop_parseISpec
......
......@@ -149,11 +149,17 @@ oSyslogUsage = Option "" ["syslog"]
\messages); one of 'no', 'yes' or 'only' [" ++ C.syslogUsage ++
"]")
-- | Generic options.
genericOpts :: [OptType]
genericOpts = [ oShowHelp
, oShowVer
]
-- | Small wrapper over getArgs and 'parseOpts'.
parseArgs :: String -> [OptType] -> IO (DaemonOptions, [String])
parseArgs cmd options = do
cmd_args <- getArgs
parseOpts defaultOptions cmd_args cmd options
parseOpts defaultOptions cmd_args cmd $ options ++ genericOpts
-- * Daemon-related functions
-- | PID file mode.
......
......@@ -80,6 +80,7 @@ module Ganeti.HTools.CLI
, oStdSpec
, oTieredSpec
, oVerbose
, genericOpts
) where
import Control.Monad
......@@ -434,6 +435,12 @@ oVerbose = Option "v" ["verbose"]
(NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 }))
"increase the verbosity level"
-- | Generic options.
genericOpts :: [GenericOptType Options]
genericOpts = [ oShowVer
, oShowHelp
]
-- * Functions
-- | Wrapper over 'Common.parseOpts' with our custom options.
......
......@@ -45,8 +45,6 @@ options =
, oDataFile
, oNodeSim
, oVerbose
, oShowVer
, oShowHelp
]
wrapReadRequest :: Options -> [String] -> IO Request
......
......@@ -86,8 +86,6 @@ options =
, oExTags
, oExInst
, oSaveCluster
, oShowVer
, oShowHelp
]
{- | Start computing the solution at the given depth and recurse until
......
......@@ -68,8 +68,6 @@ options =
, oQuiet
, oRapiMaster
, oSelInst
, oShowHelp
, oShowVer
, oVerbose
]
......
......@@ -55,8 +55,6 @@ options =
, oVerbose
, oQuiet
, oOfflineNode
, oShowVer
, oShowHelp
]
-- | Group information data-type.
......
......@@ -54,8 +54,6 @@ options =
, oLuxiSocket
, oVerbose
, oNoHeaders
, oShowVer
, oShowHelp
]
-- | Return a one-line summary of cluster state.
......
......@@ -67,8 +67,6 @@ options =
, oStdSpec
, oTieredSpec
, oSaveCluster
, oShowVer
, oShowHelp
]
-- | The allocation phase we're in (initial, after tiered allocs, or
......
......@@ -33,9 +33,7 @@ import qualified Ganeti.Constants as C
-- | Options list and functions.
options :: [OptType]
options =
[ oShowHelp
, oShowVer
, oNoDaemonize
[ oNoDaemonize
, oNoUserChecks
, oDebug
, oPort C.defaultConfdPort
......
......@@ -35,7 +35,7 @@ import System.IO
import System.IO.Error (isDoesNotExistError)
import Ganeti.HTools.Utils
import Ganeti.HTools.CLI (parseOpts)
import Ganeti.HTools.CLI (parseOpts, genericOpts)
import Ganeti.HTools.Program (personalities)
-- | Display usage and exit.
......@@ -59,5 +59,5 @@ main = do
Nothing -> usage name
Just (fn, options) -> do
cmd_args <- getArgs
(opts, args) <- parseOpts cmd_args name options
(opts, args) <- parseOpts cmd_args name $ options ++ genericOpts
fn opts args
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