Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.9 kB)

1
{-| Implementation of DataCollectors CLI functions.
2

    
3
This module holds the common command-line related functions for the
4
collector binaries.
5

    
6
-}
7

    
8
{-
9

    
10
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
11

    
12
This program is free software; you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation; either version 2 of the License, or
15
(at your option) any later version.
16

    
17
This program is distributed in the hope that it will be useful, but
18
WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
General Public License for more details.
21

    
22
You should have received a copy of the GNU General Public License
23
along with this program; if not, write to the Free Software
24
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
02110-1301, USA.
26

    
27
-}
28

    
29
module Ganeti.DataCollectors.CLI
30
  ( Options(..)
31
  , OptType
32
  , defaultOptions
33
  -- * The options
34
  , oShowHelp
35
  , oShowVer
36
  , oShowComp
37
  , oDrbdPairing
38
  , oDrbdStatus
39
  , genericOptions
40
  ) where
41

    
42
import System.Console.GetOpt
43

    
44
import Ganeti.BasicTypes
45
import Ganeti.Common as Common
46

    
47
-- * Data types
48

    
49
-- | Command line options structure.
50
data Options = Options
51
  { optShowHelp    :: Bool           -- ^ Just show the help
52
  , optShowComp    :: Bool           -- ^ Just show the completion info
53
  , optShowVer     :: Bool           -- ^ Just show the program version
54
  , optDrbdStatus  :: Maybe FilePath -- ^ Path to the file containing DRBD
55
                                     -- status information
56
  , optDrbdPairing :: Maybe FilePath -- ^ Path to the file containing pairings
57
                                     -- between instances and DRBD minors
58
  } deriving Show
59

    
60
-- | Default values for the command line options.
61
defaultOptions :: Options
62
defaultOptions  = Options
63
  { optShowHelp    = False
64
  , optShowComp    = False
65
  , optShowVer     = False
66
  , optDrbdStatus  = Nothing
67
  , optDrbdPairing = Nothing
68
  }
69

    
70
-- | Abbreviation for the option type.
71
type OptType = GenericOptType Options
72

    
73
instance StandardOptions Options where
74
  helpRequested = optShowHelp
75
  verRequested  = optShowVer
76
  compRequested = optShowComp
77
  requestHelp o = o { optShowHelp = True }
78
  requestVer  o = o { optShowVer  = True }
79
  requestComp o = o { optShowComp = True }
80

    
81
-- * Command line options
82
oDrbdPairing :: OptType
83
oDrbdPairing =
84
  ( Option "p" ["drbd-pairing"]
85
      (ReqArg (\ f o -> Ok o { optDrbdPairing = Just f}) "FILE")
86
      "the FILE containing pairings between instances and DRBD minors",
87
    OptComplFile)
88

    
89
oDrbdStatus :: OptType
90
oDrbdStatus =
91
  ( Option "s" ["drbd-status"]
92
      (ReqArg (\ f o -> Ok o { optDrbdStatus = Just f }) "FILE")
93
      "the DRBD status FILE",
94
    OptComplFile)
95

    
96
-- | Generic options.
97
genericOptions :: [GenericOptType Options]
98
genericOptions =  [ oShowVer
99
                  , oShowHelp
100
                  , oShowComp
101
                  ]