Statistics
| Branch: | Tag: | Revision:

root / htools / htools.hs @ d02f941e

History | View | Annotate | Download (2 kB)

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