Add a CLI parameter for input files
authorMichele Tartara <mtartara@google.com>
Wed, 29 May 2013 20:09:22 +0000 (20:09 +0000)
committerMichele Tartara <mtartara@google.com>
Mon, 3 Jun 2013 15:09:46 +0000 (11:09 -0400)
For many data collectors it is useful (especially for testing) to have to
possibility to specify an input file.

This commit adds a generic option for doing that.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

src/Ganeti/DataCollectors/CLI.hs

index 3c58a3f..db30441 100644 (file)
@@ -39,6 +39,7 @@ module Ganeti.DataCollectors.CLI
   , oNode
   , oConfdAddr
   , oConfdPort
+  , oInputFile
   , genericOptions
   ) where
 
@@ -64,6 +65,8 @@ data Options = Options
   , optConfdAddr   :: Maybe String   -- ^ IP address of the Confd server
   , optConfdPort   :: Maybe Int      -- ^ The port of the Confd server to
                                      -- connect to
+  , optInputFile   :: Maybe FilePath -- ^ Path to the file containing the
+                                     -- information to be parsed
   } deriving Show
 
 -- | Default values for the command line options.
@@ -77,6 +80,7 @@ defaultOptions  = Options
   , optNode        = Nothing
   , optConfdAddr   = Nothing
   , optConfdPort   = Nothing
+  , optInputFile   = Nothing
   }
 
 -- | Abbreviation for the option type.
@@ -127,6 +131,13 @@ oConfdPort =
     "Network port of the Confd server to connect to",
     OptComplInteger)
 
+oInputFile :: OptType
+oInputFile =
+  ( Option "f" ["file"]
+      (ReqArg (\ f o -> Ok o { optInputFile = Just f }) "FILE")
+      "the input FILE",
+    OptComplFile)
+
 -- | Generic options.
 genericOptions :: [GenericOptType Options]
 genericOptions =  [ oShowVer