Agda-2.8.0: A dependently typed functional programming language and proof assistant

Copyright | (c) Sven Panne 2002-2005
License | BSD-style
Safe Haskell | None
Language | Haskell2010

Agda.Utils.GetOpt

Contents

- GetOpt

Description

This module provides facilities for parsing the command-line options in a standalone program. It is essentially a Haskell port of the GNU `getopt` library.

It is a fork of System.Console.GetOpt from the base package of GHC, written by Sven Panne.

We modify it to remove the "allow prefixes of long options" behavior.

Synopsis

- getOpt :: ArgOrder a -> [OptDescr a] -> [String] -> ([a], [String], [String])
- getOpt' :: ArgOrder a -> [OptDescr a] -> [String] -> ([a], [String], [String], [String])
- usageInfo :: String -> [OptDescr a] -> String
- data ArgOrder a
  - = RequireOrder
  - | Permute
  - | ReturnInOrder (String -> a)
- data OptDescr a = Option [Char] [String] (ArgDescr a) String
- data ArgDescr a
  - = NoArg a
  - | ReqArg (String -> a) String
  - | OptArg (Maybe String -> a) String

# GetOpt

getOpt Source #

Arguments

:: ArgOrder a | non-option handling
-> [OptDescr a] | option descriptors
-> [String] | the command-line arguments

-> ([a], [String], [String])

    (options, non-options, error messages)

Process the command-line, and return the list of values that matched (and those that didn't). The arguments are:

- The order requirements (see `ArgOrder`)
- The option descriptions (see `OptDescr`)
- The actual command line arguments (presumably got from `getArgs`).

`getOpt` returns a triple consisting of the option arguments, a list of non-options, and a list of error messages.

getOpt' Source #

Arguments

:: ArgOrder a | non-option handling
-> [OptDescr a] | option descriptors
-> [String] | the command-line arguments

-> ([a], [String], [String], [String])

    (options, non-options, unrecognized, error messages)

This is almost the same as `getOpt`, but returns a quadruple consisting of the option arguments, a list of non-options, a list of unrecognized options, and a list of error messages.

usageInfo Source #

Arguments

:: String | header
-> [OptDescr a] | option descriptors
-> String | nicely formatted description of options

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

data ArgOrder a Source #

What to do with options following non-options.

Constructors

RequireOrder | no option processing after first non-option
Permute | freely intersperse options and non-options
ReturnInOrder (String -> a) | wrap non-options into options

#### Instances

Instances details

Functor ArgOrder Source # |
Instance details Defined in Agda.Utils.GetOpt Methods fmap :: (a -> b) -> ArgOrder a -> ArgOrder b Source # (<$) :: a -> ArgOrder b -> ArgOrder a Source #

data OptDescr a Source #

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 | description of a single options:

Fields

- [Char]

  list of short option characters

- [String]

  list of long option strings (without "--")

- (ArgDescr a)

  argument descriptor

- String

  explanation of option for user

#### Instances

Instances details

Functor OptDescr Source # |
Instance details Defined in Agda.Utils.GetOpt Methods fmap :: (a -> b) -> OptDescr a -> OptDescr b Source # (<$) :: a -> OptDescr b -> OptDescr a Source #

data ArgDescr a Source #

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

Instances details

Functor ArgDescr Source # |
Instance details Defined in Agda.Utils.GetOpt Methods fmap :: (a -> b) -> ArgDescr a -> ArgDescr b Source # (<$) :: a -> ArgDescr b -> ArgDescr a Source #