Split the Node_addOffline test into pri/sec
[ganeti-local] / htools / htools.hs
index acf1a50..f35c18c 100644 (file)
@@ -4,7 +4,7 @@
 
 {-
 
-Copyright (C) 2011 Google Inc.
+Copyright (C) 2011, 2012 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -26,20 +26,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 module Main (main) where
 
 import Data.Char (toLower)
-import System
+import System.Environment
+import System.Exit
 import System.IO
 
 import Ganeti.HTools.Utils
-import qualified Ganeti.HTools.Program.Hail as Hail
-import qualified Ganeti.HTools.Program.Hbal as Hbal
-import qualified Ganeti.HTools.Program.Hscan as Hscan
-
--- | Supported binaries.
-personalities :: [(String, IO ())]
-personalities = [ ("hail", Hail.main)
-                , ("hbal", Hbal.main)
-                , ("hscan", Hscan.main)
-                ]
+import Ganeti.HTools.CLI (parseOpts)
+import Ganeti.HTools.Program (personalities)
 
 -- | Display usage and exit.
 usage :: String -> IO ()
@@ -54,7 +47,12 @@ usage name = do
 
 main :: IO ()
 main = do
-  binary <- getEnv "HTOOLS" `catch` (\_ -> getProgName)
+  binary <- getEnv "HTOOLS" `catch` const getProgName
   let name = map toLower binary
-      boolnames = map (\(x, y) -> (x == name, y)) personalities
-  select (usage name) boolnames
+      boolnames = map (\(x, y) -> (x == name, Just y)) personalities
+  case select Nothing boolnames of
+    Nothing -> usage name
+    Just (fn, options) -> do
+         cmd_args <- getArgs
+         (opts, args) <- parseOpts cmd_args name options
+         fn opts args