Statistics
| Branch: | Tag: | Revision:

root / htools / htools.hs @ 72bb6b4e

History | View | Annotate | Download (2 kB)

1
{-| Main htools binary.
2

    
3
-}
4

    
5
{-
6

    
7
Copyright (C) 2011 Google Inc.
8

    
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.
13

    
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.
18

    
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
22
02110-1301, USA.
23

    
24
-}
25

    
26
module Main (main) where
27

    
28
import Data.Char (toLower)
29
import System
30
import System.IO
31

    
32
import Ganeti.HTools.Utils
33
import qualified Ganeti.HTools.Program.Hail as Hail
34
import qualified Ganeti.HTools.Program.Hbal as Hbal
35
import qualified Ganeti.HTools.Program.Hscan as Hscan
36
import qualified Ganeti.HTools.Program.Hspace as Hspace
37

    
38
-- | Supported binaries.
39
personalities :: [(String, IO ())]
40
personalities = [ ("hail", Hail.main)
41
                , ("hbal", Hbal.main)
42
                , ("hscan", Hscan.main)
43
                , ("hspace", Hspace.main)
44
                ]
45

    
46
-- | Display usage and exit.
47
usage :: String -> IO ()
48
usage name = do
49
  hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'."
50
  hPutStrLn stderr "This program must be installed under one of the following\
51
                   \ names:"
52
  mapM_ (hPutStrLn stderr . ("  - " ++) . fst) personalities
53
  hPutStrLn stderr "Please either rename/symlink the program or set\n\
54
                   \the environment variable HTOOLS to the desired role."
55
  exitWith $ ExitFailure 1
56

    
57
main :: IO ()
58
main = do
59
  binary <- getEnv "HTOOLS" `catch` (\_ -> getProgName)
60
  let name = map toLower binary
61
      boolnames = map (\(x, y) -> (x == name, y)) personalities
62
  select (usage name) boolnames