ganeti
Safe HaskellNone

Ganeti.Common

Description

Base common functionality.

This module holds common functionality shared across Ganeti daemons, HTools and any other programs.

Synopsis

Documentation

data OptCompletion Source #

Parameter type.

Constructors

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

Instances details
Eq OptCompletion # 
Instance details

Defined in Ganeti.Common

Show OptCompletion # 
Instance details

Defined in Ganeti.Common

Methods

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.

Constructors

ArgCompletion OptCompletion Int (Maybe Int) 

Instances

Instances details
Eq ArgCompletion # 
Instance details

Defined in Ganeti.Common

Show ArgCompletion # 
Instance details

Defined in Ganeti.Common

Methods

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.

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.

parseYesNo Source #

Arguments

:: Bool

Default value (when we get a Nothing)

-> 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.

maxCmdLen :: Int Source #

Max command length when formatting command list output.

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.

showCmdUsage Source #

Arguments

:: 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.

parseOpts Source #

Arguments

:: 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.

parseOptsCmds Source #

Arguments

:: 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