Revision 209b3711 hbal.hs
b/hbal.hs | ||
---|---|---|
16 | 16 |
|
17 | 17 |
import qualified Ganeti.HTools.Container as Container |
18 | 18 |
import qualified Ganeti.HTools.Cluster as Cluster |
19 |
import qualified Ganeti.HTools.Version as Version |
|
20 | 19 |
import qualified Ganeti.HTools.Node as Node |
20 |
import qualified Ganeti.HTools.CLI as CLI |
|
21 | 21 |
import Ganeti.HTools.Rapi |
22 | 22 |
import Ganeti.HTools.Utils |
23 | 23 |
|
... | ... | |
31 | 31 |
, optMaxLength :: Int -- ^ Stop after this many steps |
32 | 32 |
, optMaster :: String -- ^ Collect data from RAPI |
33 | 33 |
, optVerbose :: Int -- ^ Verbosity level |
34 |
, optShowVer :: Bool -- ^ Just show the program version |
|
35 | 34 |
, optOffline :: [String] -- ^ Names of offline nodes |
35 |
, optShowVer :: Bool -- ^ Just show the program version |
|
36 |
, optShowHelp :: Bool -- ^ Just show the help |
|
36 | 37 |
} deriving Show |
37 | 38 |
|
38 | 39 |
-- | Default values for the command line options. |
... | ... | |
46 | 47 |
, optMaxLength = -1 |
47 | 48 |
, optMaster = "" |
48 | 49 |
, optVerbose = 0 |
49 |
, optShowVer = False |
|
50 | 50 |
, optOffline = [] |
51 |
, optShowVer = False |
|
52 |
, optShowHelp = False |
|
51 | 53 |
} |
52 | 54 |
|
53 | 55 |
-- | Options list and functions |
... | ... | |
76 | 78 |
"cap the solution at this many moves (useful for very unbalanced \ |
77 | 79 |
\clusters)" |
78 | 80 |
, Option ['v'] ["verbose"] |
79 |
(NoArg (\ opts -> let nv = (optVerbose opts) |
|
80 |
in opts { optVerbose = nv + 1 })) |
|
81 |
(NoArg (\ opts -> opts { optVerbose = (optVerbose opts) + 1 })) |
|
81 | 82 |
"increase the verbosity level" |
82 |
, Option ['V'] ["version"] |
|
83 |
(NoArg (\ opts -> opts { optShowVer = True})) |
|
84 |
"show the version of the program" |
|
85 | 83 |
, Option ['O'] ["offline"] |
86 | 84 |
(ReqArg (\ n opts -> opts { optOffline = n:optOffline opts }) "NODE") |
87 | 85 |
" set node as offline" |
86 |
, Option ['V'] ["version"] |
|
87 |
(NoArg (\ opts -> opts { optShowVer = True})) |
|
88 |
"show the version of the program" |
|
89 |
, Option ['h'] ["help"] |
|
90 |
(NoArg (\ opts -> opts { optShowHelp = True})) |
|
91 |
"show help" |
|
88 | 92 |
] |
89 | 93 |
|
90 |
-- | Command line parser, using the 'options' structure. |
|
91 |
parseOpts :: [String] -> IO (Options, [String]) |
|
92 |
parseOpts argv = |
|
93 |
case getOpt Permute options argv of |
|
94 |
(o,n,[] ) -> |
|
95 |
return (foldl (flip id) defaultOptions o, n) |
|
96 |
(_,_,errs) -> |
|
97 |
ioError (userError (concat errs ++ usageInfo header options)) |
|
98 |
where header = printf "hbal %s\nUsage: hbal [OPTION...]" |
|
99 |
Version.version |
|
100 |
|
|
101 | 94 |
{- | Start computing the solution at the given depth and recurse until |
102 | 95 |
we find a valid solution or we exceed the maximum depth. |
103 | 96 |
|
... | ... | |
144 | 137 |
main :: IO () |
145 | 138 |
main = do |
146 | 139 |
cmd_args <- System.getArgs |
147 |
(opts, _) <- parseOpts cmd_args
|
|
140 |
(opts, _) <- CLI.parseOpts cmd_args "hbal" options defaultOptions optShowHelp
|
|
148 | 141 |
|
149 | 142 |
when (optShowVer opts) $ do |
150 |
putStr $ showVersion "hbal" |
|
143 |
putStr $ CLI.showVersion "hbal"
|
|
151 | 144 |
exitWith ExitSuccess |
152 | 145 |
|
153 | 146 |
let oneline = optOneline opts |
Also available in: Unified diff