Safe Haskell | None |
---|
Base common functionality.
This module holds common functionality shared across Ganeti daemons, HTools and any other programs.
Synopsis
- data OptCompletion
- = OptComplNone
- | OptComplFile
- | OptComplDir
- | OptComplHost
- | OptComplInetAddr
- | OptComplOneNode
- | OptComplManyNodes
- | OptComplOneInstance
- | OptComplManyInstances
- | OptComplOneOs
- | OptComplOneIallocator
- | OptComplInstAddNodes
- | OptComplOneGroup
- | OptComplInteger
- | OptComplFloat
- | OptComplJobId
- | OptComplCommand
- | OptComplString
- | OptComplChoices [String]
- | OptComplSuggest [String]
- data ArgCompletion = ArgCompletion OptCompletion Int (Maybe Int)
- type Personality a = (a -> [String] -> IO (), IO [GenericOptType a], [ArgCompletion], String)
- type PersonalityList a = [(String, Personality a)]
- optComplYesNo :: OptCompletion
- complToText :: OptCompletion -> String
- argComplToText :: ArgCompletion -> String
- type GenericOptType a = (OptDescr (a -> Result a), OptCompletion)
- class StandardOptions a where
- helpRequested :: a -> Bool
- verRequested :: a -> Bool
- compRequested :: a -> Bool
- requestHelp :: a -> a
- requestVer :: a -> a
- requestComp :: a -> a
- oShowHelp :: StandardOptions a => GenericOptType a
- oShowVer :: StandardOptions a => GenericOptType a
- oShowComp :: StandardOptions a => GenericOptType a
- usageHelp :: String -> [GenericOptType a] -> String
- versionInfo :: String -> String
- completionInfo :: String -> [GenericOptType a] -> [ArgCompletion] -> String
- parseYesNo :: Bool -> Maybe String -> Result Bool
- reqWithConversion :: (String -> Result a) -> (a -> b -> Result b) -> String -> ArgDescr (b -> Result b)
- maxCmdLen :: Int
- formatCommands :: StandardOptions a => PersonalityList a -> [String]
- formatCmdUsage :: StandardOptions a => String -> PersonalityList a -> String
- showCmdUsage :: StandardOptions a => String -> PersonalityList a -> Bool -> IO b
- multiCmdCompletion :: StandardOptions a => PersonalityList a -> String
- showCmdCompletion :: StandardOptions a => PersonalityList a -> IO b
- parseOpts :: StandardOptions a => a -> [String] -> String -> [GenericOptType a] -> [ArgCompletion] -> IO (a, [String])
- parseOptsCmds :: StandardOptions a => a -> [String] -> String -> PersonalityList a -> [GenericOptType a] -> IO (a, [String], a -> [String] -> IO ())
- parseOptsInner :: StandardOptions a => a -> [String] -> String -> [GenericOptType a] -> [ArgCompletion] -> Either (ExitCode, String) (a, [String])
- genericMainCmds :: StandardOptions a => a -> PersonalityList a -> [GenericOptType a] -> IO ()
- fillUpList :: ([(a, b)] -> a -> (a, b)) -> [a] -> [(a, b)] -> [(a, b)]
- fillPairFromMaybe :: (a -> (a, b)) -> (a -> [(a, b)] -> Maybe (a, b)) -> [(a, b)] -> a -> (a, b)
- isMatchingPair :: Eq a => a -> (a, b) -> Bool
- pickPairUnique :: Eq a => a -> [(a, b)] -> Maybe (a, b)
Documentation
data OptCompletion Source #
Parameter type.
OptComplNone | No parameter to this option |
OptComplFile | An existing file |
OptComplDir | An existing directory |
OptComplHost | Host name |
OptComplInetAddr | One ipv4/ipv6 address |
OptComplOneNode | One node |
OptComplManyNodes | Many nodes, comma-sep |
OptComplOneInstance | One instance |
OptComplManyInstances | Many instances, comma-sep |
OptComplOneOs | One OS name |
OptComplOneIallocator | One iallocator |
OptComplInstAddNodes | Either one or two nodes |
OptComplOneGroup | One group |
OptComplInteger | Integer values |
OptComplFloat | Float values |
OptComplJobId | Job Id |
OptComplCommand | Command (executable) |
OptComplString | Arbitrary string |
OptComplChoices [String] | List of string choices |
OptComplSuggest [String] | Suggested choices |
Instances
Eq OptCompletion # | |
Defined in Ganeti.Common (==) :: OptCompletion -> OptCompletion -> Bool (/=) :: OptCompletion -> OptCompletion -> Bool | |
Show OptCompletion # | |
Defined in Ganeti.Common showsPrec :: Int -> OptCompletion -> ShowS show :: OptCompletion -> String showList :: [OptCompletion] -> ShowS |
data ArgCompletion Source #
Argument type. This differs from (and wraps) an Option by the fact that it can (and usually does) support multiple repetitions of the same argument, via a min and max limit.
ArgCompletion OptCompletion Int (Maybe Int) |
Instances
Eq ArgCompletion # | |
Defined in Ganeti.Common (==) :: ArgCompletion -> ArgCompletion -> Bool (/=) :: ArgCompletion -> ArgCompletion -> Bool | |
Show ArgCompletion # | |
Defined in Ganeti.Common showsPrec :: Int -> ArgCompletion -> ShowS show :: ArgCompletion -> String showList :: [ArgCompletion] -> ShowS |
type Personality a = (a -> [String] -> IO (), IO [GenericOptType a], [ArgCompletion], String) Source #
A personality definition.
type PersonalityList a = [(String, Personality a)] Source #
Personality lists type, common across all binaries that expose multiple personalities.
optComplYesNo :: OptCompletion Source #
Yes/no choices completion.
complToText :: OptCompletion -> String Source #
Text serialisation for OptCompletion
, used on the Python side.
argComplToText :: ArgCompletion -> String Source #
Text serialisation for ArgCompletion
.
type GenericOptType a = (OptDescr (a -> Result a), OptCompletion) Source #
Abbreviation for the option type.
class StandardOptions a where Source #
Type class for options which support help and version.
helpRequested :: a -> Bool Source #
verRequested :: a -> Bool Source #
compRequested :: a -> Bool Source #
requestHelp :: a -> a Source #
requestVer :: a -> a Source #
requestComp :: a -> a Source #
Instances
StandardOptions Options # | |
Defined in Ganeti.HTools.CLI helpRequested :: Options -> Bool Source # verRequested :: Options -> Bool Source # compRequested :: Options -> Bool Source # requestHelp :: Options -> Options Source # requestVer :: Options -> Options Source # requestComp :: Options -> Options Source # | |
StandardOptions Options # | |
Defined in Ganeti.DataCollectors.CLI helpRequested :: Options -> Bool Source # verRequested :: Options -> Bool Source # compRequested :: Options -> Bool Source # requestHelp :: Options -> Options Source # requestVer :: Options -> Options Source # requestComp :: Options -> Options Source # | |
StandardOptions DaemonOptions # | |
Defined in Ganeti.Daemon helpRequested :: DaemonOptions -> Bool Source # verRequested :: DaemonOptions -> Bool Source # compRequested :: DaemonOptions -> Bool Source # requestHelp :: DaemonOptions -> DaemonOptions Source # |
oShowHelp :: StandardOptions a => GenericOptType a Source #
Option to request help output.
oShowVer :: StandardOptions a => GenericOptType a Source #
Option to request version information.
oShowComp :: StandardOptions a => GenericOptType a Source #
Option to request completion information
usageHelp :: String -> [GenericOptType a] -> String Source #
Usage info.
versionInfo :: String -> String Source #
Show the program version info.
completionInfo :: String -> [GenericOptType a] -> [ArgCompletion] -> String Source #
Show completion info.
:: Bool | Default value (when we get a |
-> Maybe String | Parameter value |
-> Result Bool | Resulting boolean value |
Helper for parsing a yes/no command line flag.
reqWithConversion :: (String -> Result a) -> (a -> b -> Result b) -> String -> ArgDescr (b -> Result b) Source #
Helper function for required arguments which need to be converted as opposed to stored just as string.
formatCommands :: StandardOptions a => PersonalityList a -> [String] Source #
Formats the description of various commands.
formatCmdUsage :: StandardOptions a => String -> PersonalityList a -> String Source #
Formats usage for a multi-personality program.
:: StandardOptions a | |
=> String | Program name |
-> PersonalityList a | Personality list |
-> Bool | Whether the exit code is success or not |
-> IO b |
Displays usage for a program and exits.
multiCmdCompletion :: StandardOptions a => PersonalityList a -> String Source #
Generates completion information for a multi-command binary.
showCmdCompletion :: StandardOptions a => PersonalityList a -> IO b Source #
Displays completion information for a multi-command binary and exits.
:: StandardOptions a | |
=> a | The default options |
-> [String] | The command line arguments |
-> String | The program name |
-> [GenericOptType a] | The supported command line options |
-> [ArgCompletion] | The supported command line arguments |
-> IO (a, [String]) | The resulting options and leftover arguments |
Command line parser, using a generic Options
structure.
:: StandardOptions a | |
=> a | The default options |
-> [String] | The command line arguments |
-> String | The program name |
-> PersonalityList a | The supported commands |
-> [GenericOptType a] | Generic options |
-> IO (a, [String], a -> [String] -> IO ()) | The resulting options and leftover arguments |
Command line parser, for programs with sub-commands.
parseOptsInner :: StandardOptions a => a -> [String] -> String -> [GenericOptType a] -> [ArgCompletion] -> Either (ExitCode, String) (a, [String]) Source #
Inner parse options. The arguments are similar to parseOpts
,
but it returns either a Left
composed of exit code and message,
or a Right
for the success case.
genericMainCmds :: StandardOptions a => a -> PersonalityList a -> [GenericOptType a] -> IO () Source #
Parse command line options and execute the main function of a multi-personality binary.
fillUpList :: ([(a, b)] -> a -> (a, b)) -> [a] -> [(a, b)] -> [(a, b)] Source #
Order a list of pairs in the order of the given list and fill up the list for elements that don't have a matching pair
fillPairFromMaybe :: (a -> (a, b)) -> (a -> [(a, b)] -> Maybe (a, b)) -> [(a, b)] -> a -> (a, b) Source #
Fill up a pair with fillup element if no matching pair is present
isMatchingPair :: Eq a => a -> (a, b) -> Bool Source #
Check if the given element matches the given pair
pickPairUnique :: Eq a => a -> [(a, b)] -> Maybe (a, b) Source #
Pick a specific element's pair from the list