multiarg-0.30.0.10: Command lines for options that take multiple arguments

Safe HaskellSafe
LanguageHaskell2010

Multiarg.Maddash

Contents

Description

Maddash is a Mealy finite state machine that processes options. Ordinarily you will not need this module; instead, see Multiarg for most uses or Multiarg.Mode for commands that have more than one mode.

The machine consists of the following parts:

  • The set of states, in State
  • The start state, which is Ready
  • The input alphabet, which is all Words. A Word is an input word from the command line.
  • The output alphabet, which is Pallet. A Pallet indicates whether its input is not an option at all with NotAnOption. This indicates that the input Word was not a short option and was not a long option; that is, it was not a single dash followed by a non-dash character and it was not a double dash followed by another character. (Neither a single dash alone nor a double dash alone is an option.) Anything else is an option and will return Full, which is a list of Output. Each Output indicates either an error or a good result.
  • The transition function and the output function are combined into a single function, processWord.

Synopsis

Options and option arguments

newtype OptName #

The name of an option (either a short option name or a long option name).

optSpec #

Arguments

:: [Char]

There is one character for each desired short option name. Each of these characters may not be a hyphen; otherwise, optSpec will apply error.

-> [String]

There is one string for each desired long option name. Each string:

  • cannot be empty;
  • must not begin with a hyphen; and
  • must not contain an equal sign.

Otherwise, optSpec will apply error.

-> ArgSpec a

How many option arguments this option takes. This also specifies what is returned when the option is parsed on the command line.

-> OptSpec a 

Creates an OptSpec.

data ArgSpec a #

Specifies how many option arguments an option takes.

Constructors

ZeroArg a

This option takes no option arguments

OneArg (String -> a)

This option takes one option argument

TwoArg (String -> String -> a)

This option takes two option arguments

ThreeArg (String -> String -> String -> a)

This option takes three option arguments

Instances

Functor ArgSpec # 

Methods

fmap :: (a -> b) -> ArgSpec a -> ArgSpec b #

(<$) :: a -> ArgSpec b -> ArgSpec a #

Show (ArgSpec a) # 

Methods

showsPrec :: Int -> ArgSpec a -> ShowS #

show :: ArgSpec a -> String #

showList :: [ArgSpec a] -> ShowS #

shortName :: Char -> Maybe ShortName #

Creates a short option name. Any character other than a single hyphen will succeed.

longName :: String -> Maybe LongName #

Creates a long option name. The string may not be empty, and the first character may not be a hyphen. In addition, no character may be an equal sign.

Machine components

data Output a #

Constructors

Good a 
OptionError OptionError 

Instances

Functor Output # 

Methods

fmap :: (a -> b) -> Output a -> Output b #

(<$) :: a -> Output b -> Output a #

Eq a => Eq (Output a) # 

Methods

(==) :: Output a -> Output a -> Bool #

(/=) :: Output a -> Output a -> Bool #

Ord a => Ord (Output a) # 

Methods

compare :: Output a -> Output a -> Ordering #

(<) :: Output a -> Output a -> Bool #

(<=) :: Output a -> Output a -> Bool #

(>) :: Output a -> Output a -> Bool #

(>=) :: Output a -> Output a -> Bool #

max :: Output a -> Output a -> Output a #

min :: Output a -> Output a -> Output a #

Show a => Show (Output a) # 

Methods

showsPrec :: Int -> Output a -> ShowS #

show :: Output a -> String #

showList :: [Output a] -> ShowS #

data Pallet a #

Constructors

NotAnOption 
Full [Output a] 

Instances

Functor Pallet # 

Methods

fmap :: (a -> b) -> Pallet a -> Pallet b #

(<$) :: a -> Pallet b -> Pallet a #

Eq a => Eq (Pallet a) # 

Methods

(==) :: Pallet a -> Pallet a -> Bool #

(/=) :: Pallet a -> Pallet a -> Bool #

Ord a => Ord (Pallet a) # 

Methods

compare :: Pallet a -> Pallet a -> Ordering #

(<) :: Pallet a -> Pallet a -> Bool #

(<=) :: Pallet a -> Pallet a -> Bool #

(>) :: Pallet a -> Pallet a -> Bool #

(>=) :: Pallet a -> Pallet a -> Bool #

max :: Pallet a -> Pallet a -> Pallet a #

min :: Pallet a -> Pallet a -> Pallet a #

Show a => Show (Pallet a) # 

Methods

showsPrec :: Int -> Pallet a -> ShowS #

show :: Pallet a -> String #

showList :: [Pallet a] -> ShowS #

data State a #

Constructors

Ready

Accepting new words

Pending OptName (Word -> ([Output a], State a))

In the middle of processing an option; this function will be applied to the next word to get a result

Instances

Functor State # 

Methods

fmap :: (a -> b) -> State a -> State b #

(<$) :: a -> State b -> State a #

Show (State a) # 

Methods

showsPrec :: Int -> State a -> ShowS #

show :: State a -> String #

showList :: [State a] -> ShowS #

processWord :: [(ShortName, ArgSpec a)] -> [(LongName, ArgSpec a)] -> State a -> Word -> (Pallet a, State a) #

Process a single word in the machine.

Multi-word processor

processWords :: [(ShortName, ArgSpec a)] -> [(LongName, ArgSpec a)] -> [Word] -> ([[Output a]], Either (OptName, Word -> ([Output a], State a)) [Word]) #

Processes multiple words in the machine. Processing ends with the first word that is NotAnOption. This first word that is NotAnOption, and all remaining words, are returned in the result. A list of all lists of Output are also returned, with one list for each input Word that was processed. Each of these lists may be of any length. For instance, if the input word is the flag for a long option that takes two option arguments, the corresponding list will be empty. If the input word is a flag for a short option, this list may have more than one element.

Errors

newtype OptArg #

An option argument.

Constructors

OptArg 

Instances