curly-0.59.4.2: A minimal cross-compiler for the simply-typed lambda-calculus

Safe HaskellNone
LanguageHaskell2010

Language.Syntax.CmdArgs

Contents

Synopsis

Exported modules

Preprocessing command-line arguments

data OptDescr a :: * -> * #

Each OptDescr describes a single option.

The arguments to Option are:

  • list of short option characters
  • list of long option strings (without "--")
  • argument descriptor
  • explanation of option for user

Constructors

Option [Char] [String] (ArgDescr a) String 

Instances

Functor OptDescr 

Methods

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

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

data ArgDescr a :: * -> * #

Describes whether an option takes an argument or not, and if so how the argument is injected into a value of type a.

Constructors

NoArg a

no argument expected

ReqArg (String -> a) String

option requires argument

OptArg (Maybe String -> a) String

optional argument

Instances

Functor ArgDescr 

Methods

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

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

usageInfo :: String -> [OptDescr a] -> String #

Return a string describing the usage of a command, derived from the header (first argument) and the options described by the second argument.

tokenize :: Monad m => [OptDescr a] -> (String -> a) -> ParserT [String] m [a] Source #

Create a Parser that preprocesses the command-line arguments, splitting options and their arguments into a user-defined data type.

Example usage

This module is intended to provide simple parsing functionality to the handling of command-line arguments. Here is an example of how this module may be used.

data Option = Help | Version | Other String
           deriving Eq
  
options = [
  Option ['h'] ["help"] (NoArg Help) "Display this menu.",
  Option ['v'] ["version"] (NoArg Version) "Show the version of this program"
  ]

mainAxiom = single Help >> lift (putStrLn (usageInfo options))
          <+> single Version >> lift (putStrLn "Version: 1.0")

main = void $ do
    getArgs >>= (mainAxiom <*< tokenize options Other)

Orphan instances

Functor OptDescr Source # 

Methods

map :: (a -> b) -> OptDescr a -> OptDescr b #

Functor ArgDescr Source # 

Methods

map :: (a -> b) -> ArgDescr a -> ArgDescr b #