{-
-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
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 ()
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