HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleCabal-3.12.1.0Haskell2010

Distribution.Simple.Command

This is to do with command line handling. The Cabal command line is organised into a number of named sub-commands (much like darcs). The CommandUI abstraction represents one of these sub-commands, with a name, description, a set of flags. Commands can be associated with actions and run. It handles some common stuff automatically, like the --help and command line completion flags. It is designed to allow other tools make derived commands. This feature is used heavily in cabal-install.

  • 15 types
  • 28 values
  • PackageCabal-3.12.1.0
  • Exports43
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceCommand.hs

Command interface

6 declarations
datadata CommandUI flags
#

Constructors

Constructing commands

valuehiddenCommand :: Command action -> Command action
#

Mark command as hidden. Hidden commands don't show up in the 'progname help' or 'progname --help' output.

Associating actions with commands

valuenoExtraFlags :: [String] -> IO ()
#

Utility function, many commands do not accept additional flags. This action fails with a helpful error message if the user supplies any extra.

Building lists of commands

datadata CommandSpec action
#

wraps a CommandUI together with a function that turns it into a Command. By hiding the type of flags for the UI allows construction of a list of all UIs at the top level of the program. That list can then be used for generation of manual page as well as for executing the selected command.

Constructors

Running commands

Option Fields

2 declarations
datadata OptionField a
#

We usually have a data type for storing configuration values, where every field stores a configuration option, and the user sets the value either via command line flags or a configuration file. An individual OptionField models such a field, and we usually build a list of options associated to a configuration data type.

Constructing Option Fields

valueoption
  1. :: SFlags
  2. -> LFlags
  3. -> Description
  4. -> get
  5. -> set
  6. -> MkOptDescr get set a
  7. -> OptionField a
#

Create an option taking a single OptDescr. No explicit Name is given for the Option, the name is the first LFlag given.

Example: option sf lf d get set * sf: Short option name, for example: ['d']. No hyphen permitted. * lf: Long option name, for example: ["debug"]. No hyphens permitted. * d: Description of the option, shown to the user in help messages. * get: Get the current value of the flag. * set: Set the value of the flag. Gets the current value of the flag as a parameter.

valuemultiOption
  1. :: Name
  2. -> get
  3. -> set
  4. -> [get -> set -> OptDescr a]

    MkOptDescr constructors partially applied to flags and description.

  5. -> OptionField a
#

Create an option taking several OptDescrs. You will have to give the flags and description individually to the OptDescr constructor.

Liftings & Projections

Option Descriptions

6 declarations
typetype SFlags = [Char]
#

Short command line option strings

OptDescr smart constructors

valuereqArg
  1. :: Monoid b
  2. => ArgPlaceHolder
  3. -> ReadE b
  4. -> b -> [String]
  5. -> MkOptDescr (a -> b) (b -> a -> a) a
#

Create a string-valued command line interface. Usually called in the context of option or multiOption.

Example: reqArg ad mkflag showflag

  • ad: Placeholder shown to the user, e.g. FILES if files are expected parameters.

  • mkflag: How to parse the argument into the option.

  • showflag: If parsing goes wrong, display a useful error message to the user.

valuechoiceOptFromEnum :: (Bounded b, Enum b, Show b, Eq b) => MkOptDescr (a -> b) (b -> a -> a) a
#

create a Choice option out of an enumeration type. As long flags, the Show output is used. As short flags, the first character which does not conflict with a previous one is used.