Make Query operators enforce strictness
[ganeti-local] / htools / Ganeti / HTools / Program / Hail.hs
index cb334f1..adcddf9 100644 (file)
@@ -32,25 +32,26 @@ module Ganeti.HTools.Program.Hail
 import Control.Monad
 import Data.Maybe (fromMaybe, isJust)
 import System.IO
-import System.Exit
 
 import qualified Ganeti.HTools.Cluster as Cluster
 
 import Ganeti.Common
 import Ganeti.HTools.CLI
-import Ganeti.HTools.IAlloc
+import Ganeti.HTools.Backend.IAlloc
 import Ganeti.HTools.Loader (Request(..), ClusterData(..))
 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]
@@ -58,9 +59,7 @@ arguments = [ArgCompletion OptComplFile 1 (Just 1)]
 
 wrapReadRequest :: Options -> [String] -> IO Request
 wrapReadRequest opts args = do
-  when (null args) $ do
-    hPutStrLn stderr "Error: this program needs an input file."
-    exitWith $ ExitFailure 1
+  when (null args) $ exitErr "This program needs an input file."
 
   r1 <- readRequest (head args)
   if isJust (optDataFile opts) ||  (not . null . optNodeSim) opts