{-| Implementation of command-line functions.
-This module holds the common cli-related functions for the binaries,
-separated into this module since Utils.hs is used in many other places
-and this is more IO oriented.
+This module holds the common command-line related functions for the
+binaries, separated into this module since "Ganeti.HTools.Utils" is
+used in many other places and this is more IO oriented.
-}
, oPrintNodes
, oQuiet
, oRapiMaster
+ , oReplay
, oSaveCluster
, oShowHelp
, oShowVer
import Ganeti.HTools.Types
import Ganeti.HTools.Utils
--- | The default value for the luxi socket
+-- * Constants
+
+-- | The default value for the luxi socket.
+--
+-- This is re-exported from the "Ganeti.Constants" module.
defaultLuxiSocket :: FilePath
defaultLuxiSocket = C.masterSocket
+-- * Data types
+
-- | Command line options structure.
data Options = Options
{ optDataFile :: Maybe FilePath -- ^ Path to the cluster data file
, optShowNodes :: Maybe [String] -- ^ Whether to show node status
, optShowVer :: Bool -- ^ Just show the program version
, optTieredSpec :: Maybe RSpec -- ^ Requested specs for tiered mode
+ , optReplay :: Maybe String -- ^ Unittests: RNG state
, optVerbose :: Int -- ^ Verbosity level
} deriving Show
, optShowNodes = Nothing
, optShowVer = False
, optTieredSpec = Nothing
+ , optReplay = Nothing
, optVerbose = 1
}
--- | Abrreviation for the option type
+-- | Abrreviation for the option type.
type OptType = OptDescr (Options -> Result Options)
+-- * Command line options
+
oDataFile :: OptType
oDataFile = Option "t" ["text-data"]
(ReqArg (\ f o -> Ok o { optDataFile = Just f }) "FILE")
"TSPEC")
"enable tiered specs allocation, given as 'disk,ram,cpu'"
+oReplay :: OptType
+oReplay = Option "" ["replay"]
+ (ReqArg (\ stat opts -> Ok opts { optReplay = Just stat } ) "STATE")
+ "Pre-seed the random number generator with STATE"
+
oVerbose :: OptType
oVerbose = Option "v" ["verbose"]
(NoArg (\ opts -> Ok opts { optVerbose = optVerbose opts + 1 }))
"increase the verbosity level"
--- | Usage info
+-- * Functions
+
+-- | Usage info.
usageHelp :: String -> [OptType] -> String
usageHelp progname =
usageInfo (printf "%s %s\nUsage: %s [OPTION...]"
progname Version.version progname)
--- | Command line parser, using the 'options' structure.
+-- | Command line parser, using the 'Options' structure.
parseOpts :: [String] -- ^ The command line arguments
-> String -- ^ The program name
-> [OptType] -- ^ The supported command line options