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 = ...@@ -119,8 +119,10 @@ case_wrong_arg =
-- | Test that all binaries support some common options. -- | Test that all binaries support some common options.
case_stdopts :: Assertion case_stdopts :: Assertion
case_stdopts = case_stdopts =
mapM_ (\(name, (_, o, a)) -> checkEarlyExit defaultOptions name mapM_ (\(name, (_, o, a)) -> do
(o ++ genericOpts) a) Program.personalities o' <- o
checkEarlyExit defaultOptions name
(o' ++ genericOpts) a) Program.personalities
testSuite "HTools/CLI" testSuite "HTools/CLI"
[ 'prop_parseISpec [ 'prop_parseISpec
......
...@@ -39,7 +39,8 @@ import qualified Ganeti.HTools.Program.Hinfo as Hinfo ...@@ -39,7 +39,8 @@ import qualified Ganeti.HTools.Program.Hinfo as Hinfo
-- | Supported binaries. -- | Supported binaries.
personalities :: [(String, personalities :: [(String,
(Options -> [String] -> IO (), [OptType], [ArgCompletion]))] (Options -> [String] -> IO (), IO [OptType],
[ArgCompletion]))]
personalities = [ ("hail", (Hail.main, Hail.options, Hail.arguments)) personalities = [ ("hail", (Hail.main, Hail.options, Hail.arguments))
, ("hbal", (Hbal.main, Hbal.options, Hbal.arguments)) , ("hbal", (Hbal.main, Hbal.options, Hbal.arguments))
, ("hcheck", (Hcheck.main, Hcheck.options, Hcheck.arguments)) , ("hcheck", (Hcheck.main, Hcheck.options, Hcheck.arguments))
......
...@@ -43,14 +43,15 @@ import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData) ...@@ -43,14 +43,15 @@ import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData)
import Ganeti.Utils import Ganeti.Utils
-- | Options list and functions. -- | Options list and functions.
options :: [OptType] options :: IO [OptType]
options = options =
[ oPrintNodes return
, oSaveCluster [ oPrintNodes
, oDataFile , oSaveCluster
, oNodeSim , oDataFile
, oVerbose , oNodeSim
] , oVerbose
]
-- | The list of arguments supported by the program. -- | The list of arguments supported by the program.
arguments :: [ArgCompletion] arguments :: [ArgCompletion]
......
...@@ -62,35 +62,36 @@ import qualified Ganeti.Luxi as L ...@@ -62,35 +62,36 @@ import qualified Ganeti.Luxi as L
import Ganeti.Jobs import Ganeti.Jobs
-- | Options list and functions. -- | Options list and functions.
options :: [OptType] options :: IO [OptType]
options = options =
[ oPrintNodes return
, oPrintInsts [ oPrintNodes
, oPrintCommands , oPrintInsts
, oDataFile , oPrintCommands
, oEvacMode , oDataFile
, oRapiMaster , oEvacMode
, oLuxiSocket , oRapiMaster
, oIAllocSrc , oLuxiSocket
, oExecJobs , oIAllocSrc
, oGroup , oExecJobs
, oMaxSolLength , oGroup
, oVerbose , oMaxSolLength
, oQuiet , oVerbose
, oOfflineNode , oQuiet
, oMinScore , oOfflineNode
, oMaxCpu , oMinScore
, oMinDisk , oMaxCpu
, oMinGain , oMinDisk
, oMinGainLim , oMinGain
, oDiskMoves , oMinGainLim
, oSelInst , oDiskMoves
, oInstMoves , oSelInst
, oDynuFile , oInstMoves
, oExTags , oDynuFile
, oExInst , oExTags
, oSaveCluster , oExInst
] , oSaveCluster
]
-- | The list of arguments supported by the program. -- | The list of arguments supported by the program.
arguments :: [ArgCompletion] arguments :: [ArgCompletion]
......
...@@ -50,31 +50,32 @@ import Ganeti.HTools.Types ...@@ -50,31 +50,32 @@ import Ganeti.HTools.Types
import Ganeti.Utils import Ganeti.Utils
-- | Options list and functions. -- | Options list and functions.
options :: [OptType] options :: IO [OptType]
options = options =
[ oDataFile return
, oDiskMoves [ oDataFile
, oDynuFile , oDiskMoves
, oEvacMode , oDynuFile
, oExInst , oEvacMode
, oExTags , oExInst
, oIAllocSrc , oExTags
, oInstMoves , oIAllocSrc
, oLuxiSocket , oInstMoves
, oMachineReadable , oLuxiSocket
, oMaxCpu , oMachineReadable
, oMaxSolLength , oMaxCpu
, oMinDisk , oMaxSolLength
, oMinGain , oMinDisk
, oMinGainLim , oMinGain
, oMinScore , oMinGainLim
, oNoSimulation , oMinScore
, oOfflineNode , oNoSimulation
, oQuiet , oOfflineNode
, oRapiMaster , oQuiet
, oSelInst , oRapiMaster
, oVerbose , oSelInst
] , oVerbose
]
-- | The list of arguments supported by the program. -- | The list of arguments supported by the program.
arguments :: [ArgCompletion] arguments :: [ArgCompletion]
......
...@@ -48,18 +48,19 @@ import Ganeti.HTools.Loader ...@@ -48,18 +48,19 @@ import Ganeti.HTools.Loader
import Ganeti.Utils import Ganeti.Utils
-- | Options list and functions. -- | Options list and functions.
options :: [OptType] options :: IO [OptType]
options = options =
[ oPrintNodes return
, oPrintInsts [ oPrintNodes
, oDataFile , oPrintInsts
, oRapiMaster , oDataFile
, oLuxiSocket , oRapiMaster
, oIAllocSrc , oLuxiSocket
, oVerbose , oIAllocSrc
, oQuiet , oVerbose
, oOfflineNode , oQuiet
] , oOfflineNode
]
-- | The list of arguments supported by the program. -- | The list of arguments supported by the program.
arguments :: [ArgCompletion] arguments :: [ArgCompletion]
......
...@@ -52,14 +52,15 @@ import Ganeti.Common ...@@ -52,14 +52,15 @@ import Ganeti.Common
import Ganeti.HTools.CLI import Ganeti.HTools.CLI
-- | Options list and functions. -- | Options list and functions.
options :: [OptType] options :: IO [OptType]
options = options =
[ oPrintNodes return
, oOutputDir [ oPrintNodes
, oLuxiSocket , oOutputDir
, oVerbose , oLuxiSocket
, oNoHeaders , oVerbose
] , oNoHeaders
]
-- | The list of arguments supported by the program. -- | The list of arguments supported by the program.
arguments :: [ArgCompletion] arguments :: [ArgCompletion]
......
...@@ -53,27 +53,28 @@ import Ganeti.HTools.Loader ...@@ -53,27 +53,28 @@ import Ganeti.HTools.Loader
import Ganeti.Utils import Ganeti.Utils
-- | Options list and functions. -- | Options list and functions.
options :: [OptType] options :: IO [OptType]
options = options =
[ oPrintNodes return
, oDataFile [ oPrintNodes
, oDiskTemplate , oDataFile
, oSpindleUse , oDiskTemplate
, oNodeSim , oSpindleUse
, oRapiMaster , oNodeSim
, oLuxiSocket , oRapiMaster
, oIAllocSrc , oLuxiSocket
, oVerbose , oIAllocSrc
, oQuiet , oVerbose
, oOfflineNode , oQuiet
, oMachineReadable , oOfflineNode
, oMaxCpu , oMachineReadable
, oMaxSolLength , oMaxCpu
, oMinDisk , oMaxSolLength
, oStdSpec , oMinDisk
, oTieredSpec , oStdSpec
, oSaveCluster , oTieredSpec
] , oSaveCluster
]
-- | The list of arguments supported by the program. -- | The list of arguments supported by the program.
arguments :: [ArgCompletion] arguments :: [ArgCompletion]
......
...@@ -56,6 +56,7 @@ main = do ...@@ -56,6 +56,7 @@ main = do
Nothing -> usage name Nothing -> usage name
Just (fn, options, arguments) -> do Just (fn, options, arguments) -> do
cmd_args <- getArgs cmd_args <- getArgs
(opts, args) <- parseOpts cmd_args name (options ++ genericOpts) real_options <- options
(opts, args) <- parseOpts cmd_args name (real_options ++ genericOpts)
arguments arguments
fn opts args 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