Commit d66aa238 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change type of program options to 'IO [Options]'



Some options have defaults that depend on the environment, and we
could handle these in two ways:

- use a place-holder value (e.g. data X a = Default | Custom a) that
  is later read from the environment
- move the options list to IO monad, where it can read the
  environment, etc.

The second option allows also displaying the actual defaults in the
`--help' output, even though it's not as nice, so I went with it.

This patch only changes the option types, without actually changing
any options yet.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 48483a2e
......@@ -119,8 +119,10 @@ case_wrong_arg =
-- | Test that all binaries support some common options.
case_stdopts :: Assertion
case_stdopts =
mapM_ (\(name, (_, o, a)) -> checkEarlyExit defaultOptions name
(o ++ genericOpts) a) Program.personalities
mapM_ (\(name, (_, o, a)) -> do
o' <- o
checkEarlyExit defaultOptions name
(o' ++ genericOpts) a) Program.personalities
testSuite "HTools/CLI"
[ 'prop_parseISpec
......
......@@ -39,7 +39,8 @@ import qualified Ganeti.HTools.Program.Hinfo as Hinfo
-- | Supported binaries.
personalities :: [(String,
(Options -> [String] -> IO (), [OptType], [ArgCompletion]))]
(Options -> [String] -> IO (), IO [OptType],
[ArgCompletion]))]
personalities = [ ("hail", (Hail.main, Hail.options, Hail.arguments))
, ("hbal", (Hbal.main, Hbal.options, Hbal.arguments))
, ("hcheck", (Hcheck.main, Hcheck.options, Hcheck.arguments))
......
......@@ -43,8 +43,9 @@ import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData)
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
return
[ oPrintNodes
, oSaveCluster
, oDataFile
......
......@@ -62,8 +62,9 @@ import qualified Ganeti.Luxi as L
import Ganeti.Jobs
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
return
[ oPrintNodes
, oPrintInsts
, oPrintCommands
......
......@@ -50,8 +50,9 @@ import Ganeti.HTools.Types
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
return
[ oDataFile
, oDiskMoves
, oDynuFile
......
......@@ -48,8 +48,9 @@ import Ganeti.HTools.Loader
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
return
[ oPrintNodes
, oPrintInsts
, oDataFile
......
......@@ -52,8 +52,9 @@ import Ganeti.Common
import Ganeti.HTools.CLI
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
return
[ oPrintNodes
, oOutputDir
, oLuxiSocket
......
......@@ -53,8 +53,9 @@ import Ganeti.HTools.Loader
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
return
[ oPrintNodes
, oDataFile
, oDiskTemplate
......
......@@ -56,6 +56,7 @@ main = do
Nothing -> usage name
Just (fn, options, arguments) -> do
cmd_args <- getArgs
(opts, args) <- parseOpts cmd_args name (options ++ genericOpts)
real_options <- options
(opts, args) <- parseOpts cmd_args name (real_options ++ genericOpts)
arguments
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