Package Info


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


The 'HFlags' library supports easy definition of command line flags, reimplementing the ideas from Google's '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 <; and <;.

A simple example (more in the <; directory):

' #!/usr/bin/env runhaskell

&#x7b;-# LANGUAGE TemplateHaskell #-&#x7d;

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" &#x20; sequence_ $ replicate flags_repeat greet &#x20; putStrLn $ "Your additional arguments were: " ++ show s &#x20; putStrLn $ "Which is the same as: " ++ show HFlags.arguments &#x20; where &#x20; 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./

See <; for recent changes.

License: Apache-2.0



Package Version Update ID Released Package Hub Version Platforms Subpackages
0.4.2-bp150.1.3 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • x86-64
  • ghc-hflags
  • ghc-hflags-devel