Safe Haskell | Safe-Infered |
---|
Base common functionality.
This module holds common functionality shared across Ganeti daemons, HTools and any other programs.
- 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 ()
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 |
Eq OptCompletion | |
Show OptCompletion |
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) |
Eq ArgCompletion | |
Show ArgCompletion |
type Personality a = (a -> [String] -> IO (), IO [GenericOptType a], [ArgCompletion], String)Source
type PersonalityList a = [(String, Personality a)]Source
Personality lists type, common across all binaries that expose multiple personalities.
optComplYesNo :: OptCompletionSource
Yes/no choices completion.
complToText :: OptCompletion -> StringSource
argComplToText :: ArgCompletion -> StringSource
type GenericOptType a = (OptDescr (a -> Result a), OptCompletion)Source
Abrreviation for the option type.
class StandardOptions a whereSource
Type class for options which support help and version.
helpRequested :: a -> BoolSource
verRequested :: a -> BoolSource
compRequested :: a -> BoolSource
requestHelp :: a -> aSource
requestVer :: a -> aSource
requestComp :: a -> aSource
oShowHelp :: StandardOptions a => GenericOptType aSource
Option to request help output.
oShowVer :: StandardOptions a => GenericOptType aSource
Option to request version information.
oShowComp :: StandardOptions a => GenericOptType aSource
Option to request completion information
usageHelp :: String -> [GenericOptType a] -> StringSource
Usage info.
versionInfo :: String -> StringSource
Show the program version info.
completionInfo :: String -> [GenericOptType a] -> [ArgCompletion] -> StringSource
:: 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 -> StringSource
showCmdUsage :: StandardOptions a => String -> PersonalityList a -> Bool -> IO bSource
multiCmdCompletion :: StandardOptions a => PersonalityList a -> StringSource
showCmdCompletion :: StandardOptions a => PersonalityList a -> IO bSource
:: 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.