hflags: Command line flag parser, very similar to Google's gflags

[ apache, console, library ] [ Propose Tags ]

The HFlags library supports easy definition of command line flags, reimplementing the ideas from Google's gflags (http://code.google.com/p/gflags).

Command line flags can be declared in any file at the toplevel, using defineFlag. At runtime, the actual values are assigned to the toplevel flags_name constants. Those can be used purely throughout the program.

At the beginning of the main function, $initHFlags "program description" has to be called to initialize the flags. All flags will be initialized that are transitively reachable via imports from main. This means, that any Haskell package can easily define command line flags with HFlags. This feature is demonstrated by http://github.com/errge/hflags/blob/master/examples/ImportExample.hs and http://github.com/errge/hflags/tree/master/examples/package.

A simple example (more in the http://github.com/errge/hflags/tree/master/examples directory):

#!/usr/bin/env runhaskell

{-# LANGUAGE TemplateHaskell #-}

import HFlags

defineFlag "name" "Indiana Jones" "Who to greet."
defineFlag "r:repeat" (3 + 4 :: Int) "Number of times to repeat the message."

main = do s <- $initHFlags "Simple program v0.1"
          sequence_ $ replicate flags_repeat greet
          putStrLn $ "Your additional arguments were: " ++ show s
          putStrLn $ "Which is the same as: " ++ show HFlags.arguments
  where
    greet = putStrLn $ "Hello " ++ flags_name ++ ", very nice to meet you!"

At initHFlags time, the library also tries to gather flags out of environment variables. HFLAGS_verbose=True is equivalent to specify --verbose=True. This environment feature only works with long options and the user has to specify a value even for Bools.

Since version 0.2, you mustn't put the initHFlags in a parentheses with the program description. Just $initHFlags, it's cleaner.

Changes in version 0.3

  • Added undefinedOptions

  • Added support for Char

Changes in version 0.2

  • API change: the caller mustn't use parantheses around initHFlags

  • New feature: dependent defaults, ability to compute some flags' default values based on the current values of other flags


[Skip to Readme]

Modules

[Index]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.1.1, 0.1.2, 0.1.3, 0.2, 0.3, 0.4, 0.4.1, 0.4.2, 0.4.3
Dependencies base (>=4.6 && <5), containers (>=0.4), template-haskell (>=2.8 && <2.11), text (>=0.11) [details]
License LicenseRef-OtherLicense
Author Mihaly Barasz <klao@google.com>, Gergely Risko <gergely@risko.hu>
Maintainer Gergely Risko <gergely@risko.hu>
Revised Revision 1 made by phadej at 2016-07-17T21:07:14Z
Category Console
Home page http://github.com/errge/hflags
Bug tracker http://github.com/errge/hflags/issues
Source repo head: git clone http://github.com/errge/hflags
Uploaded by GergelyRisko at 2013-09-16T15:18:04Z
Distributions NixOS:0.4.3
Reverse Dependencies 6 direct, 4 indirect [details]
Downloads 10642 total (37 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hflags-0.3

[back to package description]

hflags

Command line flag parser for Haskell, conceptually very similar to Google's gflags