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,14 +43,15 @@ import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData)
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
[ oPrintNodes
, oSaveCluster
, oDataFile
, oNodeSim
, oVerbose
]
return
[ oPrintNodes
, oSaveCluster
, oDataFile
, oNodeSim
, oVerbose
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
......
......@@ -62,35 +62,36 @@ import qualified Ganeti.Luxi as L
import Ganeti.Jobs
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
[ oPrintNodes
, oPrintInsts
, oPrintCommands
, oDataFile
, oEvacMode
, oRapiMaster
, oLuxiSocket
, oIAllocSrc
, oExecJobs
, oGroup
, oMaxSolLength
, oVerbose
, oQuiet
, oOfflineNode
, oMinScore
, oMaxCpu
, oMinDisk
, oMinGain
, oMinGainLim
, oDiskMoves
, oSelInst
, oInstMoves
, oDynuFile
, oExTags
, oExInst
, oSaveCluster
]
return
[ oPrintNodes
, oPrintInsts
, oPrintCommands
, oDataFile
, oEvacMode
, oRapiMaster
, oLuxiSocket
, oIAllocSrc
, oExecJobs
, oGroup
, oMaxSolLength
, oVerbose
, oQuiet
, oOfflineNode
, oMinScore
, oMaxCpu
, oMinDisk
, oMinGain
, oMinGainLim
, oDiskMoves
, oSelInst
, oInstMoves
, oDynuFile
, oExTags
, oExInst
, oSaveCluster
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
......
......@@ -50,31 +50,32 @@ import Ganeti.HTools.Types
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
[ oDataFile
, oDiskMoves
, oDynuFile
, oEvacMode
, oExInst
, oExTags
, oIAllocSrc
, oInstMoves
, oLuxiSocket
, oMachineReadable
, oMaxCpu
, oMaxSolLength
, oMinDisk
, oMinGain
, oMinGainLim
, oMinScore
, oNoSimulation
, oOfflineNode
, oQuiet
, oRapiMaster
, oSelInst
, oVerbose
]
return
[ oDataFile
, oDiskMoves
, oDynuFile
, oEvacMode
, oExInst
, oExTags
, oIAllocSrc
, oInstMoves
, oLuxiSocket
, oMachineReadable
, oMaxCpu
, oMaxSolLength
, oMinDisk
, oMinGain
, oMinGainLim
, oMinScore
, oNoSimulation
, oOfflineNode
, oQuiet
, oRapiMaster
, oSelInst
, oVerbose
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
......
......@@ -48,18 +48,19 @@ import Ganeti.HTools.Loader
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
[ oPrintNodes
, oPrintInsts
, oDataFile
, oRapiMaster
, oLuxiSocket
, oIAllocSrc
, oVerbose
, oQuiet
, oOfflineNode
]
return
[ oPrintNodes
, oPrintInsts
, oDataFile
, oRapiMaster
, oLuxiSocket
, oIAllocSrc
, oVerbose
, oQuiet
, oOfflineNode
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
......
......@@ -52,14 +52,15 @@ import Ganeti.Common
import Ganeti.HTools.CLI
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
[ oPrintNodes
, oOutputDir
, oLuxiSocket
, oVerbose
, oNoHeaders
]
return
[ oPrintNodes
, oOutputDir
, oLuxiSocket
, oVerbose
, oNoHeaders
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
......
......@@ -53,27 +53,28 @@ import Ganeti.HTools.Loader
import Ganeti.Utils
-- | Options list and functions.
options :: [OptType]
options :: IO [OptType]
options =
[ oPrintNodes
, oDataFile
, oDiskTemplate
, oSpindleUse
, oNodeSim
, oRapiMaster
, oLuxiSocket
, oIAllocSrc
, oVerbose
, oQuiet
, oOfflineNode
, oMachineReadable
, oMaxCpu
, oMaxSolLength
, oMinDisk
, oStdSpec
, oTieredSpec
, oSaveCluster
]
return
[ oPrintNodes
, oDataFile
, oDiskTemplate
, oSpindleUse
, oNodeSim
, oRapiMaster
, oLuxiSocket
, oIAllocSrc
, oVerbose
, oQuiet
, oOfflineNode
, oMachineReadable
, oMaxCpu
, oMaxSolLength
, oMinDisk
, oStdSpec
, oTieredSpec
, oSaveCluster
]
-- | The list of arguments supported by the program.
arguments :: [ArgCompletion]
......
......@@ -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