Revision 78694255 Ganeti/HTools/CLI.hs
b/Ganeti/HTools/CLI.hs | ||
---|---|---|
76 | 76 |
-- | Whether to be less verbose. |
77 | 77 |
silent :: a -> Bool |
78 | 78 |
|
79 |
-- | Usage info |
|
80 |
usageHelp :: (CLIOptions a) => String -> [OptDescr (a -> a)] -> String |
|
81 |
usageHelp progname options = |
|
82 |
usageInfo (printf "%s %s\nUsage: %s [OPTION...]" |
|
83 |
progname Version.version progname) options |
|
84 |
|
|
79 | 85 |
-- | Command line parser, using the 'options' structure. |
80 | 86 |
parseOpts :: (CLIOptions b) => |
81 | 87 |
[String] -- ^ The command line arguments |
... | ... | |
90 | 96 |
do |
91 | 97 |
let resu@(po, _) = (foldl (flip id) defaultOptions o, n) |
92 | 98 |
when (showHelp po) $ do |
93 |
putStr $ usageInfo header options
|
|
99 |
putStr $ usageHelp progname options
|
|
94 | 100 |
exitWith ExitSuccess |
95 | 101 |
when (showVersion po) $ do |
96 | 102 |
printf "%s %s\ncompiled with %s %s\nrunning on %s %s\n" |
... | ... | |
100 | 106 |
exitWith ExitSuccess |
101 | 107 |
return resu |
102 | 108 |
(_, _, errs) -> |
103 |
ioError (userError (concat errs ++ usageInfo header options)) |
|
104 |
where header = printf "%s %s\nUsage: %s [OPTION...]" |
|
105 |
progname Version.version progname |
|
109 |
ioError (userError (concat errs ++ usageHelp progname options)) |
|
106 | 110 |
|
107 | 111 |
-- | Parse the environment and return the node\/instance names. |
108 | 112 |
-- |
Also available in: Unified diff