commander-0.1.0.0: pattern matching against string based commands

Safe HaskellNone
LanguageHaskell2010

Commander.Params

Contents

Description

This module provides a couple of basic function parameter types to be used in Commands function definitions. By implementing the same typeclasses, one can create their own custom types to use instead (or as well as) if they prefer.

Synopsis

Function Parameter Types

data Flag flags help a Source

Use this type in a function embedded in a Command in order to require a flag. The type signature for this lists the flags that we want to match against, the associated help text, and the output type we want the flag to be cast to.

Flags of Maybe or Bool types have special handling: if the flag doesnt exist for either of these types, we'll be handed back a False/Nothing rather than get an error, else if the flag does exist we'll get back a True/Just val. Bool flags are expected to be provided an empty string as the value; if you care about the value but want it to be optional, use Maybe.

Constructors

Flag a 

Instances

KnownSymbol help => ParamHelp (Flag flags help a) Source 
KnownSymbols flags => ParamFlags (Flag flags help a) Source 
FromString a => ToParam (Flag flags help a) Source 
ToParam (Flag flags help Bool) Source 
FromString a => ToParam (Flag flags help (Maybe a)) Source 

data Value help a Source

Use this type in a function embedded in a Command in order to require a value. The type signature for this contains the associated help text for the command, and the type we expect the value to be cast to.

Constructors

Value a 

Instances

KnownSymbol help => ParamHelp (Value help a) Source 
ParamFlags (Value help a) Source 
FromString a => ToParam (Value help a) Source 

Casting from String

class FromString a where Source

Typeclass used by Flag and Value to convert the provided string to the desired haskell type. Anything that satisfies Read will satisfy this, but we can override the Read behaviour as we see fit on a per type basis by explicitly implementing this.