Options

Options.hs

Copyright © 2007 Dave Bayer. Subject to a BSD-style license.

This module is part of the Annote project.

module Options (Flag(..),Options,defaults,flags,usage) where

Options declares the command line options.


GetOpt handles command line options. It is a wrapper around System.Console.GetOpt.

import GetOpt (OptionList,OptionSpecs,noArg,reqArg,makeOptions)

Two options yield responses by GetOpt:

annote -v outputs the version string

Annote version 0.1 (48)

annote -h outputs the help message

Usage: annote [-mncodsabxyvh] [file ...]
  -m path    --markup=path    Path to Markdown
  -n         --nomark         Do not use Markdown
  -c         --code           Output stripped source
  -o path    --doc=path       Path to doc directory
  -d format  --date=format    Date format
  -s         --style          Overwrite style.css
  -a string  --start=string   Doc start string
  -b string  --end=string     Doc end string
  -x string  --xstart=string  External start string
  -y string  --xend=string    External end string
  -v         --version        Annote version
  -h         --help           This help message

Flag

Flag is the enumeration type giving the command line option keys.

data Flag
    = Filter
    | NoFilter
    | Code
    | DocDir
    | DateFormat
    | ForceStyle
    | DocStart
    | DocEnd
    | ExtStart
    | ExtEnd
    | Version
    | Help
    deriving (Eq)

Options

Options is the type of the association list of command line options.

type Options = OptionList Flag

defaults, flags

defaults, flags specify the options. While different code could support combining these lists, they are more readable separately, with the entries of flags each fitting on one line.

defaults :: OptionList Flag
defaults =
    [ (Filter,     "Markdown.pl")
    , (DateFormat, "%B %e, %Y, %l:%M %p")
    , (DocDir,     "doc")
    ]

flags :: OptionSpecs Flag
flags = makeOptions
    [ (Filter,     'm', "markup",  reqArg, "path",   "Path to Markdown")
    , (NoFilter,   'n', "nomark",  noArg,  [],       "Do not use Markdown")
    , (Code,       'c', "code",    noArg,  [],       "Output stripped source")
    , (DocDir,     'o', "doc",     reqArg, "path",   "Path to doc directory")
    , (DateFormat, 'd', "date",    reqArg, "format", "Date format")
    , (ForceStyle, 's', "style",   noArg,  [],       "Overwrite style.css")
    , (DocStart,   'a', "start",   reqArg, "string", "Doc start string")
    , (DocEnd,     'b', "end",     reqArg, "string", "Doc end string")
    , (ExtStart,   'x', "xstart",  reqArg, "string", "External start string")
    , (ExtEnd,     'y', "xend",    reqArg, "string", "External end string")
    , (Version,    'v', "version", noArg,  [],       "Annote version")
    , (Help,       'h', "help",    noArg,  [],       "This help message")
    ]

usage

usage is a command line response describing program usage.

usage :: String
usage = "Usage: annote [-mncodsabxyvh] [file ...]"