Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / DataCollectors / CLI.hs @ 6d3d13ab

History | View | Annotate | Download (2.9 kB)

1 55abd2c7 Iustin Pop
{-| Implementation of DataCollectors CLI functions.
2 55abd2c7 Iustin Pop
3 55abd2c7 Iustin Pop
This module holds the common command-line related functions for the
4 55abd2c7 Iustin Pop
collector binaries.
5 55abd2c7 Iustin Pop
6 55abd2c7 Iustin Pop
-}
7 55abd2c7 Iustin Pop
8 55abd2c7 Iustin Pop
{-
9 55abd2c7 Iustin Pop
10 55abd2c7 Iustin Pop
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
11 55abd2c7 Iustin Pop
12 55abd2c7 Iustin Pop
This program is free software; you can redistribute it and/or modify
13 55abd2c7 Iustin Pop
it under the terms of the GNU General Public License as published by
14 55abd2c7 Iustin Pop
the Free Software Foundation; either version 2 of the License, or
15 55abd2c7 Iustin Pop
(at your option) any later version.
16 55abd2c7 Iustin Pop
17 55abd2c7 Iustin Pop
This program is distributed in the hope that it will be useful, but
18 55abd2c7 Iustin Pop
WITHOUT ANY WARRANTY; without even the implied warranty of
19 55abd2c7 Iustin Pop
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 55abd2c7 Iustin Pop
General Public License for more details.
21 55abd2c7 Iustin Pop
22 55abd2c7 Iustin Pop
You should have received a copy of the GNU General Public License
23 55abd2c7 Iustin Pop
along with this program; if not, write to the Free Software
24 55abd2c7 Iustin Pop
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 55abd2c7 Iustin Pop
02110-1301, USA.
26 55abd2c7 Iustin Pop
27 55abd2c7 Iustin Pop
-}
28 55abd2c7 Iustin Pop
29 55abd2c7 Iustin Pop
module Ganeti.DataCollectors.CLI
30 55abd2c7 Iustin Pop
  ( Options(..)
31 55abd2c7 Iustin Pop
  , OptType
32 55abd2c7 Iustin Pop
  , defaultOptions
33 55abd2c7 Iustin Pop
  -- * The options
34 55abd2c7 Iustin Pop
  , oShowHelp
35 55abd2c7 Iustin Pop
  , oShowVer
36 55abd2c7 Iustin Pop
  , oShowComp
37 d78970ba Michele Tartara
  , oDrbdPairing
38 d78970ba Michele Tartara
  , oDrbdStatus
39 55abd2c7 Iustin Pop
  , genericOptions
40 55abd2c7 Iustin Pop
  ) where
41 55abd2c7 Iustin Pop
42 d78970ba Michele Tartara
import System.Console.GetOpt
43 d78970ba Michele Tartara
44 d78970ba Michele Tartara
import Ganeti.BasicTypes
45 55abd2c7 Iustin Pop
import Ganeti.Common as Common
46 55abd2c7 Iustin Pop
47 55abd2c7 Iustin Pop
-- * Data types
48 55abd2c7 Iustin Pop
49 55abd2c7 Iustin Pop
-- | Command line options structure.
50 55abd2c7 Iustin Pop
data Options = Options
51 55abd2c7 Iustin Pop
  { optShowHelp    :: Bool           -- ^ Just show the help
52 55abd2c7 Iustin Pop
  , optShowComp    :: Bool           -- ^ Just show the completion info
53 55abd2c7 Iustin Pop
  , optShowVer     :: Bool           -- ^ Just show the program version
54 d78970ba Michele Tartara
  , optDrbdStatus  :: Maybe FilePath -- ^ Path to the file containing DRBD
55 d78970ba Michele Tartara
                                     -- status information
56 d78970ba Michele Tartara
  , optDrbdPairing :: Maybe FilePath -- ^ Path to the file containing pairings
57 d78970ba Michele Tartara
                                     -- between instances and DRBD minors
58 55abd2c7 Iustin Pop
  } deriving Show
59 55abd2c7 Iustin Pop
60 55abd2c7 Iustin Pop
-- | Default values for the command line options.
61 55abd2c7 Iustin Pop
defaultOptions :: Options
62 55abd2c7 Iustin Pop
defaultOptions  = Options
63 55abd2c7 Iustin Pop
  { optShowHelp    = False
64 55abd2c7 Iustin Pop
  , optShowComp    = False
65 55abd2c7 Iustin Pop
  , optShowVer     = False
66 d78970ba Michele Tartara
  , optDrbdStatus  = Nothing
67 d78970ba Michele Tartara
  , optDrbdPairing = Nothing
68 55abd2c7 Iustin Pop
  }
69 55abd2c7 Iustin Pop
70 55abd2c7 Iustin Pop
-- | Abbreviation for the option type.
71 55abd2c7 Iustin Pop
type OptType = GenericOptType Options
72 55abd2c7 Iustin Pop
73 55abd2c7 Iustin Pop
instance StandardOptions Options where
74 55abd2c7 Iustin Pop
  helpRequested = optShowHelp
75 55abd2c7 Iustin Pop
  verRequested  = optShowVer
76 55abd2c7 Iustin Pop
  compRequested = optShowComp
77 55abd2c7 Iustin Pop
  requestHelp o = o { optShowHelp = True }
78 55abd2c7 Iustin Pop
  requestVer  o = o { optShowVer  = True }
79 55abd2c7 Iustin Pop
  requestComp o = o { optShowComp = True }
80 55abd2c7 Iustin Pop
81 55abd2c7 Iustin Pop
-- * Command line options
82 d78970ba Michele Tartara
oDrbdPairing :: OptType
83 d78970ba Michele Tartara
oDrbdPairing =
84 d78970ba Michele Tartara
  ( Option "p" ["drbd-pairing"]
85 d78970ba Michele Tartara
      (ReqArg (\ f o -> Ok o { optDrbdPairing = Just f}) "FILE")
86 d78970ba Michele Tartara
      "the FILE containing pairings between instances and DRBD minors",
87 d78970ba Michele Tartara
    OptComplFile)
88 d78970ba Michele Tartara
89 d78970ba Michele Tartara
oDrbdStatus :: OptType
90 d78970ba Michele Tartara
oDrbdStatus =
91 d78970ba Michele Tartara
  ( Option "s" ["drbd-status"]
92 d78970ba Michele Tartara
      (ReqArg (\ f o -> Ok o { optDrbdStatus = Just f }) "FILE")
93 d78970ba Michele Tartara
      "the DRBD status FILE",
94 d78970ba Michele Tartara
    OptComplFile)
95 55abd2c7 Iustin Pop
96 55abd2c7 Iustin Pop
-- | Generic options.
97 55abd2c7 Iustin Pop
genericOptions :: [GenericOptType Options]
98 55abd2c7 Iustin Pop
genericOptions =  [ oShowVer
99 55abd2c7 Iustin Pop
                  , oShowHelp
100 55abd2c7 Iustin Pop
                  , oShowComp
101 55abd2c7 Iustin Pop
                  ]