Revision 630c73e5 htools/mon-collector.hs
b/htools/mon-collector.hs | ||
---|---|---|
25 | 25 |
|
26 | 26 |
module Main (main) where |
27 | 27 |
|
28 |
import Data.Char (toLower) |
|
29 |
import System.Environment |
|
30 |
import System.IO |
|
31 |
|
|
32 | 28 |
import Ganeti.Common |
33 |
import Ganeti.Utils |
|
34 | 29 |
import Ganeti.DataCollectors.CLI (genericOptions, defaultOptions) |
35 | 30 |
import Ganeti.DataCollectors.Program (personalities) |
36 | 31 |
|
37 |
-- | Display usage and exit. |
|
38 |
usage :: String -> IO () |
|
39 |
usage name = do |
|
40 |
hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'." |
|
41 |
hPutStrLn stderr "This program must be executed specifying one of the \ |
|
42 |
\following names as the first parameter:" |
|
43 |
mapM_ (hPutStrLn stderr . (" - " ++) . fst) personalities |
|
44 |
exitErr "Please specify the desired role." |
|
45 |
|
|
32 |
-- | Simple main function. |
|
46 | 33 |
main :: IO () |
47 |
main = do |
|
48 |
cmd_args <- getArgs |
|
49 |
let binary = |
|
50 |
if null cmd_args |
|
51 |
then "" |
|
52 |
else head cmd_args |
|
53 |
name = map toLower binary |
|
54 |
boolnames = map (\(x, y) -> (x == name, Just y)) personalities |
|
55 |
case select Nothing boolnames of |
|
56 |
Nothing -> usage name |
|
57 |
Just (fn, options, arguments) -> do |
|
58 |
let actual_args = tail cmd_args |
|
59 |
real_options <- options |
|
60 |
(opts, args) <- parseOpts defaultOptions actual_args name |
|
61 |
(real_options ++ genericOptions) arguments |
|
62 |
fn opts args |
|
34 |
main = genericMainCmds defaultOptions personalities genericOptions |
Also available in: Unified diff