From 638e0a6fe04e5973e0bb8ffbe444944d712dcf9b Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 18 Dec 2012 14:41:28 +0100
Subject: [PATCH] Improve mon-collector drbd CLI handling

Currently, this doesn't abort if multiple arguments are passed, and
the error message for errors during file read has a duplicate "Error".

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 htools/Ganeti/DataCollectors/Drbd.hs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/htools/Ganeti/DataCollectors/Drbd.hs b/htools/Ganeti/DataCollectors/Drbd.hs
index 5907aac2a..23c7c8f90 100644
--- a/htools/Ganeti/DataCollectors/Drbd.hs
+++ b/htools/Ganeti/DataCollectors/Drbd.hs
@@ -62,15 +62,19 @@ options = return []
 arguments :: [ArgCompletion]
 arguments = [ArgCompletion OptComplFile 0 (Just 1)]
 
-
 -- * Command line options
 
 -- | Main function.
 main :: Options -> [String] -> IO ()
 main _ args = do
+  proc_drbd <- case args of
+                 [ ] -> return defaultFile
+                 [x] -> return x
+                 _   -> exitErr $ "This program takes only one argument," ++
+                                  " got '" ++ unwords args ++ "'"
   contents <-
-    ((E.try . readFile $ getInputPath args) :: IO (Either IOError String)) >>=
-      exitIfBad "Error reading from file" . either (BT.Bad . show) BT.Ok
+    ((E.try $ readFile proc_drbd) :: IO (Either IOError String)) >>=
+      exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok
   output <-
     case A.parse drbdStatusParser $ pack contents of
       A.Fail unparsedText contexts errorMessage -> exitErr $
@@ -78,7 +82,3 @@ main _ args = do
           ++ show contexts ++ "\n" ++ errorMessage
       A.Done _ drbdStatus -> return $ encode drbdStatus
   putStrLn output
-  where getInputPath a =
-          if null a
-            then defaultFile
-            else head a
-- 
GitLab