Revision 0427285d hscan.hs

b/hscan.hs
31 31
import System
32 32
import System.IO
33 33
import System.FilePath
34
import System.Console.GetOpt
35 34
import qualified System
36 35

  
37 36
import Text.Printf (printf)
......
40 39
import qualified Ganeti.HTools.Cluster as Cluster
41 40
import qualified Ganeti.HTools.Node as Node
42 41
import qualified Ganeti.HTools.Instance as Instance
43
import qualified Ganeti.HTools.CLI as CLI
44 42
import qualified Ganeti.HTools.Rapi as Rapi
45 43
import qualified Ganeti.HTools.Loader as Loader
46
import Ganeti.HTools.Types
47 44

  
48
-- | Command line options structure.
49
data Options = Options
50
    { optShowNodes :: Bool     -- ^ Whether to show node status
51
    , optOutPath   :: FilePath -- ^ Path to the output directory
52
    , optVerbose   :: Int      -- ^ Verbosity level
53
    , optNoHeader  :: Bool     -- ^ Do not show a header line
54
    , optShowVer   :: Bool     -- ^ Just show the program version
55
    , optShowHelp  :: Bool     -- ^ Just show the help
56
    } deriving Show
57

  
58
instance CLI.CLIOptions Options where
59
    showVersion = optShowVer
60
    showHelp    = optShowHelp
61

  
62
-- | Default values for the command line options.
63
defaultOptions :: Options
64
defaultOptions  = Options
65
 { optShowNodes = False
66
 , optOutPath   = "."
67
 , optVerbose   = 0
68
 , optNoHeader  = False
69
 , optShowVer   = False
70
 , optShowHelp  = False
71
 }
45
import Ganeti.HTools.CLI
46
import Ganeti.HTools.Types
72 47

  
73 48
-- | Options list and functions
74
options :: [OptDescr (Options -> Options)]
49
options :: [OptType]
75 50
options =
76
    [ Option ['p']     ["print-nodes"]
77
      (NoArg (\ opts -> opts { optShowNodes = True }))
78
      "print the final node list"
79
    , Option ['d']     ["output-dir"]
80
      (ReqArg (\ d opts -> opts { optOutPath = d }) "PATH")
81
      "directory in which to write output files"
82
    , Option ['v']     ["verbose"]
83
      (NoArg (\ opts -> opts { optVerbose = optVerbose opts + 1 }))
84
      "increase the verbosity level"
85
    , Option []        ["no-headers"]
86
      (NoArg (\ opts -> opts { optNoHeader = True }))
87
      "do not show a header line"
88
    , Option ['V']     ["version"]
89
      (NoArg (\ opts -> opts { optShowVer = True}))
90
      "show the version of the program"
91
    , Option ['h']     ["help"]
92
      (NoArg (\ opts -> opts { optShowHelp = True}))
93
      "show help"
51
    [ oPrintNodes
52
    , oOutputDir
53
    , oVerbose
54
    , oNoHeaders
55
    , oShowVer
56
    , oShowHelp
94 57
    ]
95 58

  
96 59
-- | Serialize a single node
......
157 120
main :: IO ()
158 121
main = do
159 122
  cmd_args <- System.getArgs
160
  (opts, clusters) <- CLI.parseOpts cmd_args "hscan" options
161
                      defaultOptions
123
  (opts, clusters) <- parseOpts cmd_args "hscan" options
162 124

  
163 125
  let odir = optOutPath opts
164 126
      nlen = maximum . map length $ clusters
165 127

  
166
  unless (optNoHeader opts) $
128
  unless (optNoHeaders opts) $
167 129
         printf "%-*s %5s %5s %5s %5s %6s %6s %6s %6s %10s\n" nlen
168 130
                "Name" "Nodes" "Inst" "BNode" "BInst" "t_mem" "f_mem"
169 131
                "t_disk" "f_disk" "Score"

Also available in: Unified diff