
On Fri, Apr 17, 2009 at 20:41, Don Stewart
dbueno:
Hi all,
In a command-line app of mine I want to have a --version flag, like many GNU apps do to report their version. The only way I know to provide the version number is to hardcode it in the source code somewhere. That means I have the version number in two places: the .cabal file and the source code. I just know that one day they'll get unsynchronised, and --version will be wrong.
Is there any way to put the version number in _one_ place, and have both the .cabal and source refer to it? Or even any easier way to synchronise both version numbers?
Yes, cabal provides support for this. Here's how we do that in xmonad.
In your program, import the magic module Paths_$progname:
import Paths_xmonad (version)
["--version"] -> putStrLn ("xmonad " ++ showVersion version)
which provides many fields from the .cabal file used to compile the program.
Awesome! Thanks. This is exactly what I was hoping for. Denis