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

Safe HaskellSafe-Inferred
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 Source

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

optSpec Source

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 Source

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

data ShortName Source

A short option name.

data LongName Source

A long option name.

shortName :: Char -> Maybe ShortName Source

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

longName :: String -> Maybe LongName Source

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 Source

Constructors

Good a 
OptionError OptionError 

Instances

Functor Output 
Eq a => Eq (Output a) 
Ord a => Ord (Output a) 
Show a => Show (Output a) 

data Pallet a Source

Constructors

NotAnOption 
Full [Output a] 

Instances

Functor Pallet 
Eq a => Eq (Pallet a) 
Ord a => Ord (Pallet a) 
Show a => Show (Pallet a) 

data State a Source

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

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

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]) Source

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 Source

An option argument.

Constructors

OptArg 

Instances

data OptionError Source

Constructors

BadOption OptName 
LongArgumentForZeroArgumentOption LongName OptArg

The user gave an argument for a long option that does not take an argument.