Options.Applicative.Simple

optparse-simple-0.1.1.4: Simple interface to optparse-applicative

Safe Haskell | None
Language | Haskell2010

Options.Applicative.Simple

Description

Simple interface to program arguments.

Typical usage with no commands:

    do (opts,()) <-
         simpleOptions "ver"
                       "header"
                       "desc"
                       (flag () () (long "some-flag"))
                       empty
       doThings opts

Typical usage with commands:

    do (opts,runCmd) <-
         simpleOptions "ver"
                       "header"
                       "desc"
                       (pure ()) $
         do addCommand "delete"
                       "Delete the thing"
                       (const deleteTheThing)
                       (pure ())
            addCommand "create"
                       "Create a thing"
                       createAThing
                       (strOption (long "hello"))
       runCmd

Synopsis

- simpleOptions :: String -> String -> String -> Parser a -> ExceptT b (Writer (Mod CommandFields b)) () -> IO (a, b)
- simpleParser :: Parser a -> ExceptT b (Writer (Mod CommandFields b)) () -> Parser (a, b)
- simpleVersion :: Version -> Q Exp
- addCommand :: String -> String -> (a -> b) -> Parser a -> ExceptT b (Writer (Mod CommandFields b)) ()
- addSubCommands :: String -> String -> ExceptT b (Writer (Mod CommandFields b)) () -> ExceptT b (Writer (Mod CommandFields b)) ()
- module Options.Applicative

# Documentation

simpleOptions #

Arguments

:: String | version string
-> String | header
-> String | program description
-> Parser a | global settings
-> ExceptT b (Writer (Mod CommandFields b)) () | commands (use `addCommand`)
-> IO (a, b) |

Generate and execute a simple options parser.

simpleParser #

Arguments

:: Parser a | common settings
-> ExceptT b (Writer (Mod CommandFields b)) () | commands (use `addCommand`)
-> Parser (a, b) |

Generate a simple options parser.

Most of the time you should use `simpleOptions` instead, but `simpleParser` can be used for sub-commands that need common options. For example:

    addCommand "thing"
               "Subcommands that operate on things"
               (\(opts,runSubCmd) -> runSubCmd opts)
               (simpleParser (flag () () (long "some-flag")) $
                do addCommand "delete"
                              "Delete the thing"
                              (const deleteTheThing)
                              (pure ())
                   addCommand "create"
                              "Create a thing"
                              createAThing
                              (strOption (long "hello")))

simpleVersion :: Version -> Q Exp #

Generate a string like `Version 1.2, Git revision 1234`.

`$(simpleVersion …)` `::` `String`

addCommand #

Arguments

:: String | command string
-> String | title of command
-> (a -> b) | constructor to wrap up command in common data type
-> Parser a | command parser
-> ExceptT b (Writer (Mod CommandFields b)) () |

Add a command to the options dispatcher.

addSubCommands #

Arguments

:: String | command string
-> String | title of command
-> ExceptT b (Writer (Mod CommandFields b)) () | sub-commands (use `addCommand`)
-> ExceptT b (Writer (Mod CommandFields b)) () |

Add a command that takes sub-commands to the options dispatcher.

Example:

    addSubCommands "thing"
                   "Subcommands that operate on things"
                   (do addCommand "delete"
                                  "Delete the thing"
                                  (const deleteTheThing)
                                  (pure ())
                       addCommand "create"
                                  "Create a thing"
                                  createAThing
                                  (strOption (long "hello")))

If there are common options between all the sub-commands, use `addCommand` in combination with `simpleParser` instead of `addSubCommands`.

module Options.Applicative