    {-# LANGUAGE CPP, TemplateHaskell #-}
    {-
    Version number-related utilities. See also the Makefile.
    -}

    module Hledger.Cli.Version (
      progname,
      version,
      prognameandversion,
      prognameanddetailedversion,
      binaryfilename
    )
    where
    import System.Info (os, arch)
    import Text.Printf

    import Hledger.Utils

    -- package name and version from the cabal file
    progname, version, prognameandversion, prognameanddetailedversion :: String
    progname :: String
    progname = "hledger"
    #ifdef VERSION
    version :: String
    version = VERSION
    #else
    version = "dev build"
    #endif
    prognameandversion :: String
    prognameandversion = String
    progname String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ " " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    version
    prognameanddetailedversion :: String
    prognameanddetailedversion = String -> String -> String -> String
    forall r. PrintfType r => String -> r
    printf "%s %s" String
    progname String
    version

    -- developer build version strings include PATCHLEVEL (number of
    -- patches since the last tag). If defined, it must be a number.
    patchlevel :: String
    #ifdef PATCHLEVEL
    patchlevel = "." ++ show (PATCHLEVEL :: Int)
    #else
    patchlevel :: String
    patchlevel = ""
    #endif

    -- the package version plus patchlevel if specified
    buildversion :: String
    buildversion :: String
    buildversion  = String
    version String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    patchlevel

    -- | Given a program name, return a precise platform-specific executable
    -- name suitable for naming downloadable binaries.  Can raise an error if
    -- the version and patch level was not defined correctly at build time.
    binaryfilename :: String -> String
    binaryfilename :: String -> String
    binaryfilename progname :: String
    progname = [String] -> String
    forall p. PrintfType p => [String] -> p
    prettify ([String] -> String) -> [String] -> String
    forall a b. (a -> b) -> a -> b
    $ Char -> String -> [String]
    forall a. Eq a => a -> [a] -> [[a]]
    splitAtElement '.' String
    buildversion
                    where
                      prettify :: [String] -> p
    prettify (major :: String
    major:minor :: String
    minor:bugfix :: String
    bugfix:patches :: String
    patches:[]) =
                          String
    -> String
    -> String
    -> String
    -> String
    -> String
    -> String
    -> String
    -> String
    -> p
    forall r. PrintfType r => String -> r
    printf "%s-%s.%s%s%s-%s-%s%s" String
    progname String
    major String
    minor String
    bugfix' String
    patches' String
    os' String
    arch String
    suffix
                              where
                                bugfix' :: String
    bugfix'
                                    | String
    bugfix String -> [String] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [String
    "0"{-,"98","99"-}] = ""
                                    | Bool
    otherwise = '.' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String
    bugfix
                                patches' :: String
    patches'
                                    | String
    patchesString -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    /=String
    "0" = '+' Char -> String -> String
    forall a. a -> [a] -> [a]
    : String
    patches
                                    | Bool
    otherwise = ""
                                (os' :: String
    os',suffix :: String
    suffix)
                                    | String
    os String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == "darwin"  = ("mac","" :: String)
                                    | String
    os String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == "mingw32" = ("windows",".exe")
                                    | Bool
    otherwise       = (String
    os,"")
                      prettify (major :: String
    major:minor :: String
    minor:bugfix :: String
    bugfix:[]) = [String] -> p
    prettify [String
    major,String
    minor,String
    bugfix,"0"]
                      prettify (major :: String
    major:minor :: String
    minor:[])        = [String] -> p
    prettify [String
    major,String
    minor,"0","0"]
                      prettify (major :: String
    major:[])              = [String] -> p
    prettify [String
    major,"0","0","0"]
                      prettify []                      = String -> p
    forall a. String -> a
    error' "VERSION is empty, please fix"  -- PARTIAL:
                      prettify _                       = String -> p
    forall a. String -> a
    error' "VERSION has too many components, please fix"