Revision 638e0a6f
b/htools/Ganeti/DataCollectors/Drbd.hs | ||
---|---|---|
62 | 62 |
arguments :: [ArgCompletion] |
63 | 63 |
arguments = [ArgCompletion OptComplFile 0 (Just 1)] |
64 | 64 |
|
65 |
|
|
66 | 65 |
-- * Command line options |
67 | 66 |
|
68 | 67 |
-- | Main function. |
69 | 68 |
main :: Options -> [String] -> IO () |
70 | 69 |
main _ args = do |
70 |
proc_drbd <- case args of |
|
71 |
[ ] -> return defaultFile |
|
72 |
[x] -> return x |
|
73 |
_ -> exitErr $ "This program takes only one argument," ++ |
|
74 |
" got '" ++ unwords args ++ "'" |
|
71 | 75 |
contents <- |
72 |
((E.try . readFile $ getInputPath args) :: IO (Either IOError String)) >>=
|
|
73 |
exitIfBad "Error reading from file" . either (BT.Bad . show) BT.Ok
|
|
76 |
((E.try $ readFile proc_drbd) :: IO (Either IOError String)) >>=
|
|
77 |
exitIfBad "reading from file" . either (BT.Bad . show) BT.Ok |
|
74 | 78 |
output <- |
75 | 79 |
case A.parse drbdStatusParser $ pack contents of |
76 | 80 |
A.Fail unparsedText contexts errorMessage -> exitErr $ |
... | ... | |
78 | 82 |
++ show contexts ++ "\n" ++ errorMessage |
79 | 83 |
A.Done _ drbdStatus -> return $ encode drbdStatus |
80 | 84 |
putStrLn output |
81 |
where getInputPath a = |
|
82 |
if null a |
|
83 |
then defaultFile |
|
84 |
else head a |
Also available in: Unified diff