Commit 55abd2c7 authored by Iustin Pop's avatar Iustin Pop

Add a custom CLI module for DataCollectors

Currently, the mon-collector binary uses the HTools/CLI module, which
is OK but mean it links in lots of htools code. By copying that module
to DataCollectors/CLI and removing the unneeded code, we reduce the
number of modules it depends on fro 20 to 12, meaning both a shorter
compiler time (24s to 9s) and a smaller binary (~9.6MB to ~7MB).

Also fixes a typo in the original HTools/CLI module, thanks Michele!
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 675f65b7
......@@ -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 \
......
{-| 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
]
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment