1 {-| Main htools binary.
7 Copyright (C) 2011 Google Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 module Main (main) where
28 import Data.Char (toLower)
29 import System.Environment
33 import Ganeti.HTools.Utils
34 import qualified Ganeti.HTools.Program.Hail as Hail
35 import qualified Ganeti.HTools.Program.Hbal as Hbal
36 import qualified Ganeti.HTools.Program.Hscan as Hscan
37 import qualified Ganeti.HTools.Program.Hspace as Hspace
39 -- | Supported binaries.
40 personalities :: [(String, IO ())]
41 personalities = [ ("hail", Hail.main)
43 , ("hscan", Hscan.main)
44 , ("hspace", Hspace.main)
47 -- | Display usage and exit.
48 usage :: String -> IO ()
50 hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'."
51 hPutStrLn stderr "This program must be installed under one of the following\
53 mapM_ (hPutStrLn stderr . (" - " ++) . fst) personalities
54 hPutStrLn stderr "Please either rename/symlink the program or set\n\
55 \the environment variable HTOOLS to the desired role."
56 exitWith $ ExitFailure 1
60 binary <- getEnv "HTOOLS" `catch` const getProgName
61 let name = map toLower binary
62 boolnames = map (\(x, y) -> (x == name, y)) personalities
63 select (usage name) boolnames