diff --git a/Makefile.am b/Makefile.am index ba74e2f7940e0f4f794d3ac113d1834d9f241f13..13919b554725d2197f642360b076416b8b169495 100644 --- a/Makefile.am +++ b/Makefile.am @@ -455,6 +455,7 @@ HS_LIB_SRCS = \ htools/Ganeti/Confd/Utils.hs \ htools/Ganeti/Config.hs \ htools/Ganeti/Daemon.hs \ + htools/Ganeti/DataCollectors/CLI.hs \ htools/Ganeti/DataCollectors/Drbd.hs \ htools/Ganeti/DataCollectors/Program.hs \ htools/Ganeti/Errors.hs \ diff --git a/htools/Ganeti/DataCollectors/CLI.hs b/htools/Ganeti/DataCollectors/CLI.hs new file mode 100644 index 0000000000000000000000000000000000000000..b1289b3bc0459e6f39235eecf08ff293812270f1 --- /dev/null +++ b/htools/Ganeti/DataCollectors/CLI.hs @@ -0,0 +1,77 @@ +{-| Implementation of DataCollectors CLI functions. + +This module holds the common command-line related functions for the +collector binaries. + +-} + +{- + +Copyright (C) 2009, 2010, 2011, 2012 Google Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. + +-} + +module Ganeti.DataCollectors.CLI + ( Options(..) + , OptType + , defaultOptions + -- * The options + , oShowHelp + , oShowVer + , oShowComp + , genericOptions + ) where + +import Ganeti.Common as Common + +-- * Data types + +-- | Command line options structure. +data Options = Options + { optShowHelp :: Bool -- ^ Just show the help + , optShowComp :: Bool -- ^ Just show the completion info + , optShowVer :: Bool -- ^ Just show the program version + } deriving Show + +-- | Default values for the command line options. +defaultOptions :: Options +defaultOptions = Options + { optShowHelp = False + , optShowComp = False + , optShowVer = False + } + +-- | Abbreviation for the option type. +type OptType = GenericOptType Options + +instance StandardOptions Options where + helpRequested = optShowHelp + verRequested = optShowVer + compRequested = optShowComp + requestHelp o = o { optShowHelp = True } + requestVer o = o { optShowVer = True } + requestComp o = o { optShowComp = True } + +-- * Command line options + +-- | Generic options. +genericOptions :: [GenericOptType Options] +genericOptions = [ oShowVer + , oShowHelp + , oShowComp + ] diff --git a/htools/Ganeti/DataCollectors/Drbd.hs b/htools/Ganeti/DataCollectors/Drbd.hs index 7d3f893e8d456666023545f65339c074f4fc46dd..5907aac2a0b7914acb1d94c935eee6d42d5f1922 100644 --- a/htools/Ganeti/DataCollectors/Drbd.hs +++ b/htools/Ganeti/DataCollectors/Drbd.hs @@ -39,7 +39,7 @@ import qualified Ganeti.BasicTypes as BT import qualified Ganeti.Constants as C import Ganeti.Block.Drbd.Parser(drbdStatusParser) import Ganeti.Common -import Ganeti.HTools.CLI +import Ganeti.DataCollectors.CLI import Ganeti.Utils diff --git a/htools/Ganeti/DataCollectors/Program.hs b/htools/Ganeti/DataCollectors/Program.hs index 7498be895ee6f85e81cb9b11a8cc5dafabb18edd..63c4cab6e3fe449fd8e2532a71a0fee3795f11e8 100644 --- a/htools/Ganeti/DataCollectors/Program.hs +++ b/htools/Ganeti/DataCollectors/Program.hs @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.DataCollectors.Program (personalities) where import Ganeti.Common (ArgCompletion) -import Ganeti.HTools.CLI (OptType, Options) +import Ganeti.DataCollectors.CLI (OptType, Options) import qualified Ganeti.DataCollectors.Drbd as Drbd diff --git a/htools/Ganeti/HTools/CLI.hs b/htools/Ganeti/HTools/CLI.hs index f08d4364da7507ee0034d47632cd1002e198d8d1..9b6b7f0f52f2fa7b99f6ea6a229899773aac494e 100644 --- a/htools/Ganeti/HTools/CLI.hs +++ b/htools/Ganeti/HTools/CLI.hs @@ -189,7 +189,7 @@ defaultOptions = Options , optVerbose = 1 } --- | Abrreviation for the option type. +-- | Abbreviation for the option type. type OptType = GenericOptType Options instance StandardOptions Options where diff --git a/htools/mon-collector.hs b/htools/mon-collector.hs index 06ff282b1bd47aee92773ca6514dcf2c641bf615..a5a6be846ec97e372fd9eee9074501be3eea5657 100644 --- a/htools/mon-collector.hs +++ b/htools/mon-collector.hs @@ -29,8 +29,9 @@ import Data.Char (toLower) import System.Environment import System.IO +import Ganeti.Common import Ganeti.Utils -import Ganeti.HTools.CLI (parseOpts, genericOpts) +import Ganeti.DataCollectors.CLI (genericOptions, defaultOptions) import Ganeti.DataCollectors.Program (personalities) -- | Display usage and exit. @@ -56,6 +57,6 @@ main = do Just (fn, options, arguments) -> do let actual_args = tail cmd_args real_options <- options - (opts, args) <- parseOpts actual_args name (real_options ++ - genericOpts) arguments + (opts, args) <- parseOpts defaultOptions actual_args name + (real_options ++ genericOptions) arguments fn opts args