Revision c3f8cb12 htools/Ganeti/HTools/Program/Hail.hs

b/htools/Ganeti/HTools/Program/Hail.hs
26 26
module Ganeti.HTools.Program.Hail (main, options) where
27 27

  
28 28
import Control.Monad
29
import Data.Maybe (fromMaybe)
29
import Data.Maybe (fromMaybe, isJust)
30 30
import System.IO
31
import System.Exit
31 32

  
32 33
import qualified Ganeti.HTools.Cluster as Cluster
33 34

  
34 35
import Ganeti.HTools.CLI
35 36
import Ganeti.HTools.IAlloc
36 37
import Ganeti.HTools.Loader (Request(..), ClusterData(..))
37
import Ganeti.HTools.ExtLoader (maybeSaveData)
38
import Ganeti.HTools.ExtLoader (maybeSaveData, loadExternalData)
38 39

  
39 40
-- | Options list and functions.
40 41
options :: [OptType]
......
48 49
  , oShowHelp
49 50
  ]
50 51

  
52
wrapReadRequest :: Options -> [String] -> IO Request
53
wrapReadRequest opts args = do
54
  when (null args) $ do
55
    hPutStrLn stderr "Error: this program needs an input file."
56
    exitWith $ ExitFailure 1
57

  
58
  r1 <- readRequest (head args)
59
  if isJust (optDataFile opts) ||  (not . null . optNodeSim) opts
60
    then do
61
      cdata <- loadExternalData opts
62
      let Request rqt _ = r1
63
      return $ Request rqt cdata
64
    else return r1
65

  
66

  
51 67
-- | Main function.
52 68
main :: Options -> [String] -> IO ()
53 69
main opts args = do
......
55 71
      verbose = optVerbose opts
56 72
      savecluster = optSaveCluster opts
57 73

  
58
  request <- readRequest opts args
74
  request <- wrapReadRequest opts args
59 75

  
60 76
  let Request rq cdata = request
61 77

  

Also available in: Unified diff